--- smsdaemon/main.cpp 2008/06/10 15:34:19 36 +++ smsdaemon/main.cpp 2008/12/01 12:08:23 118 @@ -1,80 +1,25 @@ -#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) +bool sms_exit(int exitcode) { - 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!"); - } - - modem.DeleteSms(sms[i].sms_index); - cmn->smsCounter.incomming++; - } - - if (sms.size() == 0) - Util::Sleep(10); - - if (cmn->isDebug && kbhit()) - break; + if (Common::instance()->isDaemon) + daemonCleanup(); - } + exit(exitcode); } - int main(int argc, char* argv[]) { Common* cmn = Common::instance(); @@ -99,11 +44,8 @@ if (Common::instance()->isDaemon) daemonize(); - cmn->logMessage("--------------------------------"); - - cmn->pluginManager.LoadPlugins(); - SerialPort port("/dev/ttyS1" ); + SerialPort port("/dev/ttyUSB0" ); try { port.Open( SerialPort::BAUD_9600, @@ -115,21 +57,28 @@ catch(std::exception &e) { cmn->logMessage( string("PortOpen Exception: ") + e.what() ); - exit(1); + sms_exit(1); } GsmModem modem(port); + try + { + modem.Init(); + } + catch (std::exception& e) + { + cmn->logMessage( string("GsmModem Exception: ") + e.what() ); + sms_exit(2); + } - ////////////////////////////////// - - 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();