/[projects]/smsdaemon/main.cpp
ViewVC logotype

Contents of /smsdaemon/main.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 88 - (show annotations) (download)
Mon Jun 16 09:04:05 2008 UTC (15 years, 11 months ago) by torben
File size: 1410 byte(s)
Refactored some of the main.cpp code into SmsDaemon class.


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

  ViewVC Help
Powered by ViewVC 1.1.20