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

Diff of /smsdaemon/Common.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 26 by torben, Mon Jun 9 18:15:53 2008 UTC revision 150 by torben, Sun Dec 7 21:42:15 2008 UTC
# Line 1  Line 1 
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>
# Line 7  Line 11 
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  {  {
# Line 17  Common* Common::instance() Line 25  Common* Common::instance()
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            daemonized = false;
37    }
38    
39    
40    Common::~Common()
41    {
42            if (_pluginManager)
43                    delete _pluginManager;
44    
45            if (_taskManager)
46                    delete _taskManager;
47    }
48    
49    PluginManager* Common::GetPluginManager()
50    {
51            return _pluginManager;
52    }
53    
54    TaskManager* Common::GetTaskManager()
55    {
56            return _taskManager;
57    }
58    
59    ConfigFile* Common::GetConfigfile()
60    {
61            return _configFile;
62    }
63    
64  void Common::logMessage(string msg)  void Common::logMessage(string msg)
65  {        {      
66          time_t t = time(0);          time_t t = time(0);
# Line 30  void Common::logMessage(string msg) Line 74  void Common::logMessage(string msg)
74          out << ":" << setw(2) << setfill('0') << now.tm_sec;          out << ":" << setw(2) << setfill('0') << now.tm_sec;
75          out << "  " << msg << endl;          out << "  " << msg << endl;
76    
77          if (this->isDaemon && _logFile != "")          if (this->isDaemon && _logFile != "" && daemonized)
78          {          {
79                  seteuid(0);                  seteuid(0);
80                  ofstream of( _logFile.c_str(), ios_base::out | ios_base::app | ios_base::ate);//append mode                  ofstream of( _logFile.c_str(), ios_base::out | ios_base::app | ios_base::ate);//append mode
# Line 52  void Common::logMessage(string msg) Line 96  void Common::logMessage(string msg)
96  void Common::printUsage()  void Common::printUsage()
97  {  {
98          cout << VERSION << endl;          cout << VERSION << endl;
99            cout << SVNVERSION << endl << endl;
100          cout << "Usage --daemon|--debug [arguments]" << endl;          cout << "Usage --daemon|--debug [arguments]" << endl;
101          cout << "Commandline arguments :" << endl;          cout << "Commandline arguments :" << endl;
102          cout << "  --daemon : Run in daemon (background) mode" << endl;          cout << "  --daemon :       Run in daemon (background) mode" << endl;
103          cout << "  --debug :  Run as normal (frontground) process," << endl;          cout << "  --debug :        Run as normal (frontground) process," << endl;
104          cout << "             with all messages written to std out" << endl;          cout << "                   with all messages written to std out" << endl;
105          cout << "  --help :    Show this help screen" << endl;          cout << "  --config <file>: Specify which config file to use " << endl;
106            cout << "                   default" << configFilePath << endl;
107            cout << "  --help :         Show this help screen" << endl;
108    
109          exit(0);          exit(0);
110  }  }
# Line 81  void Common::loadConfig(int argc, char* Line 128  void Common::loadConfig(int argc, char*
128                          isDaemon = false;                          isDaemon = false;
129                          isDebug = true;                          isDebug = true;
130                  }                  }
131                    else if (current == "--config")
132                    {
133                    }
134                  else if (current == "-h" || current == "--help")                  else if (current == "-h" || current == "--help")
135                  {                  {
136                          printUsage();                          printUsage();
137                  }                  }
138                  else                  else
139                  {                  {
140                          cout << VERSION;                          cout << "Unknown argument : " << current << endl << endl;
                         cout << "Unknown argument : " << current << endl;  
141                  }                  }
142          }          }
143    
144          if (! ( isDaemon || isDebug))          if (! ( isDaemon || isDebug))
145                  printUsage();                  printUsage();
146  }  }
147    
148    
149    std::string Common::getStatusMessage()
150    {
151            long int now = time(0);
152    
153            long int diff = now - this->daemonStart;
154    
155    
156            std::ostringstream out;
157            out << "Uptime " << diff << " seconds. ";
158            out << "Messages received:" << this->smsCounter.incomming << ". ";
159            out << "Messages sent:" << this->smsCounter.outgoing << ".";
160            
161            return out.str();
162    }

Legend:
Removed from v.26  
changed lines
  Added in v.150

  ViewVC Help
Powered by ViewVC 1.1.20