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

Diff of /smsdaemon/main.cpp

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

revision 149 by torben, Sun Dec 7 20:58:41 2008 UTC revision 150 by torben, Sun Dec 7 21:42:15 2008 UTC
# Line 20  bool sms_exit(int exitcode) Line 20  bool sms_exit(int exitcode)
20          exit(exitcode);          exit(exitcode);
21  }  }
22    
23    SerialPort* port = 0;
24    ISmsTransceiver* transceiver = 0;
25    
26    void openModemPort()
27    {
28            Common* cmn = Common::instance();
29            ConfigFile* config = cmn->GetConfigfile();
30    
31            port = new SerialPort ( config->GetValue("smsdaemon","serialport") );
32            try
33            {
34                    port->Open( SerialPort::BAUD_9600,
35                                       SerialPort::CHAR_SIZE_8,
36                                       SerialPort::PARITY_NONE,
37                                       SerialPort::STOP_BITS_1,
38                                       SerialPort::FLOW_CONTROL_HARD );
39            }
40            catch(std::exception &e)
41            {
42                    cmn->logMessage( string("PortOpen Exception: ") + e.what() );
43                    sms_exit(1);
44            }
45    
46            transceiver = new ModemTransceiver(*port);
47    
48            try
49            {
50                    ((ModemTransceiver*)transceiver)->Init();
51            }
52            catch (std::exception& e)
53            {
54                    cmn->logMessage( string("ModemTransceiver Exception: ") + e.what() );
55                    sms_exit(2);
56            }
57    }
58    void closeModemPort()
59    {
60            port->Close();
61            delete port;
62            delete transceiver;
63    }
64    
65  int main(int argc, char* argv[])  int main(int argc, char* argv[])
66  {  {
# Line 46  int main(int argc, char* argv[]) Line 87  int main(int argc, char* argv[])
87    
88          /////////////////////          /////////////////////
89                    
90          //Write a delimiter line in the logfile to seperate sessions  
91            openModemPort();
92            closeModemPort();
93            
94    
95          if (Common::instance()->isDaemon)          if (Common::instance()->isDaemon)
96          {          {
97                  lookup_uid_values();                  lookup_uid_values();
98                  daemonize();                  daemonize();
99                    cmn->daemonized = true;
100          }          }
101    
102                    openModemPort();
         SerialPort port( config->GetValue("smsdaemon","serialport") );  
         try  
         {  
                 port.Open( SerialPort::BAUD_9600,  
                                    SerialPort::CHAR_SIZE_8,  
                                    SerialPort::PARITY_NONE,  
                                    SerialPort::STOP_BITS_1,  
                                    SerialPort::FLOW_CONTROL_HARD );  
         }  
         catch(std::exception &e)  
         {  
                 cmn->logMessage( string("PortOpen Exception: ") + e.what() );  
                 sms_exit(1);  
         }  
   
         ModemTransceiver modem(port);  
   
         try  
         {  
                 modem.Init();  
         }  
         catch (std::exception& e)  
         {  
                 cmn->logMessage( string("ModemTransceiver Exception: ") + e.what() );  
                 sms_exit(2);  
         }  
   
103    
104          //////////////////////////////////          //////////////////////////////////
105    
106          SmsDaemon daemon(modem);          SmsDaemon daemon(*transceiver);
107    
108          daemon.Start();          daemon.Start();
109          //returns here when main-loop exits          //returns here when main-loop exits
# Line 93  int main(int argc, char* argv[]) Line 111  int main(int argc, char* argv[])
111      if (cmn->isDaemon)      if (cmn->isDaemon)
112          daemonCleanup();          daemonCleanup();
113    
114            closeModemPort();
115    
116          return 0;          return 0;
117  }  }
118    

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

  ViewVC Help
Powered by ViewVC 1.1.20