--- smsdaemon/main.cpp 2008/12/08 10:42:04 151 +++ smsdaemon/main.cpp 2008/12/22 22:22:42 214 @@ -1,12 +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" @@ -17,8 +20,8 @@ bool sms_exit(int exitcode) { - if (Common::instance()->isDaemon) - daemonCleanup(); + if (Common::instance()->isDaemon) + daemonCleanup(); exit(exitcode); } @@ -31,18 +34,25 @@ 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) { - cmn->logMessage( string("PortOpen Exception: ") + e.what() ); + Logger::logMessage( string("PortOpen Exception: ") + e.what() ); sms_exit(1); } @@ -54,7 +64,7 @@ } catch (std::exception& e) { - cmn->logMessage( string("ModemTransceiver Exception: ") + e.what() ); + Logger::logMessage( string("ModemTransceiver Exception: ") + e.what() ); sms_exit(2); } } @@ -71,7 +81,7 @@ //Set default values - cmn->setLogfile( "/var/log/smsdaemon.log"); + Logger::setLogfile( "/var/log/smsdaemon.log"); cmn->pidfile = "/var/run/smsdaemon.pid"; cmn->spooldir = "/var/spool/smsdaemon"; @@ -80,36 +90,43 @@ 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); + 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 == "builtin") + 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 } else { - cmn->logMessage( string("Invalid transceiver setting: ")+transconf); + Logger::logMessage( string("Invalid transceiver setting: ")+transconf); exit(1); } - - if (Common::instance()->isDaemon) + + if (Common::instance()->isDaemon) { lookup_uid_values(); daemonize(); @@ -117,28 +134,30 @@ } - if (transconf == "builtin") + if (transconf == "internal") { openModemPort(); } 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") {