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

Diff of /smsdaemon/main.cpp

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

revision 26 by torben, Mon Jun 9 18:15:53 2008 UTC revision 85 by torben, Mon Jun 16 06:46:56 2008 UTC
# Line 1  Line 1 
 #include <iostream>  
1  #include <string>  #include <string>
2    
3  #include <cctype>  #include <cctype>
# Line 58  void main_loop(GsmModem& modem) Line 57  void main_loop(GsmModem& modem)
57                          }                          }
58                          else                          else
59                          {                          {
60                                  modem.SendSms(sms[i].sender, "Unknown command!");                                  modem.SendSms(sms[i].sender, "Unknown command!", false);
61                          }                          }
62    
63                          modem.DeleteSms(sms[i].sms_index);                          modem.DeleteSms(sms[i].sms_index);
64                            cmn->smsCounter.incomming++;
65                  }                  }
66    
67                  if (sms.size() == 0)                  cmn->taskManager.ExecuteTasks();
68                          Util::Sleep(10);  
69    
70                  if (cmn->isDebug && kbhit())                  if (cmn->isDebug && kbhit())
71                          break;                          break;
72    
73                    Util::Sleep(10);
74    
75          }          }
76  }  }
77    
78    bool sms_exit(int exitcode)
79    {
80        if (Common::instance()->isDaemon)
81            daemonCleanup();
82    
83            exit(exitcode);
84    }
85    
86  int main(int argc, char* argv[])  int main(int argc, char* argv[])
87  {  {
# Line 84  int main(int argc, char* argv[]) Line 93  int main(int argc, char* argv[])
93          cmn->pidfile = "/var/run/smsdaemon.pid";          cmn->pidfile = "/var/run/smsdaemon.pid";
94          cmn->spooldir = "/var/spool/smsdaemon";          cmn->spooldir = "/var/spool/smsdaemon";
95    
96          cmn->uid = 500;          cmn->uid = 1000;
97          cmn->gid = 500;          cmn->gid = 1000;
98    
99          cmn->loadConfig(argc,argv);          cmn->loadConfig(argc,argv);
100            cmn->daemonStart = time(0);
101    
102                    
103          /////////////////////          /////////////////////
# Line 99  int main(int argc, char* argv[]) Line 109  int main(int argc, char* argv[])
109    
110          cmn->logMessage("--------------------------------");          cmn->logMessage("--------------------------------");
111    
112            cmn->taskManager.LoadTasks();
113          cmn->pluginManager.LoadPlugins();          cmn->pluginManager.LoadPlugins();
114                    
   
115          SerialPort port("/dev/ttyS1" );          SerialPort port("/dev/ttyS1" );
116          port.Open( SerialPort::BAUD_9600 );          try
117            {
118                    port.Open( SerialPort::BAUD_9600,
119                                       SerialPort::CHAR_SIZE_8,
120                                       SerialPort::PARITY_NONE,
121                                       SerialPort::STOP_BITS_1,
122                                       SerialPort::FLOW_CONTROL_HARD );
123            }
124            catch(std::exception &e)
125            {
126                    cmn->logMessage( string("PortOpen Exception: ") + e.what() );
127                    sms_exit(1);
128            }
129    
130          GsmModem modem(port);          GsmModem modem(port);
131    
132            try
133            {
134                    modem.Init();
135            }
136            catch (std::exception& e)
137            {
138                    cmn->logMessage( string("GsmModem Exception: ") + e.what() );
139                    sms_exit(2);
140            }
141    
142    
143          //////////////////////////////////          //////////////////////////////////
144    
145          Common::instance()->logMessage("SMS daemon started");          cmn->logMessage("SMS daemon started");
146    
147          modem.DeleteAllSms();          modem.DeleteAllSms();
148            
149            try
150            {
151                    main_loop(modem);
152            }
153            catch (std::exception& e)
154            {
155                    cmn->logMessage( e.what() );
156            }
157            catch (...)
158            {
159                    cmn->logMessage( "Caught unknown exception" );
160            }
161    
162            cmn->logMessage( cmn->getStatusMessage() );
163    
164          main_loop(modem);      if (cmn->isDaemon)
165            daemonCleanup();
166    
167            return 0;
168  }  }
169    

Legend:
Removed from v.26  
changed lines
  Added in v.85

  ViewVC Help
Powered by ViewVC 1.1.20