1 |
#include <string> |
#include <string> |
2 |
#include <stdlib.h> |
#include <stdlib.h> |
3 |
|
#include <iostream> |
4 |
|
|
5 |
#include "daemon.h" |
#include "daemon.h" |
6 |
#include "common.h" |
#include "Common.h" |
7 |
#include "Logger.h" |
#include "Logger.h" |
8 |
|
|
9 |
#include "ModemTransceiver.h" |
#include "ModemTransceiver.h" |
19 |
|
|
20 |
bool sms_exit(int exitcode) |
bool sms_exit(int exitcode) |
21 |
{ |
{ |
22 |
if (Common::instance()->isDaemon) |
if (Common::instance()->isDaemon) |
23 |
daemonCleanup(); |
daemonCleanup(); |
24 |
|
|
25 |
exit(exitcode); |
exit(exitcode); |
26 |
} |
} |
33 |
Common* cmn = Common::instance(); |
Common* cmn = Common::instance(); |
34 |
ConfigFile* config = cmn->GetConfigfile(); |
ConfigFile* config = cmn->GetConfigfile(); |
35 |
|
|
36 |
port = new SerialPort ( config->GetValue("smsdaemon","serialport") ); |
port = new SerialPort ( config->GetValue("gsmmodem","serialport") ); |
37 |
try |
try |
38 |
{ |
{ |
39 |
port->Open( SerialPort::BAUD_9600, |
port->Open( SerialPort::BAUD_9600, |
40 |
SerialPort::CHAR_SIZE_8, |
SerialPort::CHAR_SIZE_8, |
41 |
SerialPort::PARITY_NONE, |
SerialPort::PARITY_NONE, |
42 |
SerialPort::STOP_BITS_1, |
SerialPort::STOP_BITS_1, |
43 |
SerialPort::FLOW_CONTROL_HARD ); |
SerialPort::FLOW_CONTROL_HARD ); |
44 |
} |
} |
45 |
catch(std::exception &e) |
catch (std::exception &e) |
46 |
{ |
{ |
47 |
Logger::logMessage( string("PortOpen Exception: ") + e.what() ); |
Logger::logMessage( string("PortOpen Exception: ") + e.what() ); |
48 |
sms_exit(1); |
sms_exit(1); |
82 |
cmn->daemonStart = time(0); |
cmn->daemonStart = time(0); |
83 |
|
|
84 |
ConfigFile* config = cmn->GetConfigfile(); |
ConfigFile* config = cmn->GetConfigfile(); |
85 |
|
|
86 |
bool res = config->Open( cmn->configFilePath ) ; |
bool res = config->Open( cmn->configFilePath ) ; |
87 |
if (!res) { |
if (!res) |
88 |
Logger::logMessage(string("Could not open config file:") + cmn->configFilePath); |
{ |
89 |
|
cout << "Could not open config file:" << cmn->configFilePath << endl; |
90 |
return 1; |
return 1; |
91 |
} |
} |
92 |
|
|
93 |
|
Logger::initLog(); |
94 |
|
|
95 |
|
|
96 |
///////////////////// |
///////////////////// |
97 |
string transconf = config->GetValue("smsdaemon", "transceiver"); |
string transconf = config->GetValue("smsdaemon", "transceiver"); |
|
|
|
98 |
|
|
99 |
if (transconf == "internal") |
|
100 |
|
if (transconf == "internal") |
101 |
{ |
{ |
102 |
openModemPort(); |
openModemPort(); |
103 |
closeModemPort(); |
closeModemPort(); |
104 |
} |
} |
105 |
else if ( transconf == "debug" || transconf == "smstools") |
else if ( transconf == "debug" || transconf == "smstools") |
106 |
{ |
{ |
107 |
//do nothing |
//do nothing |
108 |
} |
} |
112 |
exit(1); |
exit(1); |
113 |
} |
} |
114 |
|
|
|
|
|
115 |
|
|
116 |
if (Common::instance()->isDaemon) |
|
117 |
|
if (Common::instance()->isDaemon) |
118 |
{ |
{ |
119 |
lookup_uid_values(); |
lookup_uid_values(); |
120 |
daemonize(); |
daemonize(); |
129 |
else if (transconf =="smstools") |
else if (transconf =="smstools") |
130 |
{ |
{ |
131 |
transceiver = new SmsToolTransceiver(); |
transceiver = new SmsToolTransceiver(); |
132 |
} |
} |
133 |
else if (transconf == "debug") |
else if (transconf == "debug") |
134 |
{ |
{ |
135 |
transceiver = new DebugTransceiver(); |
transceiver = new DebugTransceiver(); |
139 |
|
|
140 |
SmsDaemon daemon(*transceiver); |
SmsDaemon daemon(*transceiver); |
141 |
|
|
142 |
daemon.Start(); |
daemon.Start(); |
143 |
//returns here when main-loop exits |
//returns here when main-loop exits |
144 |
|
|
145 |
if (cmn->isDaemon) |
if (cmn->isDaemon) |
146 |
daemonCleanup(); |
daemonCleanup(); |
147 |
|
|
148 |
if (transconf == "builtin") |
if (transconf == "builtin") |
149 |
{ |
{ |