#include "common.h" #include "version.h" #include #include #include #include #include #include #include "TaskManager.h" #include "PluginManager.h" #include "ConfigFile.h" using namespace std; Common* Common::instance() { static Common store; return &store; } Common::Common() : _pluginManager(0), _taskManager(0) { _pluginManager = new PluginManager(); _taskManager = new TaskManager(); configFilePath = "/etc/smsdaemon.conf"; _configFile = new ConfigFile(); daemonized = false; } Common::~Common() { if (_pluginManager) delete _pluginManager; if (_taskManager) delete _taskManager; } PluginManager* Common::GetPluginManager() { return _pluginManager; } TaskManager* Common::GetTaskManager() { return _taskManager; } 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 << " --config : Specify which config file to use " << endl; cout << " default" << configFilePath << endl; cout << " --help : Show this help screen" << endl; exit(0); } void Common::loadConfig(int argc, char* argv[]) { isDaemon = false; isDebug = false; for (int i = 1; i< argc; i++) { string current(argv[i]); if (current == "--daemon") { isDaemon = true; isDebug = false; } else if (current == "--debug") { isDaemon = false; isDebug = true; } else if (current == "--config") { } else if (current == "-h" || current == "--help") { printUsage(); } else { cout << "Unknown argument : " << current << endl << endl; } } if (! ( isDaemon || isDebug)) printUsage(); } std::string Common::getStatusMessage() { long int now = time(0); long int diff = now - this->daemonStart; std::ostringstream out; out << "Uptime " << diff << " seconds. "; out << "Messages received:" << this->smsCounter.incomming << ". "; out << "Messages sent:" << this->smsCounter.outgoing << "."; return out.str(); }