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" |
9 |
#include "ModemTransceiver.h" |
#include "ModemTransceiver.h" |
10 |
#include "DebugTransceiver.h" |
#include "DebugTransceiver.h" |
11 |
#include "SmsToolTransceiver.h" |
#include "SmsToolTransceiver.h" |
12 |
|
#include "ProxyTransceiver.h" |
13 |
|
|
14 |
#include "serialport/SerialPort.h" |
#include "serialport/SerialPort.h" |
15 |
#include "SmsDaemon.h" |
#include "SmsDaemon.h" |
20 |
|
|
21 |
bool sms_exit(int exitcode) |
bool sms_exit(int exitcode) |
22 |
{ |
{ |
23 |
if (Common::instance()->isDaemon) |
if (Common::instance()->isDaemon) |
24 |
daemonCleanup(); |
daemonCleanup(); |
25 |
|
|
26 |
exit(exitcode); |
exit(exitcode); |
27 |
} |
} |
34 |
Common* cmn = Common::instance(); |
Common* cmn = Common::instance(); |
35 |
ConfigFile* config = cmn->GetConfigfile(); |
ConfigFile* config = cmn->GetConfigfile(); |
36 |
|
|
37 |
port = new SerialPort ( config->GetValue("gsmmodem","serialport") ); |
std::string portstr = config->GetValue("gsmmodem","serialport",""); |
38 |
|
if (portstr == "") |
39 |
|
{ |
40 |
|
Logger::logMessage("'serialport' not defined in config file"); |
41 |
|
sms_exit(2); |
42 |
|
} |
43 |
|
|
44 |
|
port = new SerialPort ( portstr ); |
45 |
try |
try |
46 |
{ |
{ |
47 |
port->Open( SerialPort::BAUD_9600, |
port->Open( SerialPort::BAUD_9600, |
48 |
SerialPort::CHAR_SIZE_8, |
SerialPort::CHAR_SIZE_8, |
49 |
SerialPort::PARITY_NONE, |
SerialPort::PARITY_NONE, |
50 |
SerialPort::STOP_BITS_1, |
SerialPort::STOP_BITS_1, |
51 |
SerialPort::FLOW_CONTROL_HARD ); |
SerialPort::FLOW_CONTROL_HARD ); |
52 |
} |
} |
53 |
catch(std::exception &e) |
catch (std::exception &e) |
54 |
{ |
{ |
55 |
Logger::logMessage( string("PortOpen Exception: ") + e.what() ); |
Logger::logMessage( string("PortOpen Exception: ") + e.what() ); |
56 |
sms_exit(1); |
sms_exit(1); |
90 |
cmn->daemonStart = time(0); |
cmn->daemonStart = time(0); |
91 |
|
|
92 |
ConfigFile* config = cmn->GetConfigfile(); |
ConfigFile* config = cmn->GetConfigfile(); |
93 |
|
|
94 |
bool res = config->Open( cmn->configFilePath ) ; |
bool res = config->Open( cmn->configFilePath ) ; |
95 |
if (!res) { |
if (!res) |
96 |
Logger::logMessage(string("Could not open config file:") + cmn->configFilePath); |
{ |
97 |
|
cout << "Could not open config file:" << cmn->configFilePath << endl; |
98 |
return 1; |
return 1; |
99 |
} |
} |
100 |
|
|
101 |
|
Logger::initLog(); |
102 |
|
|
103 |
|
|
104 |
///////////////////// |
///////////////////// |
105 |
string transconf = config->GetValue("smsdaemon", "transceiver"); |
string transconf = config->GetValue("smsdaemon", "transceiver", ""); |
|
|
|
106 |
|
|
107 |
if (transconf == "internal") |
if (transconf == "") |
108 |
|
{ |
109 |
|
Logger::logMessage("No transceiver defined in config file"); |
110 |
|
exit(1); |
111 |
|
} |
112 |
|
else if (transconf == "internal") |
113 |
{ |
{ |
114 |
openModemPort(); |
openModemPort(); |
115 |
closeModemPort(); |
closeModemPort(); |
116 |
} |
} |
117 |
else if ( transconf == "debug" || transconf == "smstools") |
else if ( transconf == "debug" || transconf == "smstools") |
118 |
{ |
{ |
119 |
//do nothing |
//do nothing |
120 |
} |
} |
124 |
exit(1); |
exit(1); |
125 |
} |
} |
126 |
|
|
|
|
|
127 |
|
|
128 |
if (Common::instance()->isDaemon) |
|
129 |
|
if (Common::instance()->isDaemon) |
130 |
{ |
{ |
131 |
lookup_uid_values(); |
lookup_uid_values(); |
132 |
daemonize(); |
daemonize(); |
141 |
else if (transconf =="smstools") |
else if (transconf =="smstools") |
142 |
{ |
{ |
143 |
transceiver = new SmsToolTransceiver(); |
transceiver = new SmsToolTransceiver(); |
144 |
} |
} |
145 |
else if (transconf == "debug") |
else if (transconf == "debug") |
146 |
{ |
{ |
147 |
transceiver = new DebugTransceiver(); |
transceiver = new DebugTransceiver(); |
148 |
} |
} |
149 |
|
|
150 |
|
ProxyTransceiver proxy(*transceiver); |
151 |
|
|
152 |
////////////////////////////////// |
////////////////////////////////// |
153 |
|
|
154 |
SmsDaemon daemon(*transceiver); |
SmsDaemon daemon(proxy); |
155 |
|
|
156 |
daemon.Start(); |
daemon.Start(); |
157 |
//returns here when main-loop exits |
//returns here when main-loop exits |
158 |
|
|
159 |
if (cmn->isDaemon) |
if (cmn->isDaemon) |
160 |
daemonCleanup(); |
daemonCleanup(); |
161 |
|
|
162 |
if (transconf == "builtin") |
if (transconf == "builtin") |
163 |
{ |
{ |