--- smsdaemon/main.cpp 2008/12/07 20:06:12 146 +++ smsdaemon/main.cpp 2008/12/08 13:48:52 154 @@ -4,7 +4,10 @@ #include "daemon.h" #include "common.h" -#include "GsmModem.h" +#include "ModemTransceiver.h" +#include "DebugTransceiver.h" +#include "SmsToolTransceiver.h" + #include "serialport/SerialPort.h" #include "SmsDaemon.h" #include "ConfigFile.h" @@ -20,6 +23,47 @@ exit(exitcode); } +SerialPort* port = 0; +ISmsTransceiver* transceiver = 0; + +void openModemPort() +{ + Common* cmn = Common::instance(); + ConfigFile* config = cmn->GetConfigfile(); + + port = new SerialPort ( config->GetValue("smsdaemon","serialport") ); + try + { + port->Open( SerialPort::BAUD_9600, + SerialPort::CHAR_SIZE_8, + SerialPort::PARITY_NONE, + SerialPort::STOP_BITS_1, + SerialPort::FLOW_CONTROL_HARD ); + } + catch(std::exception &e) + { + cmn->logMessage( string("PortOpen Exception: ") + e.what() ); + sms_exit(1); + } + + transceiver = new ModemTransceiver(*port); + + try + { + ((ModemTransceiver*)transceiver)->Init(); + } + catch (std::exception& e) + { + cmn->logMessage( string("ModemTransceiver Exception: ") + e.what() ); + sms_exit(2); + } +} +void closeModemPort() +{ + port->Close(); + delete port; + delete transceiver; +} int main(int argc, char* argv[]) { @@ -45,47 +89,50 @@ ///////////////////// + string transconf = config->GetValue("smsdaemon", "transceiver"); - //Write a delimiter line in the logfile to seperate sessions - if (Common::instance()->isDaemon) + if (transconf == "internal") { - lookup_uid_values(); - daemonize(); + openModemPort(); + closeModemPort(); + } + else if ( transconf == "debug" || transconf == "smstools") + { + //do nothing } - - - SerialPort port( config->GetValue("smsdaemon","serialport") ); - try + else { - port.Open( SerialPort::BAUD_9600, - SerialPort::CHAR_SIZE_8, - SerialPort::PARITY_NONE, - SerialPort::STOP_BITS_1, - SerialPort::FLOW_CONTROL_HARD ); + cmn->logMessage( string("Invalid transceiver setting: ")+transconf); + exit(1); } - catch(std::exception &e) + + + + if (Common::instance()->isDaemon) { - cmn->logMessage( string("PortOpen Exception: ") + e.what() ); - sms_exit(1); + lookup_uid_values(); + daemonize(); + cmn->daemonized = true; } - GsmModem modem(port); - try + if (transconf == "internal") { - modem.Init(); + openModemPort(); } - catch (std::exception& e) + else if (transconf =="smstools") { - cmn->logMessage( string("GsmModem Exception: ") + e.what() ); - sms_exit(2); + transceiver = new SmsToolTransceiver(); + } + else if (transconf == "debug") + { + transceiver = new DebugTransceiver(); } - ////////////////////////////////// - SmsDaemon daemon(modem); + SmsDaemon daemon(*transceiver); daemon.Start(); //returns here when main-loop exits @@ -93,6 +140,11 @@ if (cmn->isDaemon) daemonCleanup(); + if (transconf == "builtin") + { + closeModemPort(); + } + return 0; }