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

Diff of /smsdaemon/SmsDaemon.cpp

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

revision 95 by torben, Mon Jun 16 12:21:30 2008 UTC revision 157 by torben, Mon Dec 8 21:28:40 2008 UTC
# Line 3  Line 3 
3  #include <string>  #include <string>
4    
5  #include <sstream>  #include <sstream>
6    #include <stdlib.h>
7    
8  #include "common.h"  #include "common.h"
9    
10  #include "GsmModem.h"  #include "ISmsTransceiver.h"
11    
12  #include "Plugin.h"  #include "Plugin.h"
13  #include "kbhit.h"  #include "kbhit.h"
# Line 14  Line 16 
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    
24  using namespace std;  using namespace std;
25    
   
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 48  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    
# Line 62  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    
71                  _modem.DeleteSms(sms[i].sms_index);                  _modem.DeleteSms(sms[i].GetIndex());
72                  cmn->smsCounter.incomming++;                  cmn->smsCounter.incomming++;
73          }          }
74  }  }
# Line 89  void SmsDaemon::MainLoop() Line 92  void SmsDaemon::MainLoop()
92                  if (cmn->isDebug && kbhit())                  if (cmn->isDebug && kbhit())
93                          break;                          break;
94    
95                  Util::Sleep(10);                  Util::Sleep(100);
96    
97          }          }
98  }  }
# Line 97  void SmsDaemon::MainLoop() Line 100  void SmsDaemon::MainLoop()
100  void SmsDaemon::Start()  void SmsDaemon::Start()
101  {  {
102          Common* cmn = Common::instance();          Common* cmn = Common::instance();
103            string transceiver = cmn->GetConfigfile()->GetValue("smsdaemon","transceiver");
104    
105            srand(time(0));
106    
107          cmn->daemonStart = time(0);          cmn->daemonStart = time(0);
108          _lastSmsCheck = Util::GetTimeOfDay();          _lastSmsCheck = Util::GetTimeOfDay();
109    
110          cmn->logMessage("--------------------------------");          Logger::logMessage("--------------------------------");
111          cmn->logMessage( VERSION );          Logger::logMessage( VERSION );
112          cmn->logMessage( SVNVER );          Logger::logMessage( SVNVERSION );
113            Logger::logMessage( string("Transceiver: ") + transceiver );
114    
115          cmn->GetTaskManager()->LoadTasks();          cmn->GetTaskManager()->LoadTasks();
116          cmn->GetPluginManager()->LoadPlugins();          cmn->GetPluginManager()->LoadPlugins();
117          cmn->logMessage("SMS daemon started");          Logger::logMessage("SMS daemon started");
118    
119          _modem.DeleteAllSms();          _modem.DeleteAllSms();
120                    
# Line 118  void SmsDaemon::Start() Line 124  void SmsDaemon::Start()
124          }          }
125          catch (std::exception& e)          catch (std::exception& e)
126          {          {
127                  cmn->logMessage( e.what() );                  Logger::logMessage( e.what() );
128          }          }
129          catch (...)          catch (...)
130          {          {
131                  cmn->logMessage( "Caught unknown exception" );                  Logger::logMessage( "Caught unknown exception" );
132          }          }
133    
134          cmn->logMessage( cmn->getStatusMessage() );          Logger::logMessage( cmn->getStatusMessage() );
135  }  }

Legend:
Removed from v.95  
changed lines
  Added in v.157

  ViewVC Help
Powered by ViewVC 1.1.20