4 |
#include "daemon.h" |
#include "daemon.h" |
5 |
#include "common.h" |
#include "common.h" |
6 |
|
|
7 |
#include "GsmModem.h" |
#include "ModemTransceiver.h" |
8 |
#include "SerialPort.h" |
#include "serialport/SerialPort.h" |
9 |
#include "SmsDaemon.h" |
#include "SmsDaemon.h" |
10 |
|
#include "ConfigFile.h" |
11 |
|
|
12 |
using namespace std; |
using namespace std; |
13 |
|
|
20 |
exit(exitcode); |
exit(exitcode); |
21 |
} |
} |
22 |
|
|
23 |
int main(int argc, char* argv[]) |
SerialPort* port = 0; |
24 |
|
ISmsTransceiver* transceiver = 0; |
25 |
|
|
26 |
|
void openModemPort() |
27 |
{ |
{ |
28 |
Common* cmn = Common::instance(); |
Common* cmn = Common::instance(); |
29 |
|
ConfigFile* config = cmn->GetConfigfile(); |
30 |
|
|
31 |
//Set default values |
port = new SerialPort ( config->GetValue("smsdaemon","serialport") ); |
|
|
|
|
cmn->setLogfile( "/var/log/smsdaemon.log"); |
|
|
cmn->pidfile = "/var/run/smsdaemon.pid"; |
|
|
cmn->spooldir = "/var/spool/smsdaemon"; |
|
|
|
|
|
cmn->uid = 1000; |
|
|
cmn->gid = 1000; |
|
|
|
|
|
cmn->loadConfig(argc,argv); |
|
|
cmn->daemonStart = time(0); |
|
|
|
|
|
|
|
|
///////////////////// |
|
|
|
|
|
//Write a delimiter line in the logfile to seperate sessions |
|
|
|
|
|
if (Common::instance()->isDaemon) |
|
|
daemonize(); |
|
|
|
|
|
|
|
|
SerialPort port("/dev/ttyS1" ); |
|
32 |
try |
try |
33 |
{ |
{ |
34 |
port.Open( SerialPort::BAUD_9600, |
port->Open( SerialPort::BAUD_9600, |
35 |
SerialPort::CHAR_SIZE_8, |
SerialPort::CHAR_SIZE_8, |
36 |
SerialPort::PARITY_NONE, |
SerialPort::PARITY_NONE, |
37 |
SerialPort::STOP_BITS_1, |
SerialPort::STOP_BITS_1, |
43 |
sms_exit(1); |
sms_exit(1); |
44 |
} |
} |
45 |
|
|
46 |
GsmModem modem(port); |
transceiver = new ModemTransceiver(*port); |
47 |
|
|
48 |
try |
try |
49 |
{ |
{ |
50 |
modem.Init(); |
((ModemTransceiver*)transceiver)->Init(); |
51 |
} |
} |
52 |
catch (std::exception& e) |
catch (std::exception& e) |
53 |
{ |
{ |
54 |
cmn->logMessage( string("GsmModem Exception: ") + e.what() ); |
cmn->logMessage( string("ModemTransceiver Exception: ") + e.what() ); |
55 |
sms_exit(2); |
sms_exit(2); |
56 |
} |
} |
57 |
|
} |
58 |
|
void closeModemPort() |
59 |
|
{ |
60 |
|
port->Close(); |
61 |
|
delete port; |
62 |
|
delete transceiver; |
63 |
|
} |
64 |
|
|
65 |
|
int main(int argc, char* argv[]) |
66 |
|
{ |
67 |
|
Common* cmn = Common::instance(); |
68 |
|
|
69 |
|
//Set default values |
70 |
|
|
71 |
|
cmn->setLogfile( "/var/log/smsdaemon.log"); |
72 |
|
cmn->pidfile = "/var/run/smsdaemon.pid"; |
73 |
|
cmn->spooldir = "/var/spool/smsdaemon"; |
74 |
|
|
75 |
|
|
76 |
|
cmn->loadConfig(argc,argv); |
77 |
|
cmn->daemonStart = time(0); |
78 |
|
|
79 |
|
ConfigFile* config = cmn->GetConfigfile(); |
80 |
|
|
81 |
|
bool res = config->Open( cmn->configFilePath ) ; |
82 |
|
if (!res) { |
83 |
|
cmn->logMessage(string("Could not open config file:") + cmn->configFilePath); |
84 |
|
return 1; |
85 |
|
} |
86 |
|
|
87 |
|
|
88 |
|
///////////////////// |
89 |
|
|
90 |
|
|
91 |
|
openModemPort(); |
92 |
|
closeModemPort(); |
93 |
|
|
94 |
|
|
95 |
|
if (Common::instance()->isDaemon) |
96 |
|
{ |
97 |
|
lookup_uid_values(); |
98 |
|
daemonize(); |
99 |
|
cmn->daemonized = true; |
100 |
|
} |
101 |
|
|
102 |
|
openModemPort(); |
103 |
|
|
104 |
////////////////////////////////// |
////////////////////////////////// |
105 |
|
|
106 |
SmsDaemon daemon(modem); |
SmsDaemon daemon(*transceiver); |
107 |
|
|
108 |
daemon.Start(); |
daemon.Start(); |
109 |
//returns here when main-loop exits |
//returns here when main-loop exits |
111 |
if (cmn->isDaemon) |
if (cmn->isDaemon) |
112 |
daemonCleanup(); |
daemonCleanup(); |
113 |
|
|
114 |
|
closeModemPort(); |
115 |
|
|
116 |
return 0; |
return 0; |
117 |
} |
} |
118 |
|
|