--- smsdaemon/main.cpp 2008/12/07 00:59:05 132 +++ smsdaemon/main.cpp 2008/12/07 21:42:15 150 @@ -4,10 +4,10 @@ #include "daemon.h" #include "common.h" -#include "GsmModem.h" +#include "ModemTransceiver.h" #include "serialport/SerialPort.h" #include "SmsDaemon.h" - +#include "ConfigFile.h" using namespace std; @@ -20,35 +20,18 @@ exit(exitcode); } -int main(int argc, char* argv[]) +SerialPort* port = 0; +ISmsTransceiver* transceiver = 0; + +void openModemPort() { Common* cmn = Common::instance(); + ConfigFile* config = cmn->GetConfigfile(); - //Set default values - - cmn->setLogfile( "/var/log/smsdaemon.log"); - 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); - - - ///////////////////// - - //Write a delimiter line in the logfile to seperate sessions - - if (Common::instance()->isDaemon) - daemonize(); - - - SerialPort port("/dev/ttyUSB0" ); + port = new SerialPort ( config->GetValue("smsdaemon","serialport") ); try { - port.Open( SerialPort::BAUD_9600, + port->Open( SerialPort::BAUD_9600, SerialPort::CHAR_SIZE_8, SerialPort::PARITY_NONE, SerialPort::STOP_BITS_1, @@ -60,22 +43,67 @@ sms_exit(1); } - GsmModem modem(port); + transceiver = new ModemTransceiver(*port); try { - modem.Init(); + ((ModemTransceiver*)transceiver)->Init(); } catch (std::exception& e) { - cmn->logMessage( string("GsmModem Exception: ") + e.what() ); + cmn->logMessage( string("ModemTransceiver Exception: ") + e.what() ); sms_exit(2); } +} +void closeModemPort() +{ + port->Close(); + delete port; + delete transceiver; +} +int main(int argc, char* argv[]) +{ + Common* cmn = Common::instance(); + + //Set default values + + cmn->setLogfile( "/var/log/smsdaemon.log"); + cmn->pidfile = "/var/run/smsdaemon.pid"; + cmn->spooldir = "/var/spool/smsdaemon"; + + + 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; + } + + + ///////////////////// + + + openModemPort(); + closeModemPort(); + + + if (Common::instance()->isDaemon) + { + lookup_uid_values(); + daemonize(); + cmn->daemonized = true; + } + + openModemPort(); ////////////////////////////////// - SmsDaemon daemon(modem); + SmsDaemon daemon(*transceiver); daemon.Start(); //returns here when main-loop exits @@ -83,6 +111,8 @@ if (cmn->isDaemon) daemonCleanup(); + closeModemPort(); + return 0; }