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

Diff of /smsdaemon/SmsDaemon.cpp

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

revision 149 by torben, Sun Dec 7 20:58:41 2008 UTC revision 210 by torben, Sun Dec 21 21:14:40 2008 UTC
# Line 5  Line 5 
5  #include <sstream>  #include <sstream>
6  #include <stdlib.h>  #include <stdlib.h>
7    
8  #include "common.h"  #include "Common.h"
9    
10  #include "ISmsTransceiver.h"  #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 28  void SmsDaemon::CreateLogMessage(SMS& sm Line 30  void SmsDaemon::CreateLogMessage(SMS& sm
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    
# Line 50  void SmsDaemon::CheckSms() Line 52  void SmsDaemon::CheckSms()
52          for (unsigned int i=0; i<sms.size(); ++i)          for (unsigned int i=0; i<sms.size(); ++i)
53          {          {
54                  string cmd = sms[i].ExtractCommand();                  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 66  void SmsDaemon::CheckSms() Line 68  void SmsDaemon::CheckSms()
68                          _modem.SendSms(sms[i].GetSender(), "Unknown command!", false);                          _modem.SendSms(sms[i].GetSender(), "Unknown command!", false);
69                  }                  }
70    
                 _modem.DeleteSms(sms[i].GetIndex());  
71                  cmn->smsCounter.incomming++;                  cmn->smsCounter.incomming++;
72          }          }
73  }  }
# Line 76  void SmsDaemon::MainLoop() Line 77  void SmsDaemon::MainLoop()
77  {  {
78          Common* cmn = Common::instance();          Common* cmn = Common::instance();
79          volatile bool& mainContinue = cmn->mainContinue;          volatile bool& mainContinue = cmn->mainContinue;
80            volatile bool& reloadConfig = cmn->reloadConfig;
81    
82          mainContinue = true;          mainContinue = true;
83    
# Line 90  void SmsDaemon::MainLoop() Line 91  void SmsDaemon::MainLoop()
91                  if (cmn->isDebug && kbhit())                  if (cmn->isDebug && kbhit())
92                          break;                          break;
93    
94                    if (reloadConfig)
95                            ReloadConfig();
96    
97                  Util::Sleep(100);                  Util::Sleep(100);
98    
99          }          }
100  }  }
101    
102    void SmsDaemon::ReloadConfig()
103    {
104            Common* cmn = Common::instance();
105            cmn->reloadConfig = false;
106    
107            cmn->GetConfigfile()->Reload();
108    
109            cmn->GetPluginManager()->DestroyPlugins();
110            cmn->GetPluginManager()->LoadPlugins();
111    
112            cmn->GetTaskManager()->DestroyTasks();
113            cmn->GetTaskManager()->LoadTasks();
114    
115    }
116    
117  void SmsDaemon::Start()  void SmsDaemon::Start()
118  {  {
119          Common* cmn = Common::instance();          Common* cmn = Common::instance();
120            string transceiver = cmn->GetConfigfile()->GetValue("smsdaemon","transceiver");
121    
122          srand(time(0));          srand(time(0));
123    
124          cmn->daemonStart = time(0);          cmn->daemonStart = time(0);
125          _lastSmsCheck = Util::GetTimeOfDay();          _lastSmsCheck = Util::GetTimeOfDay();
126    
127          cmn->logMessage("--------------------------------");          Logger::logMessage("--------------------------------");
128          cmn->logMessage( VERSION );          Logger::logMessage( VERSION );
129          cmn->logMessage( SVNVERSION );          Logger::logMessage( SVNVERSION );
130            Logger::logMessage( string("Transceiver: ") + transceiver );
131    
132          cmn->GetTaskManager()->LoadTasks();          cmn->GetTaskManager()->LoadTasks();
133          cmn->GetPluginManager()->LoadPlugins();          cmn->GetPluginManager()->LoadPlugins();
134          cmn->logMessage("SMS daemon started");          Logger::logMessage("SMS daemon started");
135    
         _modem.DeleteAllSms();  
           
136          try          try
137          {          {
138                  MainLoop();                  MainLoop();
139          }          }
140          catch (std::exception& e)          catch (std::exception& e)
141          {          {
142                  cmn->logMessage( e.what() );                  Logger::logMessage( e.what() );
143          }          }
144          catch (...)          catch (...)
145          {          {
146                  cmn->logMessage( "Caught unknown exception" );                  Logger::logMessage( "Caught unknown exception" );
147          }          }
148    
149          cmn->logMessage( cmn->getStatusMessage() );          cmn->GetPluginManager()->DestroyPlugins();
150    
151            Logger::logMessage( cmn->getStatusMessage() );
152  }  }

Legend:
Removed from v.149  
changed lines
  Added in v.210

  ViewVC Help
Powered by ViewVC 1.1.20