1 |
torben |
26 |
#include <string> |
2 |
torben |
114 |
#include <stdlib.h> |
3 |
torben |
26 |
|
4 |
|
|
#include "daemon.h" |
5 |
|
|
#include "common.h" |
6 |
|
|
|
7 |
|
|
#include "GsmModem.h" |
8 |
torben |
132 |
#include "serialport/SerialPort.h" |
9 |
torben |
88 |
#include "SmsDaemon.h" |
10 |
torben |
146 |
#include "ConfigFile.h" |
11 |
torben |
26 |
|
12 |
|
|
using namespace std; |
13 |
|
|
|
14 |
|
|
|
15 |
torben |
57 |
bool sms_exit(int exitcode) |
16 |
|
|
{ |
17 |
|
|
if (Common::instance()->isDaemon) |
18 |
|
|
daemonCleanup(); |
19 |
torben |
26 |
|
20 |
torben |
57 |
exit(exitcode); |
21 |
|
|
} |
22 |
|
|
|
23 |
torben |
146 |
|
24 |
torben |
26 |
int main(int argc, char* argv[]) |
25 |
|
|
{ |
26 |
|
|
Common* cmn = Common::instance(); |
27 |
|
|
|
28 |
|
|
//Set default values |
29 |
|
|
|
30 |
|
|
cmn->setLogfile( "/var/log/smsdaemon.log"); |
31 |
|
|
cmn->pidfile = "/var/run/smsdaemon.pid"; |
32 |
|
|
cmn->spooldir = "/var/spool/smsdaemon"; |
33 |
|
|
|
34 |
|
|
|
35 |
|
|
cmn->loadConfig(argc,argv); |
36 |
torben |
36 |
cmn->daemonStart = time(0); |
37 |
torben |
26 |
|
38 |
torben |
146 |
ConfigFile* config = cmn->GetConfigfile(); |
39 |
torben |
26 |
|
40 |
torben |
146 |
bool res = config->Open( cmn->configFilePath ) ; |
41 |
|
|
if (!res) { |
42 |
|
|
cmn->logMessage(string("Could not open config file:") + cmn->configFilePath); |
43 |
|
|
return 1; |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
|
47 |
torben |
26 |
///////////////////// |
48 |
|
|
|
49 |
|
|
//Write a delimiter line in the logfile to seperate sessions |
50 |
|
|
|
51 |
torben |
146 |
if (Common::instance()->isDaemon) |
52 |
|
|
{ |
53 |
|
|
lookup_uid_values(); |
54 |
torben |
26 |
daemonize(); |
55 |
torben |
146 |
} |
56 |
torben |
26 |
|
57 |
|
|
|
58 |
torben |
146 |
SerialPort port( config->GetValue("smsdaemon","serialport") ); |
59 |
torben |
29 |
try |
60 |
|
|
{ |
61 |
torben |
33 |
port.Open( SerialPort::BAUD_9600, |
62 |
|
|
SerialPort::CHAR_SIZE_8, |
63 |
|
|
SerialPort::PARITY_NONE, |
64 |
|
|
SerialPort::STOP_BITS_1, |
65 |
|
|
SerialPort::FLOW_CONTROL_HARD ); |
66 |
torben |
29 |
} |
67 |
|
|
catch(std::exception &e) |
68 |
|
|
{ |
69 |
|
|
cmn->logMessage( string("PortOpen Exception: ") + e.what() ); |
70 |
torben |
57 |
sms_exit(1); |
71 |
torben |
29 |
} |
72 |
torben |
26 |
|
73 |
|
|
GsmModem modem(port); |
74 |
|
|
|
75 |
torben |
57 |
try |
76 |
|
|
{ |
77 |
|
|
modem.Init(); |
78 |
|
|
} |
79 |
|
|
catch (std::exception& e) |
80 |
|
|
{ |
81 |
|
|
cmn->logMessage( string("GsmModem Exception: ") + e.what() ); |
82 |
|
|
sms_exit(2); |
83 |
|
|
} |
84 |
torben |
26 |
|
85 |
torben |
57 |
|
86 |
torben |
26 |
////////////////////////////////// |
87 |
|
|
|
88 |
torben |
88 |
SmsDaemon daemon(modem); |
89 |
torben |
26 |
|
90 |
torben |
88 |
daemon.Start(); |
91 |
|
|
//returns here when main-loop exits |
92 |
torben |
26 |
|
93 |
torben |
30 |
if (cmn->isDaemon) |
94 |
|
|
daemonCleanup(); |
95 |
|
|
|
96 |
|
|
return 0; |
97 |
torben |
26 |
} |