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 |
|
|
#include "SerialPort.h" |
9 |
torben |
88 |
#include "SmsDaemon.h" |
10 |
torben |
26 |
|
11 |
|
|
|
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 |
26 |
int main(int argc, char* argv[]) |
24 |
|
|
{ |
25 |
|
|
Common* cmn = Common::instance(); |
26 |
|
|
|
27 |
|
|
//Set default values |
28 |
|
|
|
29 |
|
|
cmn->setLogfile( "/var/log/smsdaemon.log"); |
30 |
|
|
cmn->pidfile = "/var/run/smsdaemon.pid"; |
31 |
|
|
cmn->spooldir = "/var/spool/smsdaemon"; |
32 |
|
|
|
33 |
torben |
29 |
cmn->uid = 1000; |
34 |
|
|
cmn->gid = 1000; |
35 |
torben |
26 |
|
36 |
|
|
cmn->loadConfig(argc,argv); |
37 |
torben |
36 |
cmn->daemonStart = time(0); |
38 |
torben |
26 |
|
39 |
|
|
|
40 |
|
|
///////////////////// |
41 |
|
|
|
42 |
|
|
//Write a delimiter line in the logfile to seperate sessions |
43 |
|
|
|
44 |
|
|
if (Common::instance()->isDaemon) |
45 |
|
|
daemonize(); |
46 |
|
|
|
47 |
|
|
|
48 |
torben |
118 |
SerialPort port("/dev/ttyUSB0" ); |
49 |
torben |
29 |
try |
50 |
|
|
{ |
51 |
torben |
33 |
port.Open( SerialPort::BAUD_9600, |
52 |
|
|
SerialPort::CHAR_SIZE_8, |
53 |
|
|
SerialPort::PARITY_NONE, |
54 |
|
|
SerialPort::STOP_BITS_1, |
55 |
|
|
SerialPort::FLOW_CONTROL_HARD ); |
56 |
torben |
29 |
} |
57 |
|
|
catch(std::exception &e) |
58 |
|
|
{ |
59 |
|
|
cmn->logMessage( string("PortOpen Exception: ") + e.what() ); |
60 |
torben |
57 |
sms_exit(1); |
61 |
torben |
29 |
} |
62 |
torben |
26 |
|
63 |
|
|
GsmModem modem(port); |
64 |
|
|
|
65 |
torben |
57 |
try |
66 |
|
|
{ |
67 |
|
|
modem.Init(); |
68 |
|
|
} |
69 |
|
|
catch (std::exception& e) |
70 |
|
|
{ |
71 |
|
|
cmn->logMessage( string("GsmModem Exception: ") + e.what() ); |
72 |
|
|
sms_exit(2); |
73 |
|
|
} |
74 |
torben |
26 |
|
75 |
torben |
57 |
|
76 |
torben |
26 |
////////////////////////////////// |
77 |
|
|
|
78 |
torben |
88 |
SmsDaemon daemon(modem); |
79 |
torben |
26 |
|
80 |
torben |
88 |
daemon.Start(); |
81 |
|
|
//returns here when main-loop exits |
82 |
torben |
26 |
|
83 |
torben |
30 |
if (cmn->isDaemon) |
84 |
|
|
daemonCleanup(); |
85 |
|
|
|
86 |
|
|
return 0; |
87 |
torben |
26 |
} |