--- smsdaemon/main.cpp 2008/06/12 12:43:29 63 +++ smsdaemon/main.cpp 2008/11/02 20:14:20 114 @@ -1,78 +1,16 @@ -#include #include +#include -#include -#include #include "daemon.h" #include "common.h" #include "GsmModem.h" #include "SerialPort.h" +#include "SmsDaemon.h" -#include "Plugin.h" -#include "kbhit.h" - -#include "util.h" using namespace std; -using namespace Util; - - -void create_log_message(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 main_loop(GsmModem& modem) -{ - Common* cmn = Common::instance(); - volatile bool& mainContinue = cmn->mainContinue; - - PluginManager& manager = cmn->pluginManager; - mainContinue = true; - - while (mainContinue) - { - 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++; - } - - if (sms.size() == 0) - Util::Sleep(10); - - if (cmn->isDebug && kbhit()) - break; - - } -} bool sms_exit(int exitcode) { @@ -106,9 +44,6 @@ if (Common::instance()->isDaemon) daemonize(); - cmn->logMessage("--------------------------------"); - - cmn->pluginManager.LoadPlugins(); SerialPort port("/dev/ttyS1" ); try @@ -140,13 +75,10 @@ ////////////////////////////////// - cmn->logMessage("SMS daemon started"); - - modem.DeleteAllSms(); - - main_loop(modem); + SmsDaemon daemon(modem); - cmn->logMessage( cmn->getStatusMessage() ); + daemon.Start(); + //returns here when main-loop exits if (cmn->isDaemon) daemonCleanup();