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

Annotation of /smsdaemon/main.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 26 - (hide annotations) (download)
Mon Jun 9 18:15:53 2008 UTC (15 years, 11 months ago) by torben
File size: 1996 byte(s)
Added first basic edition of smsdaemon.

So far sending & receiving sms works and a basic sample plugin is implemented.

1 torben 26 #include <iostream>
2     #include <string>
3    
4     #include <cctype>
5     #include <sstream>
6     #include "daemon.h"
7     #include "common.h"
8    
9     #include "GsmModem.h"
10     #include "SerialPort.h"
11    
12     #include "Plugin.h"
13     #include "kbhit.h"
14    
15     #include "util.h"
16    
17     using namespace std;
18     using namespace Util;
19    
20    
21     void create_log_message(SMS& sms,bool hasPlugin)
22     {
23     ostringstream os;
24     os << "Recieved sms from " << sms.sender << " ; command=" << GetSmsCommand(sms);
25     if (!hasPlugin)
26     os << " -- PLUGIN NOT FOUND";
27    
28     Common::instance()->logMessage(os.str());
29     }
30    
31    
32     void main_loop(GsmModem& modem)
33     {
34     Common* cmn = Common::instance();
35     volatile bool& mainContinue = cmn->mainContinue;
36    
37     PluginManager& manager = cmn->pluginManager;
38    
39     mainContinue = true;
40    
41     while (mainContinue)
42     {
43     vector<SMS> sms = modem.ReadSms();
44    
45     for (unsigned int i=0; i<sms.size(); ++i)
46     {
47     string cmd = GetSmsCommand(sms[i]);
48    
49     cmd = Util::str_tolower(cmd);
50    
51     Plugin* pl = manager.GetPlugin(cmd);
52    
53     create_log_message(sms[i], pl != 0);
54    
55     if (pl)
56     {
57     pl->Execute(modem, sms[i]);
58     }
59     else
60     {
61     modem.SendSms(sms[i].sender, "Unknown command!");
62     }
63    
64     modem.DeleteSms(sms[i].sms_index);
65     }
66    
67     if (sms.size() == 0)
68     Util::Sleep(10);
69    
70     if (cmn->isDebug && kbhit())
71     break;
72    
73     }
74     }
75    
76    
77     int main(int argc, char* argv[])
78     {
79     Common* cmn = Common::instance();
80    
81     //Set default values
82    
83     cmn->setLogfile( "/var/log/smsdaemon.log");
84     cmn->pidfile = "/var/run/smsdaemon.pid";
85     cmn->spooldir = "/var/spool/smsdaemon";
86    
87     cmn->uid = 500;
88     cmn->gid = 500;
89    
90     cmn->loadConfig(argc,argv);
91    
92    
93     /////////////////////
94    
95     //Write a delimiter line in the logfile to seperate sessions
96    
97     if (Common::instance()->isDaemon)
98     daemonize();
99    
100     cmn->logMessage("--------------------------------");
101    
102     cmn->pluginManager.LoadPlugins();
103    
104    
105     SerialPort port("/dev/ttyS1" );
106     port.Open( SerialPort::BAUD_9600 );
107     GsmModem modem(port);
108    
109    
110     //////////////////////////////////
111    
112     Common::instance()->logMessage("SMS daemon started");
113    
114     modem.DeleteAllSms();
115    
116     main_loop(modem);
117    
118     }

  ViewVC Help
Powered by ViewVC 1.1.20