/[projects]/smsdaemon/main.cpp
ViewVC logotype

Diff of /smsdaemon/main.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 150 by torben, Sun Dec 7 21:42:15 2008 UTC revision 211 by torben, Sun Dec 21 22:08:20 2008 UTC
# Line 1  Line 1 
1  #include <string>  #include <string>
2  #include <stdlib.h>  #include <stdlib.h>
3    #include <iostream>
4    
5  #include "daemon.h"  #include "daemon.h"
6  #include "common.h"  #include "Common.h"
7    #include "Logger.h"
8    
9  #include "ModemTransceiver.h"  #include "ModemTransceiver.h"
10    #include "DebugTransceiver.h"
11    #include "SmsToolTransceiver.h"
12    #include "ProxyTransceiver.h"
13    
14  #include "serialport/SerialPort.h"  #include "serialport/SerialPort.h"
15  #include "SmsDaemon.h"  #include "SmsDaemon.h"
16  #include "ConfigFile.h"  #include "ConfigFile.h"
# Line 14  using namespace std; Line 20  using namespace std;
20    
21  bool sms_exit(int exitcode)  bool sms_exit(int exitcode)
22  {  {
23      if (Common::instance()->isDaemon)          if (Common::instance()->isDaemon)
24          daemonCleanup();                  daemonCleanup();
25    
26          exit(exitcode);          exit(exitcode);
27  }  }
# Line 28  void openModemPort() Line 34  void openModemPort()
34          Common* cmn = Common::instance();          Common* cmn = Common::instance();
35          ConfigFile* config = cmn->GetConfigfile();          ConfigFile* config = cmn->GetConfigfile();
36    
37          port = new SerialPort ( config->GetValue("smsdaemon","serialport") );          port = new SerialPort ( config->GetValue("gsmmodem","serialport") );
38          try          try
39          {          {
40                  port->Open( SerialPort::BAUD_9600,                  port->Open( SerialPort::BAUD_9600,
41                                     SerialPort::CHAR_SIZE_8,                              SerialPort::CHAR_SIZE_8,
42                                     SerialPort::PARITY_NONE,                              SerialPort::PARITY_NONE,
43                                     SerialPort::STOP_BITS_1,                              SerialPort::STOP_BITS_1,
44                                     SerialPort::FLOW_CONTROL_HARD );                              SerialPort::FLOW_CONTROL_HARD );
45          }          }
46          catch(std::exception &e)          catch (std::exception &e)
47          {          {
48                  cmn->logMessage( string("PortOpen Exception: ") + e.what() );                  Logger::logMessage( string("PortOpen Exception: ") + e.what() );
49                  sms_exit(1);                  sms_exit(1);
50          }          }
51    
# Line 51  void openModemPort() Line 57  void openModemPort()
57          }          }
58          catch (std::exception& e)          catch (std::exception& e)
59          {          {
60                  cmn->logMessage( string("ModemTransceiver Exception: ") + e.what() );                  Logger::logMessage( string("ModemTransceiver Exception: ") + e.what() );
61                  sms_exit(2);                  sms_exit(2);
62          }          }
63  }  }
# Line 68  int main(int argc, char* argv[]) Line 74  int main(int argc, char* argv[])
74    
75          //Set default values          //Set default values
76    
77          cmn->setLogfile( "/var/log/smsdaemon.log");          Logger::setLogfile( "/var/log/smsdaemon.log");
78          cmn->pidfile = "/var/run/smsdaemon.pid";          cmn->pidfile = "/var/run/smsdaemon.pid";
79          cmn->spooldir = "/var/spool/smsdaemon";          cmn->spooldir = "/var/spool/smsdaemon";
80    
# Line 77  int main(int argc, char* argv[]) Line 83  int main(int argc, char* argv[])
83          cmn->daemonStart = time(0);          cmn->daemonStart = time(0);
84    
85          ConfigFile* config = cmn->GetConfigfile();          ConfigFile* config = cmn->GetConfigfile();
86            
87          bool res = config->Open( cmn->configFilePath ) ;          bool res = config->Open( cmn->configFilePath ) ;
88          if (!res) {          if (!res)
89                  cmn->logMessage(string("Could not open config file:") + cmn->configFilePath);          {
90                    cout << "Could not open config file:" << cmn->configFilePath << endl;
91                  return 1;                  return 1;
92          }          }
93            
94            Logger::initLog();
95    
96    
97          /////////////////////          /////////////////////
98                    string transconf = config->GetValue("smsdaemon", "transceiver");
99    
100    
101            if (transconf == "internal")
102            {
103                    openModemPort();
104                    closeModemPort();
105            }
106            else if ( transconf == "debug" || transconf == "smstools")
107            {
108                    //do nothing
109            }
110            else
111            {
112                    Logger::logMessage( string("Invalid transceiver setting: ")+transconf);
113                    exit(1);
114            }
115    
116    
         openModemPort();  
         closeModemPort();  
           
117    
118          if (Common::instance()->isDaemon)          if (Common::instance()->isDaemon)
119          {          {
120                  lookup_uid_values();                  lookup_uid_values();
121                  daemonize();                  daemonize();
122                  cmn->daemonized = true;                  cmn->daemonized = true;
123          }          }
124    
125          openModemPort();  
126            if (transconf == "internal")
127            {
128                    openModemPort();
129            }
130            else if (transconf =="smstools")
131            {
132                    transceiver = new SmsToolTransceiver();
133            }
134            else if (transconf == "debug")
135            {
136                    transceiver = new DebugTransceiver();
137            }
138    
139            ProxyTransceiver proxy(*transceiver);
140    
141          //////////////////////////////////          //////////////////////////////////
142    
143          SmsDaemon daemon(*transceiver);          SmsDaemon daemon(proxy);
144    
145          daemon.Start();          daemon.Start();
146          //returns here when main-loop exits          //returns here when main-loop exits
147    
148      if (cmn->isDaemon)          if (cmn->isDaemon)
149          daemonCleanup();                  daemonCleanup();
150    
151          closeModemPort();          if (transconf == "builtin")
152            {
153                    closeModemPort();
154            }
155    
156          return 0;          return 0;
157  }  }

Legend:
Removed from v.150  
changed lines
  Added in v.211

  ViewVC Help
Powered by ViewVC 1.1.20