--- smsdaemon/main.cpp 2008/12/07 20:58:41 149 +++ smsdaemon/main.cpp 2008/12/07 21:42:15 150 @@ -20,6 +20,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[]) { @@ -46,46 +87,23 @@ ///////////////////// - //Write a delimiter line in the logfile to seperate sessions + + openModemPort(); + closeModemPort(); + if (Common::instance()->isDaemon) { lookup_uid_values(); daemonize(); + cmn->daemonized = true; } - - SerialPort port( 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); - } - - ModemTransceiver modem(port); - - try - { - modem.Init(); - } - catch (std::exception& e) - { - cmn->logMessage( string("ModemTransceiver Exception: ") + e.what() ); - sms_exit(2); - } - + openModemPort(); ////////////////////////////////// - SmsDaemon daemon(modem); + SmsDaemon daemon(*transceiver); daemon.Start(); //returns here when main-loop exits @@ -93,6 +111,8 @@ if (cmn->isDaemon) daemonCleanup(); + closeModemPort(); + return 0; }