--- smsdaemon/common.cpp 2008/12/07 20:06:12 146 +++ smsdaemon/Common.cpp 2010/04/27 21:06:53 678 @@ -1,4 +1,4 @@ -#include "common.h" +#include "Common.h" #include "version.h" @@ -7,16 +7,16 @@ #include #include #include -#include #include #include #include "TaskManager.h" #include "PluginManager.h" #include "ConfigFile.h" +#include "Util.h" +#include "Logger.h" using namespace std; -const char* Months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov","Dec"}; Common* Common::instance() { @@ -26,12 +26,15 @@ Common::Common() - : _pluginManager(0), _taskManager(0) + : _pluginManager(0), _taskManager(0) { _pluginManager = new PluginManager(); _taskManager = new TaskManager(); configFilePath = "/etc/smsdaemon.conf"; _configFile = new ConfigFile(); + + daemonized = false; + reloadConfig = false; } @@ -59,37 +62,6 @@ return _configFile; } -void Common::logMessage(string msg) -{ - time_t t = time(0); - tm now; - localtime_r(&t, &now); - - ostringstream out; - 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; - - if (this->isDaemon && _logFile != "") - { - seteuid(0); - ofstream of( _logFile.c_str(), ios_base::out | ios_base::app | ios_base::ate);//append mode - if (of) - { - of << out.str(); - of.flush(); - of.close(); - } - seteuid( this->uid); - } - else - { - cout << out.str(); - cout.flush(); - } -} void Common::printUsage() { @@ -101,7 +73,7 @@ cout << " --debug : Run as normal (frontground) process," << endl; cout << " with all messages written to std out" << endl; cout << " --config : Specify which config file to use " << endl; - cout << " default" << configFilePath << endl; + cout << " default" << configFilePath << endl; cout << " --help : Show this help screen" << endl; exit(0); @@ -115,11 +87,11 @@ for (int i = 1; i< argc; i++) { string current(argv[i]); - if (current == "--daemon") + if (current == "--daemon") { - isDaemon = true; + isDaemon = true; isDebug = false; - + } else if (current == "--debug") { @@ -128,6 +100,17 @@ } else if (current == "--config") { + i++; + if ( ismsCounter.incomming << ". "; out << "Messages sent:" << this->smsCounter.outgoing << "."; - + return out.str(); } +