--- smsdaemon/main.cpp 2008/06/11 16:08:37 57 +++ smsdaemon/main.cpp 2008/12/07 20:58:41 149 @@ -1,78 +1,16 @@ -#include #include +#include -#include -#include #include "daemon.h" #include "common.h" -#include "GsmModem.h" -#include "SerialPort.h" - -#include "Plugin.h" -#include "kbhit.h" - -#include "util.h" +#include "ModemTransceiver.h" +#include "serialport/SerialPort.h" +#include "SmsDaemon.h" +#include "ConfigFile.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!"); - } - - 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) { @@ -82,6 +20,7 @@ exit(exitcode); } + int main(int argc, char* argv[]) { Common* cmn = Common::instance(); @@ -92,25 +31,31 @@ cmn->pidfile = "/var/run/smsdaemon.pid"; cmn->spooldir = "/var/spool/smsdaemon"; - cmn->uid = 1000; - cmn->gid = 1000; cmn->loadConfig(argc,argv); cmn->daemonStart = time(0); + ConfigFile* config = cmn->GetConfigfile(); + + bool res = config->Open( cmn->configFilePath ) ; + if (!res) { + cmn->logMessage(string("Could not open config file:") + cmn->configFilePath); + return 1; + } + ///////////////////// //Write a delimiter line in the logfile to seperate sessions - if (Common::instance()->isDaemon) + if (Common::instance()->isDaemon) + { + lookup_uid_values(); daemonize(); + } - cmn->logMessage("--------------------------------"); - - cmn->pluginManager.LoadPlugins(); - SerialPort port("/dev/ttyS1" ); + SerialPort port( config->GetValue("smsdaemon","serialport") ); try { port.Open( SerialPort::BAUD_9600, @@ -125,7 +70,7 @@ sms_exit(1); } - GsmModem modem(port); + ModemTransceiver modem(port); try { @@ -133,20 +78,17 @@ } catch (std::exception& e) { - cmn->logMessage( string("GsmModem Exception: ") + e.what() ); + cmn->logMessage( string("ModemTransceiver 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();