--- smsdaemon/main.cpp 2008/06/16 07:41:47 87 +++ smsdaemon/main.cpp 2008/06/16 09:04:05 88 @@ -1,79 +1,15 @@ #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++; - } - - cmn->taskManager.ExecuteTasks(); - - - if (cmn->isDebug && kbhit()) - break; - - Util::Sleep(10); - - } -} bool sms_exit(int exitcode) { @@ -107,10 +43,6 @@ if (Common::instance()->isDaemon) daemonize(); - cmn->logMessage("--------------------------------"); - - cmn->taskManager.LoadTasks(); - cmn->pluginManager.LoadPlugins(); SerialPort port("/dev/ttyS1" ); try @@ -142,24 +74,10 @@ ////////////////////////////////// - cmn->logMessage("SMS daemon started"); - - modem.DeleteAllSms(); - - try - { - main_loop(modem); - } - catch (std::exception& e) - { - cmn->logMessage( e.what() ); - } - catch (...) - { - cmn->logMessage( "Caught unknown exception" ); - } + SmsDaemon daemon(modem); - cmn->logMessage( cmn->getStatusMessage() ); + daemon.Start(); + //returns here when main-loop exits if (cmn->isDaemon) daemonCleanup();