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

Diff of /smsdaemon/main.cpp

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

revision 158 by torben, Mon Dec 8 21:49:49 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"
# Line 8  Line 9 
9  #include "ModemTransceiver.h"  #include "ModemTransceiver.h"
10  #include "DebugTransceiver.h"  #include "DebugTransceiver.h"
11  #include "SmsToolTransceiver.h"  #include "SmsToolTransceiver.h"
12    #include "ProxyTransceiver.h"
13    
14  #include "serialport/SerialPort.h"  #include "serialport/SerialPort.h"
15  #include "SmsDaemon.h"  #include "SmsDaemon.h"
# Line 18  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 32  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                  Logger::logMessage( string("PortOpen Exception: ") + e.what() );                  Logger::logMessage( string("PortOpen Exception: ") + e.what() );
49                  sms_exit(1);                  sms_exit(1);
# Line 81  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                  Logger::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");          string transconf = config->GetValue("smsdaemon", "transceiver");
           
99    
100          if (transconf == "internal")  
101            if (transconf == "internal")
102          {          {
103                  openModemPort();                  openModemPort();
104                  closeModemPort();                  closeModemPort();
105          }          }
106          else if ( transconf == "debug" || transconf == "smstools")          else if ( transconf == "debug" || transconf == "smstools")
107          {          {
108                  //do nothing                  //do nothing
109          }          }
# Line 108  int main(int argc, char* argv[]) Line 113  int main(int argc, char* argv[])
113                  exit(1);                  exit(1);
114          }          }
115    
           
116    
117          if (Common::instance()->isDaemon)  
118            if (Common::instance()->isDaemon)
119          {          {
120                  lookup_uid_values();                  lookup_uid_values();
121                  daemonize();                  daemonize();
# Line 125  int main(int argc, char* argv[]) Line 130  int main(int argc, char* argv[])
130          else if (transconf =="smstools")          else if (transconf =="smstools")
131          {          {
132                  transceiver = new SmsToolTransceiver();                  transceiver = new SmsToolTransceiver();
133          }          }
134          else if (transconf == "debug")          else if (transconf == "debug")
135          {          {
136                  transceiver = new DebugTransceiver();                  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          if (transconf == "builtin")          if (transconf == "builtin")
152          {          {

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

  ViewVC Help
Powered by ViewVC 1.1.20