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

Diff of /smsdaemon/Common.cpp

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

revision 36 by torben, Tue Jun 10 15:34:19 2008 UTC revision 175 by torben, Wed Dec 10 22:02:28 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>
 #include <fstream>  
10  #include <sstream>  #include <sstream>
11  #include <time.h>  #include <time.h>
12    
13    #include "TaskManager.h"
14    #include "PluginManager.h"
15    #include "ConfigFile.h"
16    
17  using namespace std;  using namespace std;
 char* Months[] = { "", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov","Dec"};  
18    
19  Common* Common::instance()  Common* Common::instance()
20  {  {
# Line 17  Common* Common::instance() Line 23  Common* Common::instance()
23  }  }
24    
25    
26  void Common::logMessage(string msg)  Common::Common()
27  {                : _pluginManager(0), _taskManager(0)
28          time_t t = time(0);  {
29          tm now;          _pluginManager = new PluginManager();
30          localtime_r(&t, &now);          _taskManager = new TaskManager();
31            configFilePath = "/etc/smsdaemon.conf";
32          ostringstream out;          _configFile = new ConfigFile();
         out << Months[ now.tm_mon ] << " " << setw(2) << setfill('0') << now.tm_mday;  
         out << " " << setw(2) << setfill('0') << now.tm_hour;  
         out << ":" << setw(2) << setfill('0') << now.tm_min;  
         out << ":" << setw(2) << setfill('0') << now.tm_sec;  
         out << "  " << msg << endl;  
33    
34          if (this->isDaemon && _logFile != "")          daemonized = false;
35          {  }
36                  seteuid(0);  
37                  ofstream of( _logFile.c_str(), ios_base::out | ios_base::app | ios_base::ate);//append mode  
38                  if (of)  Common::~Common()
39                  {  {
40                          of << out.str();          if (_pluginManager)
41                          of.flush();                  delete _pluginManager;
42                          of.close();  
43                  }          if (_taskManager)
44                  seteuid( this->uid);                  delete _taskManager;
45          }  }
46          else  
47          {  PluginManager* Common::GetPluginManager()
48                  cout << out.str();  {
49                  cout.flush();          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    
63  void Common::printUsage()  void Common::printUsage()
64  {  {
65          cout << VERSION << endl;          cout << VERSION << endl;
66            cout << SVNVERSION << endl << endl;
67          cout << "Usage --daemon|--debug [arguments]" << endl;          cout << "Usage --daemon|--debug [arguments]" << endl;
68          cout << "Commandline arguments :" << endl;          cout << "Commandline arguments :" << endl;
69          cout << "  --daemon : Run in daemon (background) mode" << endl;          cout << "  --daemon :       Run in daemon (background) mode" << endl;
70          cout << "  --debug :  Run as normal (frontground) process," << endl;          cout << "  --debug :        Run as normal (frontground) process," << endl;
71          cout << "             with all messages written to std out" << endl;          cout << "                   with all messages written to std out" << endl;
72          cout << "  --help :    Show this help screen" << endl;          cout << "  --config <file>: Specify which config file to use " << endl;
73            cout << "                   default" << configFilePath << endl;
74            cout << "  --help :         Show this help screen" << endl;
75    
76          exit(0);          exit(0);
77  }  }
# Line 81  void Common::loadConfig(int argc, char* Line 95  void Common::loadConfig(int argc, char*
95                          isDaemon = false;                          isDaemon = false;
96                          isDebug = true;                          isDebug = true;
97                  }                  }
98                    else if (current == "--config")
99                    {
100                            i++;
101                            if ( i<argc)
102                            {
103                                    configFilePath = argv[i];
104                            }
105                            else
106                            {
107                                    printUsage();
108                                    exit(1);
109                            }
110                            
111                    }
112                  else if (current == "-h" || current == "--help")                  else if (current == "-h" || current == "--help")
113                  {                  {
114                          printUsage();                          printUsage();
115                  }                  }
116                  else                  else
117                  {                  {
118                          cout << VERSION;                          cout << "Unknown argument : " << current << endl << endl;
                         cout << "Unknown argument : " << current << endl;  
119                  }                  }
120          }          }
121    

Legend:
Removed from v.36  
changed lines
  Added in v.175

  ViewVC Help
Powered by ViewVC 1.1.20