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

Diff of /smsdaemon/main.cpp

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

revision 146 by torben, Sun Dec 7 20:06:12 2008 UTC revision 151 by torben, Mon Dec 8 10:42:04 2008 UTC
# Line 4  Line 4 
4  #include "daemon.h"  #include "daemon.h"
5  #include "common.h"  #include "common.h"
6    
7  #include "GsmModem.h"  #include "ModemTransceiver.h"
8    #include "DebugTransceiver.h"
9    #include "SmsToolTransceiver.h"
10    
11  #include "serialport/SerialPort.h"  #include "serialport/SerialPort.h"
12  #include "SmsDaemon.h"  #include "SmsDaemon.h"
13  #include "ConfigFile.h"  #include "ConfigFile.h"
# Line 20  bool sms_exit(int exitcode) Line 23  bool sms_exit(int exitcode)
23          exit(exitcode);          exit(exitcode);
24  }  }
25    
26    SerialPort* port = 0;
27    ISmsTransceiver* transceiver = 0;
28    
29    void openModemPort()
30    {
31            Common* cmn = Common::instance();
32            ConfigFile* config = cmn->GetConfigfile();
33    
34            port = new SerialPort ( config->GetValue("smsdaemon","serialport") );
35            try
36            {
37                    port->Open( SerialPort::BAUD_9600,
38                                       SerialPort::CHAR_SIZE_8,
39                                       SerialPort::PARITY_NONE,
40                                       SerialPort::STOP_BITS_1,
41                                       SerialPort::FLOW_CONTROL_HARD );
42            }
43            catch(std::exception &e)
44            {
45                    cmn->logMessage( string("PortOpen Exception: ") + e.what() );
46                    sms_exit(1);
47            }
48    
49            transceiver = new ModemTransceiver(*port);
50    
51            try
52            {
53                    ((ModemTransceiver*)transceiver)->Init();
54            }
55            catch (std::exception& e)
56            {
57                    cmn->logMessage( string("ModemTransceiver Exception: ") + e.what() );
58                    sms_exit(2);
59            }
60    }
61    void closeModemPort()
62    {
63            port->Close();
64            delete port;
65            delete transceiver;
66    }
67    
68  int main(int argc, char* argv[])  int main(int argc, char* argv[])
69  {  {
# Line 45  int main(int argc, char* argv[]) Line 89  int main(int argc, char* argv[])
89                    
90    
91          /////////////////////          /////////////////////
92            string transconf = config->GetValue("smsdaemon", "transceiver");
93                    
         //Write a delimiter line in the logfile to seperate sessions  
94    
95          if (Common::instance()->isDaemon)          if (transconf == "builtin")
96          {          {
97                  lookup_uid_values();                  openModemPort();
98                  daemonize();                  closeModemPort();
99            }
100            else if ( transconf == "debug" || transconf == "smstools")
101            {
102                    //do nothing
103          }          }
104            else
           
         SerialPort port( config->GetValue("smsdaemon","serialport") );  
         try  
105          {          {
106                  port.Open( SerialPort::BAUD_9600,                  cmn->logMessage( string("Invalid transceiver setting: ")+transconf);
107                                     SerialPort::CHAR_SIZE_8,                  exit(1);
                                    SerialPort::PARITY_NONE,  
                                    SerialPort::STOP_BITS_1,  
                                    SerialPort::FLOW_CONTROL_HARD );  
108          }          }
109          catch(std::exception &e)  
110            
111    
112            if (Common::instance()->isDaemon)
113          {          {
114                  cmn->logMessage( string("PortOpen Exception: ") + e.what() );                  lookup_uid_values();
115                  sms_exit(1);                  daemonize();
116                    cmn->daemonized = true;
117          }          }
118    
         GsmModem modem(port);  
119    
120          try          if (transconf == "builtin")
121          {          {
122                  modem.Init();                  openModemPort();
123          }          }
124          catch (std::exception& e)          else if (transconf =="smstools")
125          {          {
126                  cmn->logMessage( string("GsmModem Exception: ") + e.what() );                  transceiver = new SmsToolTransceiver();
127                  sms_exit(2);          }
128            else if (transconf == "debug")
129            {
130                    transceiver = new DebugTransceiver();
131          }          }
132    
   
133          //////////////////////////////////          //////////////////////////////////
134    
135          SmsDaemon daemon(modem);          SmsDaemon daemon(*transceiver);
136    
137          daemon.Start();          daemon.Start();
138          //returns here when main-loop exits          //returns here when main-loop exits
# Line 93  int main(int argc, char* argv[]) Line 140  int main(int argc, char* argv[])
140      if (cmn->isDaemon)      if (cmn->isDaemon)
141          daemonCleanup();          daemonCleanup();
142    
143            if (transconf == "builtin")
144            {
145                    closeModemPort();
146            }
147    
148          return 0;          return 0;
149  }  }
150    

Legend:
Removed from v.146  
changed lines
  Added in v.151

  ViewVC Help
Powered by ViewVC 1.1.20