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

Diff of /smsdaemon/SmsDaemon.cpp

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

revision 101 by torben, Mon Jun 16 16:41:18 2008 UTC revision 675 by torben, Tue Apr 27 20:07:12 2010 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    #include "AccessManager.h"
22    #include "embedded-http/embeddedhttp.h"
23    
24  #include "version.h"  #include "version.h"
25    
26    
27  using namespace std;  using namespace std;
28    
29  void SmsDaemon::CreateLogMessage(SMS& sms,bool hasPlugin)  void SmsDaemon::CreateLogMessage(SMS& sms,bool hasPlugin)
30  {  {
31          ostringstream os;          ostringstream os;
32          os << "Recieved sms from " << sms.sender << " ; command=" << GetSmsCommand(sms);          os << "Recieved sms from " << sms.GetSender() << " ; command=" << sms.ExtractCommand();
33          if (!hasPlugin)          if (!hasPlugin)
34                  os << " -- PLUGIN NOT FOUND";                  os << " -- PLUGIN NOT FOUND";
35    
36          Common::instance()->logMessage(os.str());          Logger::logMessage(os.str());
37  }  }
38    
39    
40  void SmsDaemon::CheckSms()  void SmsDaemon::CheckSms()
41  {  {
42          const int INTERVAL = 250; //no of milliseconds between sms checks          const int INTERVAL = 1000; //no of milliseconds between sms checks
43          timeval now = Util::GetTimeOfDay();          timeval now = Util::GetTimeOfDay();
44    
45          if ( Util::mTimeDiff(_lastSmsCheck,now) < INTERVAL)          if ( Util::mTimeDiff(_lastSmsCheck,now) < INTERVAL)
# Line 47  void SmsDaemon::CheckSms() Line 54  void SmsDaemon::CheckSms()
54    
55          for (unsigned int i=0; i<sms.size(); ++i)          for (unsigned int i=0; i<sms.size(); ++i)
56          {          {
57                  string cmd = GetSmsCommand(sms[i]);                  string cmd = sms[i].ExtractCommand();
58                            
59                  cmd = Util::str_tolower(cmd);                  cmd = Util::str_tolower(cmd);
60    
61                  Plugin* pl = manager->GetPlugin(cmd);                  Plugin* pl = manager->GetPlugin(cmd);
# Line 61  void SmsDaemon::CheckSms() Line 68  void SmsDaemon::CheckSms()
68                  }                  }
69                  else                  else
70                  {                  {
71                          _modem.SendSms(sms[i].sender, "Unknown command!", false);                          _modem.SendSms(sms[i].GetSender(), "Unknown command!", false);
72                  }                  }
73    
                 _modem.DeleteSms(sms[i].sms_index);  
74                  cmn->smsCounter.incomming++;                  cmn->smsCounter.incomming++;
75          }          }
76  }  }
# Line 74  void SmsDaemon::MainLoop() Line 80  void SmsDaemon::MainLoop()
80  {  {
81          Common* cmn = Common::instance();          Common* cmn = Common::instance();
82          volatile bool& mainContinue = cmn->mainContinue;          volatile bool& mainContinue = cmn->mainContinue;
83            volatile bool& reloadConfig = cmn->reloadConfig;
84    
85          mainContinue = true;          mainContinue = true;
86    
# Line 88  void SmsDaemon::MainLoop() Line 94  void SmsDaemon::MainLoop()
94                  if (cmn->isDebug && kbhit())                  if (cmn->isDebug && kbhit())
95                          break;                          break;
96    
97                  Util::Sleep(10);                  if (reloadConfig)
98                            ReloadConfig();
99    
100                    Util::Sleep(100);
101    
102          }          }
103  }  }
104    
105    void SmsDaemon::ReloadConfig()
106    {
107            Common* cmn = Common::instance();
108            cmn->reloadConfig = false;
109    
110            cmn->GetConfigfile()->Reload();
111    
112            cmn->GetPluginManager()->DestroyPlugins();
113            cmn->GetPluginManager()->LoadPlugins();
114    
115            cmn->GetTaskManager()->DestroyTasks();
116            cmn->GetTaskManager()->LoadTasks();
117    
118            AccessManager::Load(); //reload blaclist & privileged list
119    }
120    
121  void SmsDaemon::Start()  void SmsDaemon::Start()
122  {  {
123          Common* cmn = Common::instance();          Common* cmn = Common::instance();
124            string transceiver = cmn->GetConfigfile()->GetValue("smsdaemon","transceiver");
125    
126            srand(time(0));
127    
128          cmn->daemonStart = time(0);          cmn->daemonStart = time(0);
129          _lastSmsCheck = Util::GetTimeOfDay();          _lastSmsCheck = Util::GetTimeOfDay();
130    
131          cmn->logMessage("--------------------------------");          Logger::logMessage("--------------------------------");
132          cmn->logMessage( VERSION );          Logger::logMessage( VERSION );
133          cmn->logMessage( SVNVERSION );          Logger::logMessage( SVNVERSION );
134            Logger::logMessage( string("Transceiver: ") + transceiver );
135    
136            AccessManager::Load(); //reload blaclist & privileged list
137          cmn->GetTaskManager()->LoadTasks();          cmn->GetTaskManager()->LoadTasks();
138          cmn->GetPluginManager()->LoadPlugins();          cmn->GetPluginManager()->LoadPlugins();
139          cmn->logMessage("SMS daemon started");          Logger::logMessage("SMS daemon started");
140    
141            embeddedHttp = new EmbeddedHttp();
142            embeddedHttp->startServer();
143    
         _modem.DeleteAllSms();  
           
144          try          try
145          {          {
146                  MainLoop();                  MainLoop();
147          }          }
148          catch (std::exception& e)          catch (std::exception& e)
149          {          {
150                  cmn->logMessage( e.what() );                  Logger::logMessage( e.what() );
151          }          }
152          catch (...)          catch (...)
153          {          {
154                  cmn->logMessage( "Caught unknown exception" );                  Logger::logMessage( "Caught unknown exception" );
155          }          }
156    
157          cmn->logMessage( cmn->getStatusMessage() );          embeddedHttp->stopServer();
158    
159            cmn->GetPluginManager()->DestroyPlugins();
160    
161            Logger::logMessage( cmn->getStatusMessage() );
162  }  }

Legend:
Removed from v.101  
changed lines
  Added in v.675

  ViewVC Help
Powered by ViewVC 1.1.20