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

Annotation of /smsdaemon/Common.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 196 - (hide annotations) (download)
Thu Dec 18 06:53:29 2008 UTC (15 years, 5 months ago) by torben
File size: 2500 byte(s)
Make pretty

astyle -t -b -N

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 92 }
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 torben 146 ConfigFile* Common::GetConfigfile()
58     {
59     return _configFile;
60     }
61    
62 torben 26
63     void Common::printUsage()
64     {
65 torben 106 cout << VERSION << endl;
66     cout << SVNVERSION << endl << endl;
67 torben 26 cout << "Usage --daemon|--debug [arguments]" << endl;
68     cout << "Commandline arguments :" << endl;
69 torben 146 cout << " --daemon : Run in daemon (background) mode" << endl;
70     cout << " --debug : Run as normal (frontground) process," << endl;
71     cout << " with all messages written to std out" << endl;
72     cout << " --config <file>: Specify which config file to use " << endl;
73 torben 196 cout << " default" << configFilePath << endl;
74 torben 146 cout << " --help : Show this help screen" << endl;
75 torben 26
76     exit(0);
77     }
78    
79     void Common::loadConfig(int argc, char* argv[])
80     {
81     isDaemon = false;
82     isDebug = false;
83    
84     for (int i = 1; i< argc; i++)
85     {
86     string current(argv[i]);
87 torben 196 if (current == "--daemon")
88 torben 26 {
89 torben 196 isDaemon = true;
90 torben 26 isDebug = false;
91 torben 196
92 torben 26 }
93     else if (current == "--debug")
94     {
95     isDaemon = false;
96     isDebug = true;
97     }
98 torben 146 else if (current == "--config")
99     {
100 torben 175 i++;
101     if ( i<argc)
102 torben 196 {
103 torben 175 configFilePath = argv[i];
104     }
105     else
106     {
107     printUsage();
108     exit(1);
109     }
110 torben 196
111 torben 146 }
112 torben 26 else if (current == "-h" || current == "--help")
113     {
114     printUsage();
115     }
116     else
117     {
118 torben 106 cout << "Unknown argument : " << current << endl << endl;
119 torben 26 }
120     }
121    
122     if (! ( isDaemon || isDebug))
123     printUsage();
124     }
125 torben 36
126    
127     std::string Common::getStatusMessage()
128     {
129     long int now = time(0);
130    
131     long int diff = now - this->daemonStart;
132    
133    
134     std::ostringstream out;
135     out << "Uptime " << diff << " seconds. ";
136     out << "Messages received:" << this->smsCounter.incomming << ". ";
137     out << "Messages sent:" << this->smsCounter.outgoing << ".";
138 torben 196
139 torben 36 return out.str();
140     }

Properties

Name Value
svn:mergeinfo

  ViewVC Help
Powered by ViewVC 1.1.20