--- smsdaemon/main.cpp 2008/12/08 21:28:40 157 +++ smsdaemon/main.cpp 2008/12/22 22:22:42 214 @@ -1,13 +1,15 @@ #include #include +#include #include "daemon.h" -#include "common.h" +#include "Common.h" #include "Logger.h" #include "ModemTransceiver.h" #include "DebugTransceiver.h" #include "SmsToolTransceiver.h" +#include "ProxyTransceiver.h" #include "serialport/SerialPort.h" #include "SmsDaemon.h" @@ -18,8 +20,8 @@ bool sms_exit(int exitcode) { - if (Common::instance()->isDaemon) - daemonCleanup(); + if (Common::instance()->isDaemon) + daemonCleanup(); exit(exitcode); } @@ -32,16 +34,23 @@ Common* cmn = Common::instance(); ConfigFile* config = cmn->GetConfigfile(); - port = new SerialPort ( config->GetValue("smsdaemon","serialport") ); + std::string portstr = config->GetValue("gsmmodem","serialport",""); + if (portstr == "") + { + Logger::logMessage("'serialport' not defined in config file"); + sms_exit(2); + } + + port = new SerialPort ( portstr ); try { - port->Open( SerialPort::BAUD_9600, - SerialPort::CHAR_SIZE_8, - SerialPort::PARITY_NONE, - SerialPort::STOP_BITS_1, - SerialPort::FLOW_CONTROL_HARD ); + port->Open( SerialPort::BAUD_9600, + SerialPort::CHAR_SIZE_8, + SerialPort::PARITY_NONE, + SerialPort::STOP_BITS_1, + SerialPort::FLOW_CONTROL_HARD ); } - catch(std::exception &e) + catch (std::exception &e) { Logger::logMessage( string("PortOpen Exception: ") + e.what() ); sms_exit(1); @@ -81,24 +90,31 @@ cmn->daemonStart = time(0); ConfigFile* config = cmn->GetConfigfile(); - + bool res = config->Open( cmn->configFilePath ) ; - if (!res) { - Logger::logMessage(string("Could not open config file:") + cmn->configFilePath); + if (!res) + { + cout << "Could not open config file:" << cmn->configFilePath << endl; return 1; } - + + Logger::initLog(); + ///////////////////// - string transconf = config->GetValue("smsdaemon", "transceiver"); - + string transconf = config->GetValue("smsdaemon", "transceiver", ""); - if (transconf == "internal") + if (transconf == "") + { + Logger::logMessage("No transceiver defined in config file"); + exit(1); + } + else if (transconf == "internal") { openModemPort(); closeModemPort(); - } - else if ( transconf == "debug" || transconf == "smstools") + } + else if ( transconf == "debug" || transconf == "smstools") { //do nothing } @@ -108,9 +124,9 @@ exit(1); } - - if (Common::instance()->isDaemon) + + if (Common::instance()->isDaemon) { lookup_uid_values(); daemonize(); @@ -125,21 +141,23 @@ else if (transconf =="smstools") { transceiver = new SmsToolTransceiver(); - } + } else if (transconf == "debug") { transceiver = new DebugTransceiver(); } + ProxyTransceiver proxy(*transceiver); + ////////////////////////////////// - SmsDaemon daemon(*transceiver); + SmsDaemon daemon(proxy); - daemon.Start(); + daemon.Start(); //returns here when main-loop exits - if (cmn->isDaemon) - daemonCleanup(); + if (cmn->isDaemon) + daemonCleanup(); if (transconf == "builtin") {