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

Annotation of /smsdaemon/Common.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 208 - (hide annotations) (download)
Sun Dec 21 18:41:08 2008 UTC (15 years, 5 months ago) by torben
File size: 2523 byte(s)
Enable dynamic reload of plugins/tasks when recieving a HUP signal

1 torben 158 #include "Common.h"
2 torben 26
3 torben 94
4     #include "version.h"
5    
6 torben 114 #include <stdlib.h>
7 torben 26 #include <string>
8     #include <iostream>
9     #include <iomanip>
10     #include <sstream>
11     #include <time.h>
12    
13 torben 92 #include "TaskManager.h"
14     #include "PluginManager.h"
15 torben 146 #include "ConfigFile.h"
16 torben 92
17 torben 26 using namespace std;
18    
19     Common* Common::instance()
20     {
21     static Common store;
22     return &store;
23     }
24    
25    
26 torben 92 Common::Common()
27 torben 196 : _pluginManager(0), _taskManager(0)
28 torben 92 {
29     _pluginManager = new PluginManager();
30     _taskManager = new TaskManager();
31 torben 146 configFilePath = "/etc/smsdaemon.conf";
32     _configFile = new ConfigFile();
33 torben 150
34     daemonized = false;
35 torben 208 reloadConfig = false;
36 torben 92 }
37    
38    
39     Common::~Common()
40     {
41     if (_pluginManager)
42     delete _pluginManager;
43    
44     if (_taskManager)
45     delete _taskManager;
46     }
47    
48     PluginManager* Common::GetPluginManager()
49     {
50     return _pluginManager;
51     }
52    
53     TaskManager* Common::GetTaskManager()
54     {
55     return _taskManager;
56     }
57    
58 torben 146 ConfigFile* Common::GetConfigfile()
59     {
60     return _configFile;
61     }
62    
63 torben 26
64     void Common::printUsage()
65     {
66 torben 106 cout << VERSION << endl;
67     cout << SVNVERSION << endl << endl;
68 torben 26 cout << "Usage --daemon|--debug [arguments]" << endl;
69     cout << "Commandline arguments :" << endl;
70 torben 146 cout << " --daemon : Run in daemon (background) mode" << endl;
71     cout << " --debug : Run as normal (frontground) process," << endl;
72     cout << " with all messages written to std out" << endl;
73     cout << " --config <file>: Specify which config file to use " << endl;
74 torben 196 cout << " default" << configFilePath << endl;
75 torben 146 cout << " --help : Show this help screen" << endl;
76 torben 26
77     exit(0);
78     }
79    
80     void Common::loadConfig(int argc, char* argv[])
81     {
82     isDaemon = false;
83     isDebug = false;
84    
85     for (int i = 1; i< argc; i++)
86     {
87     string current(argv[i]);
88 torben 196 if (current == "--daemon")
89 torben 26 {
90 torben 196 isDaemon = true;
91 torben 26 isDebug = false;
92 torben 196
93 torben 26 }
94     else if (current == "--debug")
95     {
96     isDaemon = false;
97     isDebug = true;
98     }
99 torben 146 else if (current == "--config")
100     {
101 torben 175 i++;
102     if ( i<argc)
103 torben 196 {
104 torben 175 configFilePath = argv[i];
105     }
106     else
107     {
108     printUsage();
109     exit(1);
110     }
111 torben 196
112 torben 146 }
113 torben 26 else if (current == "-h" || current == "--help")
114     {
115     printUsage();
116     }
117     else
118     {
119 torben 106 cout << "Unknown argument : " << current << endl << endl;
120 torben 26 }
121     }
122    
123     if (! ( isDaemon || isDebug))
124     printUsage();
125     }
126 torben 36
127    
128     std::string Common::getStatusMessage()
129     {
130     long int now = time(0);
131    
132     long int diff = now - this->daemonStart;
133    
134    
135     std::ostringstream out;
136     out << "Uptime " << diff << " seconds. ";
137     out << "Messages received:" << this->smsCounter.incomming << ". ";
138     out << "Messages sent:" << this->smsCounter.outgoing << ".";
139 torben 196
140 torben 36 return out.str();
141     }

Properties

Name Value
svn:mergeinfo

  ViewVC Help
Powered by ViewVC 1.1.20