--- smsdaemon/common.cpp 2008/06/16 11:30:20 92 +++ smsdaemon/Common.cpp 2008/12/08 21:49:49 158 @@ -1,17 +1,20 @@ -#include "common.h" +#include "Common.h" + +#include "version.h" + +#include #include #include #include -#include #include #include #include "TaskManager.h" #include "PluginManager.h" +#include "ConfigFile.h" using namespace std; -const char* Months[] = { "", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov","Dec"}; Common* Common::instance() { @@ -25,6 +28,10 @@ { _pluginManager = new PluginManager(); _taskManager = new TaskManager(); + configFilePath = "/etc/smsdaemon.conf"; + _configFile = new ConfigFile(); + + daemonized = false; } @@ -47,47 +54,24 @@ return _taskManager; } -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(); - } +ConfigFile* Common::GetConfigfile() +{ + return _configFile; } + void Common::printUsage() { cout << VERSION << endl; + cout << SVNVERSION << endl << endl; cout << "Usage --daemon|--debug [arguments]" << endl; cout << "Commandline arguments :" << endl; - cout << " --daemon : Run in daemon (background) mode" << endl; - cout << " --debug : Run as normal (frontground) process," << endl; - cout << " with all messages written to std out" << endl; - cout << " --help : Show this help screen" << endl; + cout << " --daemon : Run in daemon (background) mode" << endl; + 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 << " --help : Show this help screen" << endl; exit(0); } @@ -111,14 +95,16 @@ isDaemon = false; isDebug = true; } + else if (current == "--config") + { + } else if (current == "-h" || current == "--help") { printUsage(); } else { - cout << VERSION; - cout << "Unknown argument : " << current << endl; + cout << "Unknown argument : " << current << endl << endl; } }