1 |
#include "common.h" |
#include "common.h" |
2 |
|
|
3 |
|
|
4 |
|
#include "version.h" |
5 |
|
|
6 |
|
#include <stdlib.h> |
7 |
#include <string> |
#include <string> |
8 |
#include <iostream> |
#include <iostream> |
9 |
#include <iomanip> |
#include <iomanip> |
11 |
#include <sstream> |
#include <sstream> |
12 |
#include <time.h> |
#include <time.h> |
13 |
|
|
14 |
|
#include "TaskManager.h" |
15 |
|
#include "PluginManager.h" |
16 |
|
#include "ConfigFile.h" |
17 |
|
|
18 |
using namespace std; |
using namespace std; |
19 |
char* Months[] = { "", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov","Dec"}; |
const char* Months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov","Dec"}; |
20 |
|
|
21 |
Common* Common::instance() |
Common* Common::instance() |
22 |
{ |
{ |
25 |
} |
} |
26 |
|
|
27 |
|
|
28 |
|
Common::Common() |
29 |
|
: _pluginManager(0), _taskManager(0) |
30 |
|
{ |
31 |
|
_pluginManager = new PluginManager(); |
32 |
|
_taskManager = new TaskManager(); |
33 |
|
configFilePath = "/etc/smsdaemon.conf"; |
34 |
|
_configFile = new ConfigFile(); |
35 |
|
} |
36 |
|
|
37 |
|
|
38 |
|
Common::~Common() |
39 |
|
{ |
40 |
|
if (_pluginManager) |
41 |
|
delete _pluginManager; |
42 |
|
|
43 |
|
if (_taskManager) |
44 |
|
delete _taskManager; |
45 |
|
} |
46 |
|
|
47 |
|
PluginManager* Common::GetPluginManager() |
48 |
|
{ |
49 |
|
return _pluginManager; |
50 |
|
} |
51 |
|
|
52 |
|
TaskManager* Common::GetTaskManager() |
53 |
|
{ |
54 |
|
return _taskManager; |
55 |
|
} |
56 |
|
|
57 |
|
ConfigFile* Common::GetConfigfile() |
58 |
|
{ |
59 |
|
return _configFile; |
60 |
|
} |
61 |
|
|
62 |
void Common::logMessage(string msg) |
void Common::logMessage(string msg) |
63 |
{ |
{ |
64 |
time_t t = time(0); |
time_t t = time(0); |
94 |
void Common::printUsage() |
void Common::printUsage() |
95 |
{ |
{ |
96 |
cout << VERSION << endl; |
cout << VERSION << endl; |
97 |
|
cout << SVNVERSION << endl << endl; |
98 |
cout << "Usage --daemon|--debug [arguments]" << endl; |
cout << "Usage --daemon|--debug [arguments]" << endl; |
99 |
cout << "Commandline arguments :" << endl; |
cout << "Commandline arguments :" << endl; |
100 |
cout << " --daemon : Run in daemon (background) mode" << endl; |
cout << " --daemon : Run in daemon (background) mode" << endl; |
101 |
cout << " --debug : Run as normal (frontground) process," << endl; |
cout << " --debug : Run as normal (frontground) process," << endl; |
102 |
cout << " with all messages written to std out" << endl; |
cout << " with all messages written to std out" << endl; |
103 |
cout << " --help : Show this help screen" << endl; |
cout << " --config <file>: Specify which config file to use " << endl; |
104 |
|
cout << " default" << configFilePath << endl; |
105 |
|
cout << " --help : Show this help screen" << endl; |
106 |
|
|
107 |
exit(0); |
exit(0); |
108 |
} |
} |
126 |
isDaemon = false; |
isDaemon = false; |
127 |
isDebug = true; |
isDebug = true; |
128 |
} |
} |
129 |
|
else if (current == "--config") |
130 |
|
{ |
131 |
|
} |
132 |
else if (current == "-h" || current == "--help") |
else if (current == "-h" || current == "--help") |
133 |
{ |
{ |
134 |
printUsage(); |
printUsage(); |
135 |
} |
} |
136 |
else |
else |
137 |
{ |
{ |
138 |
cout << VERSION; |
cout << "Unknown argument : " << current << endl << endl; |
|
cout << "Unknown argument : " << current << endl; |
|
139 |
} |
} |
140 |
} |
} |
141 |
|
|
142 |
if (! ( isDaemon || isDebug)) |
if (! ( isDaemon || isDebug)) |
143 |
printUsage(); |
printUsage(); |
144 |
} |
} |
145 |
|
|
146 |
|
|
147 |
|
std::string Common::getStatusMessage() |
148 |
|
{ |
149 |
|
long int now = time(0); |
150 |
|
|
151 |
|
long int diff = now - this->daemonStart; |
152 |
|
|
153 |
|
|
154 |
|
std::ostringstream out; |
155 |
|
out << "Uptime " << diff << " seconds. "; |
156 |
|
out << "Messages received:" << this->smsCounter.incomming << ". "; |
157 |
|
out << "Messages sent:" << this->smsCounter.outgoing << "."; |
158 |
|
|
159 |
|
return out.str(); |
160 |
|
} |