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("smsdaemon","serialport") ); |
port = new SerialPort ( config->GetValue("gsmmodem","serialport") ); |
38 |
try |
try |
39 |
{ |
{ |
40 |
port->Open( SerialPort::BAUD_9600, |
port->Open( SerialPort::BAUD_9600, |
41 |
SerialPort::CHAR_SIZE_8, |
SerialPort::CHAR_SIZE_8, |
42 |
SerialPort::PARITY_NONE, |
SerialPort::PARITY_NONE, |
43 |
SerialPort::STOP_BITS_1, |
SerialPort::STOP_BITS_1, |
44 |
SerialPort::FLOW_CONTROL_HARD ); |
SerialPort::FLOW_CONTROL_HARD ); |
45 |
} |
} |
46 |
catch(std::exception &e) |
catch (std::exception &e) |
47 |
{ |
{ |
48 |
Logger::logMessage( string("PortOpen Exception: ") + e.what() ); |
Logger::logMessage( string("PortOpen Exception: ") + e.what() ); |
49 |
sms_exit(1); |
sms_exit(1); |
83 |
cmn->daemonStart = time(0); |
cmn->daemonStart = time(0); |
84 |
|
|
85 |
ConfigFile* config = cmn->GetConfigfile(); |
ConfigFile* config = cmn->GetConfigfile(); |
86 |
|
|
87 |
bool res = config->Open( cmn->configFilePath ) ; |
bool res = config->Open( cmn->configFilePath ) ; |
88 |
if (!res) { |
if (!res) |
89 |
Logger::logMessage(string("Could not open config file:") + cmn->configFilePath); |
{ |
90 |
|
cout << "Could not open config file:" << cmn->configFilePath << endl; |
91 |
return 1; |
return 1; |
92 |
} |
} |
93 |
|
|
94 |
|
Logger::initLog(); |
95 |
|
|
96 |
|
|
97 |
///////////////////// |
///////////////////// |
98 |
string transconf = config->GetValue("smsdaemon", "transceiver"); |
string transconf = config->GetValue("smsdaemon", "transceiver"); |
|
|
|
99 |
|
|
100 |
if (transconf == "internal") |
|
101 |
|
if (transconf == "internal") |
102 |
{ |
{ |
103 |
openModemPort(); |
openModemPort(); |
104 |
closeModemPort(); |
closeModemPort(); |
105 |
} |
} |
106 |
else if ( transconf == "debug" || transconf == "smstools") |
else if ( transconf == "debug" || transconf == "smstools") |
107 |
{ |
{ |
108 |
//do nothing |
//do nothing |
109 |
} |
} |
113 |
exit(1); |
exit(1); |
114 |
} |
} |
115 |
|
|
|
|
|
116 |
|
|
117 |
if (Common::instance()->isDaemon) |
|
118 |
|
if (Common::instance()->isDaemon) |
119 |
{ |
{ |
120 |
lookup_uid_values(); |
lookup_uid_values(); |
121 |
daemonize(); |
daemonize(); |
130 |
else if (transconf =="smstools") |
else if (transconf =="smstools") |
131 |
{ |
{ |
132 |
transceiver = new SmsToolTransceiver(); |
transceiver = new SmsToolTransceiver(); |
133 |
} |
} |
134 |
else if (transconf == "debug") |
else if (transconf == "debug") |
135 |
{ |
{ |
136 |
transceiver = new DebugTransceiver(); |
transceiver = new DebugTransceiver(); |
137 |
} |
} |
138 |
|
|
139 |
|
ProxyTransceiver proxy(*transceiver); |
140 |
|
|
141 |
////////////////////////////////// |
////////////////////////////////// |
142 |
|
|
143 |
SmsDaemon daemon(*transceiver); |
SmsDaemon daemon(proxy); |
144 |
|
|
145 |
daemon.Start(); |
daemon.Start(); |
146 |
//returns here when main-loop exits |
//returns here when main-loop exits |
147 |
|
|
148 |
if (cmn->isDaemon) |
if (cmn->isDaemon) |
149 |
daemonCleanup(); |
daemonCleanup(); |
150 |
|
|
151 |
if (transconf == "builtin") |
if (transconf == "builtin") |
152 |
{ |
{ |