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

Contents of /smsdaemon/SmsDaemon.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 94 - (show annotations) (download)
Mon Jun 16 11:57:48 2008 UTC (15 years, 11 months ago) by torben
File size: 1929 byte(s)
Testing keyword property substitution

1 #include "SmsDaemon.h"
2
3 #include <string>
4
5 #include <sstream>
6 #include "common.h"
7
8 #include "GsmModem.h"
9
10 #include "Plugin.h"
11 #include "kbhit.h"
12
13 #include "util.h"
14
15 #include "TaskManager.h"
16 #include "PluginManager.h"
17
18 #include "version.h"
19
20 using namespace std;
21
22
23 void SmsDaemon::CreateLogMessage(SMS& sms,bool hasPlugin)
24 {
25 ostringstream os;
26 os << "Recieved sms from " << sms.sender << " ; command=" << GetSmsCommand(sms);
27 if (!hasPlugin)
28 os << " -- PLUGIN NOT FOUND";
29
30 Common::instance()->logMessage(os.str());
31 }
32
33
34 void SmsDaemon::CheckSms()
35 {
36 Common* cmn = Common::instance();
37
38 PluginManager* manager = cmn->GetPluginManager();
39 vector<SMS> sms = _modem.ReadSms();
40
41 for (unsigned int i=0; i<sms.size(); ++i)
42 {
43 string cmd = GetSmsCommand(sms[i]);
44
45 cmd = Util::str_tolower(cmd);
46
47 Plugin* pl = manager->GetPlugin(cmd);
48
49 CreateLogMessage(sms[i], pl != 0);
50
51 if (pl)
52 {
53 pl->Execute(_modem, sms[i]);
54 }
55 else
56 {
57 _modem.SendSms(sms[i].sender, "Unknown command!", false);
58 }
59
60 _modem.DeleteSms(sms[i].sms_index);
61 cmn->smsCounter.incomming++;
62 }
63 }
64
65
66 void SmsDaemon::MainLoop()
67 {
68 Common* cmn = Common::instance();
69 volatile bool& mainContinue = cmn->mainContinue;
70
71
72 mainContinue = true;
73
74 while (mainContinue)
75 {
76
77 CheckSms();
78
79 cmn->GetTaskManager()->ExecuteTasks(_modem);
80
81 if (cmn->isDebug && kbhit())
82 break;
83
84 Util::Sleep(10);
85
86 }
87 }
88
89 void SmsDaemon::Start()
90 {
91 Common* cmn = Common::instance();
92
93
94 cmn->daemonStart = time(0);
95
96 cmn->logMessage("--------------------------------");
97 cmn->logMessage( VERSION );
98 cmn->logMessage( SVNVER );
99
100 cmn->GetTaskManager()->LoadTasks();
101 cmn->GetPluginManager()->LoadPlugins();
102 cmn->logMessage("SMS daemon started");
103
104 _modem.DeleteAllSms();
105
106 try
107 {
108 MainLoop();
109 }
110 catch (std::exception& e)
111 {
112 cmn->logMessage( e.what() );
113 }
114 catch (...)
115 {
116 cmn->logMessage( "Caught unknown exception" );
117 }
118
119 cmn->logMessage( cmn->getStatusMessage() );
120 }

  ViewVC Help
Powered by ViewVC 1.1.20