/[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 168 by torben, Tue Dec 9 21:44:15 2008 UTC
# Line 2  Line 2 
2  #include <stdlib.h>  #include <stdlib.h>
3    
4  #include "daemon.h"  #include "daemon.h"
5  #include "common.h"  #include "Common.h"
6    #include "Logger.h"
7    
8  #include "ModemTransceiver.h"  #include "ModemTransceiver.h"
9    #include "DebugTransceiver.h"
10    #include "SmsToolTransceiver.h"
11    
12  #include "serialport/SerialPort.h"  #include "serialport/SerialPort.h"
13  #include "SmsDaemon.h"  #include "SmsDaemon.h"
14  #include "ConfigFile.h"  #include "ConfigFile.h"
# Line 28  void openModemPort() Line 32  void openModemPort()
32          Common* cmn = Common::instance();          Common* cmn = Common::instance();
33          ConfigFile* config = cmn->GetConfigfile();          ConfigFile* config = cmn->GetConfigfile();
34    
35          port = new SerialPort ( config->GetValue("smsdaemon","serialport") );          port = new SerialPort ( config->GetValue("gsmmodem","serialport") );
36          try          try
37          {          {
38                  port->Open( SerialPort::BAUD_9600,                  port->Open( SerialPort::BAUD_9600,
# Line 39  void openModemPort() Line 43  void openModemPort()
43          }          }
44          catch(std::exception &e)          catch(std::exception &e)
45          {          {
46                  cmn->logMessage( string("PortOpen Exception: ") + e.what() );                  Logger::logMessage( string("PortOpen Exception: ") + e.what() );
47                  sms_exit(1);                  sms_exit(1);
48          }          }
49    
# Line 51  void openModemPort() Line 55  void openModemPort()
55          }          }
56          catch (std::exception& e)          catch (std::exception& e)
57          {          {
58                  cmn->logMessage( string("ModemTransceiver Exception: ") + e.what() );                  Logger::logMessage( string("ModemTransceiver Exception: ") + e.what() );
59                  sms_exit(2);                  sms_exit(2);
60          }          }
61  }  }
# Line 68  int main(int argc, char* argv[]) Line 72  int main(int argc, char* argv[])
72    
73          //Set default values          //Set default values
74    
75          cmn->setLogfile( "/var/log/smsdaemon.log");          Logger::setLogfile( "/var/log/smsdaemon.log");
76          cmn->pidfile = "/var/run/smsdaemon.pid";          cmn->pidfile = "/var/run/smsdaemon.pid";
77          cmn->spooldir = "/var/spool/smsdaemon";          cmn->spooldir = "/var/spool/smsdaemon";
78    
# Line 80  int main(int argc, char* argv[]) Line 84  int main(int argc, char* argv[])
84                    
85          bool res = config->Open( cmn->configFilePath ) ;          bool res = config->Open( cmn->configFilePath ) ;
86          if (!res) {          if (!res) {
87                  cmn->logMessage(string("Could not open config file:") + cmn->configFilePath);                  Logger::logMessage(string("Could not open config file:") + cmn->configFilePath);
88                  return 1;                  return 1;
89          }          }
90                    
91    
92          /////////////////////          /////////////////////
93            string transconf = config->GetValue("smsdaemon", "transceiver");
94                    
95    
96          openModemPort();          if (transconf == "internal")
97          closeModemPort();          {
98                    openModemPort();
99                    closeModemPort();
100            }
101            else if ( transconf == "debug" || transconf == "smstools")
102            {
103                    //do nothing
104            }
105            else
106            {
107                    Logger::logMessage( string("Invalid transceiver setting: ")+transconf);
108                    exit(1);
109            }
110    
111                    
112    
113          if (Common::instance()->isDaemon)          if (Common::instance()->isDaemon)
# Line 99  int main(int argc, char* argv[]) Line 117  int main(int argc, char* argv[])
117                  cmn->daemonized = true;                  cmn->daemonized = true;
118          }          }
119    
120          openModemPort();  
121            if (transconf == "internal")
122            {
123                    openModemPort();
124            }
125            else if (transconf =="smstools")
126            {
127                    transceiver = new SmsToolTransceiver();
128            }
129            else if (transconf == "debug")
130            {
131                    transceiver = new DebugTransceiver();
132            }
133    
134          //////////////////////////////////          //////////////////////////////////
135    
# Line 111  int main(int argc, char* argv[]) Line 141  int main(int argc, char* argv[])
141      if (cmn->isDaemon)      if (cmn->isDaemon)
142          daemonCleanup();          daemonCleanup();
143    
144          closeModemPort();          if (transconf == "builtin")
145            {
146                    closeModemPort();
147            }
148    
149          return 0;          return 0;
150  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.20