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

Contents of /smsdaemon/main.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 146 - (show annotations) (download)
Sun Dec 7 20:06:12 2008 UTC (15 years, 5 months ago) by torben
File size: 1695 byte(s)
Added configuration module

1 #include <string>
2 #include <stdlib.h>
3
4 #include "daemon.h"
5 #include "common.h"
6
7 #include "GsmModem.h"
8 #include "serialport/SerialPort.h"
9 #include "SmsDaemon.h"
10 #include "ConfigFile.h"
11
12 using namespace std;
13
14
15 bool sms_exit(int exitcode)
16 {
17 if (Common::instance()->isDaemon)
18 daemonCleanup();
19
20 exit(exitcode);
21 }
22
23
24 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 cmn->daemonStart = time(0);
37
38 ConfigFile* config = cmn->GetConfigfile();
39
40 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 /////////////////////
48
49 //Write a delimiter line in the logfile to seperate sessions
50
51 if (Common::instance()->isDaemon)
52 {
53 lookup_uid_values();
54 daemonize();
55 }
56
57
58 SerialPort port( config->GetValue("smsdaemon","serialport") );
59 try
60 {
61 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 }
67 catch(std::exception &e)
68 {
69 cmn->logMessage( string("PortOpen Exception: ") + e.what() );
70 sms_exit(1);
71 }
72
73 GsmModem modem(port);
74
75 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
85
86 //////////////////////////////////
87
88 SmsDaemon daemon(modem);
89
90 daemon.Start();
91 //returns here when main-loop exits
92
93 if (cmn->isDaemon)
94 daemonCleanup();
95
96 return 0;
97 }

  ViewVC Help
Powered by ViewVC 1.1.20