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

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

  ViewVC Help
Powered by ViewVC 1.1.20