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

Diff of /smsdaemon/SmsDaemon.cpp

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

revision 99 by torben, Mon Jun 16 15:32:07 2008 UTC revision 196 by torben, Thu Dec 18 06:53:29 2008 UTC
# Line 3  Line 3 
3  #include <string>  #include <string>
4    
5  #include <sstream>  #include <sstream>
6  #include "common.h"  #include <stdlib.h>
7    
8  #include "GsmModem.h"  #include "Common.h"
9    
10    #include "ISmsTransceiver.h"
11    
12  #include "Plugin.h"  #include "Plugin.h"
13  #include "kbhit.h"  #include "kbhit.h"
14    
15  #include "util.h"  #include "Util.h"
16    
17  #include "TaskManager.h"  #include "TaskManager.h"
18  #include "PluginManager.h"  #include "PluginManager.h"
19    #include "ConfigFile.h"
20    #include "Logger.h"
21    
22  #include "version.h"  #include "version.h"
23    
# Line 22  using namespace std; Line 26  using namespace std;
26  void SmsDaemon::CreateLogMessage(SMS& sms,bool hasPlugin)  void SmsDaemon::CreateLogMessage(SMS& sms,bool hasPlugin)
27  {  {
28          ostringstream os;          ostringstream os;
29          os << "Recieved sms from " << sms.sender << " ; command=" << GetSmsCommand(sms);          os << "Recieved sms from " << sms.GetSender() << " ; command=" << sms.ExtractCommand();
30          if (!hasPlugin)          if (!hasPlugin)
31                  os << " -- PLUGIN NOT FOUND";                  os << " -- PLUGIN NOT FOUND";
32    
33          Common::instance()->logMessage(os.str());          Logger::logMessage(os.str());
34  }  }
35    
36    
37  void SmsDaemon::CheckSms()  void SmsDaemon::CheckSms()
38  {  {
39          const int INTERVAL = 250; //no of milliseconds between sms checks          const int INTERVAL = 1000; //no of milliseconds between sms checks
40          timeval now = Util::GetTimeOfDay();          timeval now = Util::GetTimeOfDay();
41    
42          if ( Util::mTimeDiff(_lastSmsCheck,now) < INTERVAL)          if ( Util::mTimeDiff(_lastSmsCheck,now) < INTERVAL)
# Line 47  void SmsDaemon::CheckSms() Line 51  void SmsDaemon::CheckSms()
51    
52          for (unsigned int i=0; i<sms.size(); ++i)          for (unsigned int i=0; i<sms.size(); ++i)
53          {          {
54                  string cmd = GetSmsCommand(sms[i]);                  string cmd = sms[i].ExtractCommand();
55                            
56                  cmd = Util::str_tolower(cmd);                  cmd = Util::str_tolower(cmd);
57    
58                  Plugin* pl = manager->GetPlugin(cmd);                  Plugin* pl = manager->GetPlugin(cmd);
# Line 61  void SmsDaemon::CheckSms() Line 65  void SmsDaemon::CheckSms()
65                  }                  }
66                  else                  else
67                  {                  {
68                          _modem.SendSms(sms[i].sender, "Unknown command!", false);                          _modem.SendSms(sms[i].GetSender(), "Unknown command!", false);
69                  }                  }
70    
                 _modem.DeleteSms(sms[i].sms_index);  
71                  cmn->smsCounter.incomming++;                  cmn->smsCounter.incomming++;
72          }          }
73  }  }
# Line 88  void SmsDaemon::MainLoop() Line 91  void SmsDaemon::MainLoop()
91                  if (cmn->isDebug && kbhit())                  if (cmn->isDebug && kbhit())
92                          break;                          break;
93    
94                  Util::Sleep(10);                  Util::Sleep(100);
95    
96          }          }
97  }  }
# Line 96  void SmsDaemon::MainLoop() Line 99  void SmsDaemon::MainLoop()
99  void SmsDaemon::Start()  void SmsDaemon::Start()
100  {  {
101          Common* cmn = Common::instance();          Common* cmn = Common::instance();
102            string transceiver = cmn->GetConfigfile()->GetValue("smsdaemon","transceiver");
103    
104            srand(time(0));
105    
106          cmn->daemonStart = time(0);          cmn->daemonStart = time(0);
107          _lastSmsCheck = Util::GetTimeOfDay();          _lastSmsCheck = Util::GetTimeOfDay();
108    
109          cmn->logMessage("--------------------------------");          Logger::logMessage("--------------------------------");
110          cmn->logMessage( VERSION );          Logger::logMessage( VERSION );
111          cmn->logMessage( "Svn: " SVNVER );          Logger::logMessage( SVNVERSION );
112            Logger::logMessage( string("Transceiver: ") + transceiver );
113    
114          cmn->GetTaskManager()->LoadTasks();          cmn->GetTaskManager()->LoadTasks();
115          cmn->GetPluginManager()->LoadPlugins();          cmn->GetPluginManager()->LoadPlugins();
116          cmn->logMessage("SMS daemon started");          Logger::logMessage("SMS daemon started");
117    
118          _modem.DeleteAllSms();          _modem.DeleteAllSms();
119            
120          try          try
121          {          {
122                  MainLoop();                  MainLoop();
123          }          }
124          catch (std::exception& e)          catch (std::exception& e)
125          {          {
126                  cmn->logMessage( e.what() );                  Logger::logMessage( e.what() );
127          }          }
128          catch (...)          catch (...)
129          {          {
130                  cmn->logMessage( "Caught unknown exception" );                  Logger::logMessage( "Caught unknown exception" );
131          }          }
132    
133          cmn->logMessage( cmn->getStatusMessage() );          Logger::logMessage( cmn->getStatusMessage() );
134  }  }

Legend:
Removed from v.99  
changed lines
  Added in v.196

  ViewVC Help
Powered by ViewVC 1.1.20