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

Diff of /smsdaemon/main.cpp

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

revision 63 by torben, Thu Jun 12 12:43:29 2008 UTC revision 118 by torben, Mon Dec 1 12:08:23 2008 UTC
# Line 1  Line 1 
 #include <iostream>  
1  #include <string>  #include <string>
2    #include <stdlib.h>
3    
 #include <cctype>  
 #include <sstream>  
4  #include "daemon.h"  #include "daemon.h"
5  #include "common.h"  #include "common.h"
6    
7  #include "GsmModem.h"  #include "GsmModem.h"
8  #include "SerialPort.h"  #include "SerialPort.h"
9    #include "SmsDaemon.h"
10    
 #include "Plugin.h"  
 #include "kbhit.h"  
   
 #include "util.h"  
11    
12  using namespace std;  using namespace std;
 using namespace Util;  
   
   
 void create_log_message(SMS& sms,bool hasPlugin)  
 {  
         ostringstream os;  
         os << "Recieved sms from " << sms.sender << " ; command=" << GetSmsCommand(sms);  
         if (!hasPlugin)  
                 os << " -- PLUGIN NOT FOUND";  
   
         Common::instance()->logMessage(os.str());  
 }  
   
   
 void main_loop(GsmModem& modem)  
 {  
         Common* cmn = Common::instance();  
         volatile bool& mainContinue = cmn->mainContinue;  
   
         PluginManager& manager = cmn->pluginManager;  
13    
         mainContinue = true;  
   
         while (mainContinue)  
         {  
                 vector<SMS> sms = modem.ReadSms();  
   
                 for (unsigned int i=0; i<sms.size(); ++i)  
                 {  
                         string cmd = GetSmsCommand(sms[i]);  
                           
                         cmd = Util::str_tolower(cmd);  
   
                         Plugin* pl = manager.GetPlugin(cmd);  
   
                         create_log_message(sms[i], pl != 0);  
   
                         if (pl)  
                         {  
                                 pl->Execute(modem, sms[i]);  
                         }  
                         else  
                         {  
                                 modem.SendSms(sms[i].sender, "Unknown command!", false);  
                         }  
   
                         modem.DeleteSms(sms[i].sms_index);  
                         cmn->smsCounter.incomming++;  
                 }  
   
                 if (sms.size() == 0)  
                         Util::Sleep(10);  
   
                 if (cmn->isDebug && kbhit())  
                         break;  
   
         }  
 }  
14    
15  bool sms_exit(int exitcode)  bool sms_exit(int exitcode)
16  {  {
# Line 106  int main(int argc, char* argv[]) Line 44  int main(int argc, char* argv[])
44          if (Common::instance()->isDaemon)          if (Common::instance()->isDaemon)
45                  daemonize();                  daemonize();
46    
         cmn->logMessage("--------------------------------");  
   
         cmn->pluginManager.LoadPlugins();  
47                    
48          SerialPort port("/dev/ttyS1" );          SerialPort port("/dev/ttyUSB0" );
49          try          try
50          {          {
51                  port.Open( SerialPort::BAUD_9600,                  port.Open( SerialPort::BAUD_9600,
# Line 140  int main(int argc, char* argv[]) Line 75  int main(int argc, char* argv[])
75    
76          //////////////////////////////////          //////////////////////////////////
77    
78          cmn->logMessage("SMS daemon started");          SmsDaemon daemon(modem);
   
         modem.DeleteAllSms();  
   
         main_loop(modem);  
79    
80          cmn->logMessage( cmn->getStatusMessage() );          daemon.Start();
81            //returns here when main-loop exits
82    
83      if (cmn->isDaemon)      if (cmn->isDaemon)
84          daemonCleanup();          daemonCleanup();

Legend:
Removed from v.63  
changed lines
  Added in v.118

  ViewVC Help
Powered by ViewVC 1.1.20