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

Annotation of /smsdaemon/main.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 88 - (hide 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 torben 26 #include <string>
2    
3     #include "daemon.h"
4     #include "common.h"
5    
6     #include "GsmModem.h"
7     #include "SerialPort.h"
8 torben 88 #include "SmsDaemon.h"
9 torben 26
10    
11     using namespace std;
12    
13    
14 torben 57 bool sms_exit(int exitcode)
15     {
16     if (Common::instance()->isDaemon)
17     daemonCleanup();
18 torben 26
19 torben 57 exit(exitcode);
20     }
21    
22 torben 26 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 torben 29 cmn->uid = 1000;
33     cmn->gid = 1000;
34 torben 26
35     cmn->loadConfig(argc,argv);
36 torben 36 cmn->daemonStart = time(0);
37 torben 26
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 torben 29 SerialPort port("/dev/ttyS1" );
48     try
49     {
50 torben 33 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 torben 29 }
56     catch(std::exception &e)
57     {
58     cmn->logMessage( string("PortOpen Exception: ") + e.what() );
59 torben 57 sms_exit(1);
60 torben 29 }
61 torben 26
62     GsmModem modem(port);
63    
64 torben 57 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 torben 26
74 torben 57
75 torben 26 //////////////////////////////////
76    
77 torben 88 SmsDaemon daemon(modem);
78 torben 26
79 torben 88 daemon.Start();
80     //returns here when main-loop exits
81 torben 26
82 torben 30 if (cmn->isDaemon)
83     daemonCleanup();
84    
85     return 0;
86 torben 26 }

  ViewVC Help
Powered by ViewVC 1.1.20