#include "SmsDaemon.h" #include #include #include "common.h" #include "GsmModem.h" #include "Plugin.h" #include "kbhit.h" #include "util.h" using namespace std; void SmsDaemon::CreateLogMessage(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 SmsDaemon::CheckSms() { Common* cmn = Common::instance(); PluginManager& manager = cmn->pluginManager; vector sms = _modem.ReadSms(); for (unsigned int i=0; iExecute(_modem, sms[i]); } else { _modem.SendSms(sms[i].sender, "Unknown command!", false); } _modem.DeleteSms(sms[i].sms_index); cmn->smsCounter.incomming++; } } void SmsDaemon::MainLoop() { Common* cmn = Common::instance(); volatile bool& mainContinue = cmn->mainContinue; mainContinue = true; while (mainContinue) { CheckSms(); cmn->taskManager.ExecuteTasks(); if (cmn->isDebug && kbhit()) break; Util::Sleep(10); } } void SmsDaemon::Start() { Common* cmn = Common::instance(); cmn->daemonStart = time(0); cmn->logMessage("--------------------------------"); cmn->taskManager.LoadTasks(); cmn->pluginManager.LoadPlugins(); cmn->logMessage("SMS daemon started"); _modem.DeleteAllSms(); try { MainLoop(); } catch (std::exception& e) { cmn->logMessage( e.what() ); } catch (...) { cmn->logMessage( "Caught unknown exception" ); } cmn->logMessage( cmn->getStatusMessage() ); }