From: Maxim Mamontov Date: Tue, 22 Mar 2011 11:56:26 +0000 (+0200) Subject: Fix compilation issues after splitting SETTINGS into interface and X-Git-Tag: 2.407-rc3~121 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/12aae76fbeaa3dc91ab5ecad5531a2c1925340d2 Fix compilation issues after splitting SETTINGS into interface and implementation parts --- diff --git a/projects/stargazer/Makefile b/projects/stargazer/Makefile index 29d61b1a..9f7dd869 100644 --- a/projects/stargazer/Makefile +++ b/projects/stargazer/Makefile @@ -8,19 +8,19 @@ PROG = stargazer SRCS = ./admin_impl.cpp \ ./admins_impl.cpp \ + ./eventloop.cpp \ ./main.cpp \ - ./settings.cpp \ + ./pidfile.cpp \ + ./plugin_runner.cpp \ + ./settings_impl.cpp \ ./stg_timer.cpp \ + ./store_loader.cpp \ ./tariff_impl.cpp \ ./tariffs_impl.cpp \ ./traffcounter.cpp \ ./user_impl.cpp \ ./user_property.cpp \ - ./users_impl.cpp \ - ./plugin_runner.cpp \ - ./store_loader.cpp \ - ./pidfile.cpp \ - ./eventloop.cpp + ./users_impl.cpp STGLIBS = -lstg_logger \ -lstg_locker \ diff --git a/projects/stargazer/main.cpp b/projects/stargazer/main.cpp index 9ae5db7d..63d5a6b0 100644 --- a/projects/stargazer/main.cpp +++ b/projects/stargazer/main.cpp @@ -24,18 +24,18 @@ $Author: faust $ */ -//#include -#include +/*#include #include #include -#include +#include */ #include #include #include -#include +#include #include +/*#include #include -#include +#include */ #include #include @@ -44,7 +44,7 @@ #include #include -#include "settings.h" +#include "settings_impl.h" #include "user.h" #include "users_impl.h" #include "admins_impl.h" @@ -309,7 +309,7 @@ sigaction(SIGSEGV, &newsa, &oldsa);*/ return; } //----------------------------------------------------------------------------- -int StartScriptExecuter(char * procName, int msgKey, int * msgID, SETTINGS * settings) +int StartScriptExecuter(char * procName, int msgKey, int * msgID, SETTINGS_IMPL * settings) { STG_LOGGER & WriteServLog = GetStgLogger(); @@ -317,7 +317,6 @@ if (*msgID == -11) // If msgID == -11 - first call. Create queue { for (int i = 0; i < 2; i++) { - //WriteServLog("Creating queue with key=%d ...", msgKey); *msgID = msgget(msgKey, IPC_CREAT | IPC_EXCL | 0600); if (*msgID == -1) @@ -331,7 +330,6 @@ if (*msgID == -11) // If msgID == -11 - first call. Create queue else { msgctl(*msgID, IPC_RMID, NULL); - //printfd(__FILE__, "Queue removed!"); } } else @@ -346,20 +344,16 @@ pid_t executerPid = fork(); switch (executerPid) { - case -1: // ìÁÖÁ + case -1: WriteServLog("Fork error!"); return -1; - case 0: // ðÏÔÏÍÏË - //close(0); - //close(1); - //close(2); - //setsid(); + case 0: delete settings; Executer(msgKey, *msgID, executerPid, procName); return 1; - default: // ïÓÎÏ×ÎÏÊ ÐÒÏÃÅÓÓ + default: if (executersPid.empty()) { Executer(msgKey, *msgID, executerPid, NULL); } @@ -381,23 +375,21 @@ unlink(startFile.c_str()); switch (stgChildPid) { - case -1: // ìÁÖÁ + case -1: return -1; break; - case 0: // ðÏÔÏÍÏË - //close(0); + case 0: close(1); close(2); setsid(); break; - default: // ïÓÎÏ×ÎÏÊ ÐÒÏÃÅÓÓ + default: for (int i = 0; i < 120 * 5; i++) { if (access(startFile.c_str(), F_OK) == 0) { - //printf("Fork successfull. Exit.\n"); unlink(startFile.c_str()); exit(0); } @@ -450,7 +442,7 @@ int main(int argc, char * argv[]) - Fork and exit * */ -SETTINGS * settings = NULL; +SETTINGS_IMPL * settings = NULL; STORE * dataStore = NULL; TARIFFS_IMPL * tariffs = NULL; ADMINS_IMPL * admins = NULL; @@ -475,13 +467,12 @@ if (getuid()) } if (argc == 2) - settings = new SETTINGS(argv[1]); + settings = new SETTINGS_IMPL(argv[1]); else - settings = new SETTINGS(); + settings = new SETTINGS_IMPL(); if (settings->ReadSettings()) { - //printfd(__FILE__, "ReadSettings error.\n"); STG_LOGGER & WriteServLog = GetStgLogger(); if (settings->GetLogFileName() != "") @@ -558,7 +549,7 @@ traffCnt->SetMonitorDir(settings->GetMonitorDir()); modSettings = settings->GetModulesSettings(); -for (unsigned i = 0; i < modSettings.size(); i++) +for (size_t i = 0; i < modSettings.size(); i++) { string modulePath = settings->GetModulesPath(); modulePath += "/mod_"; @@ -617,8 +608,7 @@ while (modIter != modules.end()) //printfd(__FILE__, "Error: %s\n", capRunner.GetStrError().c_str()); goto exitLbl; } - WriteServLog("Module: \'%s\'. Start successfull. %d", modIter->GetPlugin()->GetVersion().c_str(), - modIter->GetPlugin()->GetStartPosition()); + WriteServLog("Module: '%s'. Start successfull.", modIter->GetPlugin()->GetVersion().c_str()); ++modIter; } SetSignalHandlers(); @@ -733,30 +723,20 @@ if (res) else WriteServLog("Queue removed successfully."); -/*struct sigaction newsa, oldsa; -sigset_t sigmask; -sigemptyset(&sigmask); -sigaddset(&sigmask, SIGCHLD); -newsa.sa_handler = SIG_IGN; -newsa.sa_mask = sigmask; -newsa.sa_flags = 0; -sigaction(SIGCHLD, &newsa, &oldsa);*/ - KillExecuters(); StopStgTimer(); WriteServLog("StgTimer: Stop successfull."); -WriteServLog("Stg stopped successfully."); -sleep(1); -WriteServLog("---------------------------------------------"); - delete traffCnt; delete users; delete admins; delete tariffs; delete settings; +WriteServLog("Stg stopped successfully."); +WriteServLog("---------------------------------------------"); + return 0; } //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugin_runner.cpp b/projects/stargazer/plugin_runner.cpp index e21bb75d..be43e1ec 100644 --- a/projects/stargazer/plugin_runner.cpp +++ b/projects/stargazer/plugin_runner.cpp @@ -26,21 +26,24 @@ #include #include -#include #include "plugin_runner.h" #include "common.h" -#include "conffiles.h" +#include "settings_impl.h" +#include "admins_impl.h" +#include "tariffs_impl.h" +#include "users_impl.h" +#include "traffcounter.h" //----------------------------------------------------------------------------- PLUGIN_RUNNER::PLUGIN_RUNNER(const std::string & pFileName, const MODULE_SETTINGS & ms, - ADMINS * a, - TARIFFS * t, - USERS * u, + ADMINS_IMPL * a, + TARIFFS_IMPL * t, + USERS_IMPL * u, TRAFFCOUNTER * tc, STORE * st, - const SETTINGS * s) + const SETTINGS_IMPL * s) : pluginFileName(pFileName), pluginSettingFileName(), plugin(NULL), @@ -103,11 +106,18 @@ if (isPluginLoaded) Unload(); } -isPluginLoaded = 0; +isPluginLoaded = false; } //----------------------------------------------------------------------------- PLUGIN * PLUGIN_RUNNER::GetPlugin() { +if (!isPluginLoaded) + { + errorStr = "Plugin '" + pluginFileName + "' is not loaded yet!"; + printfd(__FILE__, "PLUGIN_LOADER::GetPlugin() - %s\n", errorStr.c_str()); + return NULL; + } + return plugin; } //----------------------------------------------------------------------------- @@ -117,6 +127,13 @@ if (!isPluginLoaded) if (Load()) return -1; +if (!plugin) + { + errorStr = "Plugin '" + pluginFileName + "' was not created!"; + printfd(__FILE__, "PLUGIN_LOADER::Start() - %s\n", errorStr.c_str()); + return -1; + } + plugin->SetTariffs(tariffs); plugin->SetAdmins(admins); plugin->SetUsers(users); @@ -129,20 +146,47 @@ if (plugin->Start()) errorStr = plugin->GetStrError(); return -1; } + return 0; } //----------------------------------------------------------------------------- int PLUGIN_RUNNER::Stop() { +if (!isPluginLoaded) + { + errorStr = "Plugin '" + pluginFileName + "' was not loaded yet!"; + printfd(__FILE__, "PLUGIN_LOADER::Stop() - %s\n", errorStr.c_str()); + return -1; + } + +if (!plugin) + { + errorStr = "Plugin '" + pluginFileName + "' was not created!"; + printfd(__FILE__, "PLUGIN_LOADER::Stop() - %s\n", errorStr.c_str()); + return -1; + } + plugin->Stop(); -//if (Unload()) -// return -1; return 0; } //----------------------------------------------------------------------------- int PLUGIN_RUNNER::Reload() { +if (!isPluginLoaded) + { + errorStr = "Plugin '" + pluginFileName + "' was not loaded yet!"; + printfd(__FILE__, "PLUGIN_LOADER::Reload() - %s\n", errorStr.c_str()); + return -1; + } + +if (!plugin) + { + errorStr = "Plugin '" + pluginFileName + "' was not created!"; + printfd(__FILE__, "PLUGIN_LOADER::Reload() - %s\n", errorStr.c_str()); + return -1; + } + int res = plugin->Reload(); errorStr = plugin->GetStrError(); return res; @@ -151,16 +195,35 @@ return res; bool PLUGIN_RUNNER::IsRunning() { if (!isPluginLoaded) + { + errorStr = "Plugin '" + pluginFileName + "' was not loaded yet!"; + printfd(__FILE__, "PLUGIN_LOADER::IsRunning() - %s\n", errorStr.c_str()); + return false; + } + +if (!plugin) + { + errorStr = "Plugin '" + pluginFileName + "' was not created!"; + printfd(__FILE__, "PLUGIN_LOADER::IsRunning() - %s\n", errorStr.c_str()); return false; + } + return plugin->IsRunning(); } //----------------------------------------------------------------------------- int PLUGIN_RUNNER::Load() { -if (!pluginFileName.size()) +if (isPluginLoaded) { - errorStr = "Plugin loading failed. No plugin"; - printfd(__FILE__, "%s\n", errorStr.c_str()); + errorStr = "Plugin '" + pluginFileName + "' was already loaded!"; + printfd(__FILE__, "PLUGIN_LOADER::Load() - %s\n", errorStr.c_str()); + return -1; + } + +if (pluginFileName.empty()) + { + errorStr = "Empty plugin file name!"; + printfd(__FILE__, "PLUGIN_LOADER::Load() - %s\n", errorStr.c_str()); return -1; } @@ -168,33 +231,36 @@ libHandle = dlopen(pluginFileName.c_str(), RTLD_NOW); if (!libHandle) { - errorStr = std::string("Plugin loading failed. ") + dlerror(); - printfd(__FILE__, "%s\n", errorStr.c_str()); + errorStr = "Error loading plugin '" + + pluginFileName + "': '" + dlerror() + "'"; + printfd(__FILE__, "PLUGIN_LOADER::Load() - %s\n", errorStr.c_str()); return -1; } +isPluginLoaded = true; + PLUGIN * (*GetPlugin)(); GetPlugin = (PLUGIN * (*)())dlsym(libHandle, "GetPlugin"); if (!GetPlugin) { errorStr = std::string("GetPlugin() not found. ") + dlerror(); + printfd(__FILE__, "PLUGIN_LOADER::Load() - %s\n", errorStr.c_str()); return -1; } plugin = GetPlugin(); -isPluginLoaded++; if (!plugin) { errorStr = "Plugin was not created!"; - printfd(__FILE__, "%s\n", errorStr.c_str()); + printfd(__FILE__, "PLUGIN_LOADER::Load() - %s\n", errorStr.c_str()); return -1; } plugin->SetSettings(modSettings); -printfd(__FILE__, "Plugin %s parsesettings\n", plugin->GetVersion().c_str()); if (plugin->ParseSettings()) { - errorStr = "Plugin \'" + plugin->GetVersion() + "\' error: " + plugin->GetStrError(); + errorStr = plugin->GetStrError(); + printfd(__FILE__, "PLUGIN_LOADER::Load() - Failed to parse settings. Plugin reports: '%s'\n", errorStr.c_str()); return -1; } @@ -207,27 +273,15 @@ if (isPluginLoaded) { if (dlclose(libHandle)) { - errorStr = dlerror(); - printfd(__FILE__, "Error unloading plugin '%s': '%s'", pluginFileName.c_str(), dlerror()); + errorStr = "Failed to unload plugin '"; + errorStr += pluginFileName + "': "; + errorStr += dlerror(); + printfd(__FILE__, "PLUGIN_LOADER::Unload() - %s", errorStr.c_str()); return -1; } - isPluginLoaded--; + plugin = NULL; + isPluginLoaded = false; } return 0; } //----------------------------------------------------------------------------- -const std::string & PLUGIN_RUNNER::GetStrError() const -{ -return errorStr; -} -//----------------------------------------------------------------------------- -uint16_t PLUGIN_RUNNER::GetStartPosition() const -{ -return plugin->GetStartPosition(); -} -//----------------------------------------------------------------------------- -uint16_t PLUGIN_RUNNER::GetStopPosition() const -{ -return plugin->GetStopPosition(); -} -//----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugin_runner.h b/projects/stargazer/plugin_runner.h index 95ddd680..ba90306c 100644 --- a/projects/stargazer/plugin_runner.h +++ b/projects/stargazer/plugin_runner.h @@ -27,28 +27,30 @@ #ifndef PLUGIN_RUNNER_H #define PLUGIN_RUNNER_H -#include - #include -#include "plugin.h" #include "module_settings.h" -#include "traffcounter.h" -#include "tariffs.h" -#include "admins.h" -#include "users.h" +#include "plugin.h" +#include "os_int.h" + +class SETTINGS_IMPL; +class ADMINS_IMPL; +class TARIFFS_IMPL; +class USERS_IMPL; +class TRAFFCOUNTER; +class STORE; //----------------------------------------------------------------------------- class PLUGIN_RUNNER { public: PLUGIN_RUNNER(const std::string & pluginFileName, const MODULE_SETTINGS & ms, - ADMINS * admins, - TARIFFS * tariffs, - USERS * users, + ADMINS_IMPL * admins, + TARIFFS_IMPL * tariffs, + USERS_IMPL * users, TRAFFCOUNTER * tc, STORE * store, - const SETTINGS * s); + const SETTINGS_IMPL * s); PLUGIN_RUNNER(const PLUGIN_RUNNER & rvalue); ~PLUGIN_RUNNER(); @@ -60,33 +62,33 @@ public: int Restart(); bool IsRunning(); - const std::string & GetStrError() const; + const std::string & GetStrError() const { return errorStr; } PLUGIN * GetPlugin(); const std::string & GetFileName() const { return pluginFileName; } int Load(); int Unload(); - uint16_t GetStartPosition() const; - uint16_t GetStopPosition() const; + uint16_t GetStartPosition() const { return plugin->GetStartPosition(); } + uint16_t GetStopPosition() const { return plugin->GetStopPosition(); } private: std::string pluginFileName; std::string pluginSettingFileName; PLUGIN * plugin; - int isPluginLoaded; + bool isPluginLoaded; std::string errorStr; void * libHandle; bool isRunning; - ADMINS * admins; - TARIFFS * tariffs; - USERS * users; + ADMINS_IMPL * admins; + TARIFFS_IMPL * tariffs; + USERS_IMPL * users; STORE * store; TRAFFCOUNTER * traffCnt; - const SETTINGS * stgSettings; + const SETTINGS_IMPL * stgSettings; MODULE_SETTINGS modSettings; }; //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp index 4e60829d..7062966f 100644 --- a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp +++ b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp @@ -42,7 +42,7 @@ #include "stg_locker.h" #include "tariff.h" #include "user_property.h" -#include "../../../settings.h" +#include "settings.h" extern volatile const time_t stgTime; diff --git a/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp b/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp index af741985..a5467aae 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp +++ b/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp @@ -6,10 +6,10 @@ #include "rpcconfig.h" +#include "common.h" #include "admin.h" #include "module_settings.h" -#include "../../../settings.h" -#include "common.h" +#include "settings.h" #include "info_methods.h" #include "users_methods.h" diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser.cpp index 8a01f169..042df803 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser.cpp @@ -13,7 +13,7 @@ #include "version.h" #include "tariffs.h" #include "user_property.h" -#include "../../../settings.h" +#include "settings.h" #define UNAME_LEN (256) //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/other/ping/ping.cpp b/projects/stargazer/plugins/other/ping/ping.cpp index f9fc387a..6a04c6fe 100644 --- a/projects/stargazer/plugins/other/ping/ping.cpp +++ b/projects/stargazer/plugins/other/ping/ping.cpp @@ -8,7 +8,6 @@ #include "user.h" #include "stg_locker.h" #include "user_property.h" -#include "../../../settings.h" class PING_CREATOR { diff --git a/projects/stargazer/settings_impl.cpp b/projects/stargazer/settings_impl.cpp index 8af7f7aa..0ee78fa8 100644 --- a/projects/stargazer/settings_impl.cpp +++ b/projects/stargazer/settings_impl.cpp @@ -32,14 +32,14 @@ $Author: faust $ #include #include -#include "settings.h" +#include "settings_impl.h" #include "stg_logger.h" #include "dotconfpp.h" using namespace std; //----------------------------------------------------------------------------- -SETTINGS::SETTINGS() +SETTINGS_IMPL::SETTINGS_IMPL() : confDir("/etc/stargazer"), scriptsDir("/etc/stargazer"), pidFile("/var/run/stargazer.pid"), @@ -61,7 +61,7 @@ SETTINGS::SETTINGS() { } //----------------------------------------------------------------------------- -SETTINGS::SETTINGS(const std::string & cd) +SETTINGS_IMPL::SETTINGS_IMPL(const std::string & cd) : confDir(cd), scriptsDir(cd), monitoring(false), @@ -82,7 +82,7 @@ SETTINGS::SETTINGS(const std::string & cd) { } //----------------------------------------------------------------------------- -SETTINGS::SETTINGS(const SETTINGS & rval) +SETTINGS_IMPL::SETTINGS_IMPL(const SETTINGS_IMPL & rval) : confDir(rval.confDir), scriptsDir(rval.scriptsDir), pidFile(rval.pidFile), @@ -104,11 +104,7 @@ SETTINGS::SETTINGS(const SETTINGS & rval) { } //----------------------------------------------------------------------------- -SETTINGS::~SETTINGS() -{ -} -//----------------------------------------------------------------------------- -int SETTINGS::ParseYesNo(const string & value, bool * val) +int SETTINGS_IMPL::ParseYesNo(const string & value, bool * val) { if (0 == strcasecmp(value.c_str(), "yes")) { @@ -125,7 +121,7 @@ strError = "Incorrect value \'" + value + "\'."; return -1; } //----------------------------------------------------------------------------- -int SETTINGS::ParseInt(const string & value, int * val) +int SETTINGS_IMPL::ParseInt(const string & value, int * val) { if (str2x(value, *val)) { @@ -135,7 +131,7 @@ if (str2x(value, *val)) return 0; } //----------------------------------------------------------------------------- -int SETTINGS::ParseUnsigned(const string & value, unsigned * val) +int SETTINGS_IMPL::ParseUnsigned(const string & value, unsigned * val) { if (str2x(value, *val)) { @@ -145,7 +141,7 @@ if (str2x(value, *val)) return 0; } //----------------------------------------------------------------------------- -int SETTINGS::ParseIntInRange(const string & value, int min, int max, int * val) +int SETTINGS_IMPL::ParseIntInRange(const string & value, int min, int max, int * val) { if (ParseInt(value, val) != 0) return -1; @@ -159,7 +155,7 @@ if (*val < min || *val > max) return 0; } //----------------------------------------------------------------------------- -int SETTINGS::ParseUnsignedInRange(const string & value, unsigned min, unsigned max, unsigned * val) +int SETTINGS_IMPL::ParseUnsignedInRange(const string & value, unsigned min, unsigned max, unsigned * val) { if (ParseUnsigned(value, val) != 0) return -1; @@ -173,7 +169,7 @@ if (*val < min || *val > max) return 0; } //----------------------------------------------------------------------------- -int SETTINGS::ParseModuleSettings(const DOTCONFDocumentNode * node, vector * params) +int SETTINGS_IMPL::ParseModuleSettings(const DOTCONFDocumentNode * node, vector * params) { const DOTCONFDocumentNode * childNode; PARAM_VALUE pv; @@ -212,14 +208,14 @@ while (childNode) return 0; } //----------------------------------------------------------------------------- -void SETTINGS::ErrorCallback(void * data, const char * buf) +void SETTINGS_IMPL::ErrorCallback(void * data, const char * buf) { printfd(__FILE__, buf); - SETTINGS * settings = static_cast(data); + SETTINGS_IMPL * settings = static_cast(data); settings->logger(buf); } //----------------------------------------------------------------------------- -int SETTINGS::ReadSettings() +int SETTINGS_IMPL::ReadSettings() { const char * requiredOptions[] = { "ModulesPath", @@ -240,7 +236,7 @@ int storeModulesCount = 0; modulesSettings.clear(); DOTCONFDocument conf(DOTCONFDocument::CASEINSENSITIVE); -conf.setErrorCallback(SETTINGS::ErrorCallback, this); +conf.setErrorCallback(SETTINGS_IMPL::ErrorCallback, this); conf.setRequiredOptionNames(requiredOptions); string confFile = confDir + "/stargazer.conf"; @@ -479,7 +475,7 @@ while (node) return 0; } //----------------------------------------------------------------------------- -int SETTINGS::ParseDetailStatWritePeriod(const string & detailStatPeriodStr) +int SETTINGS_IMPL::ParseDetailStatWritePeriod(const string & detailStatPeriodStr) { if (detailStatPeriodStr == "1") { diff --git a/projects/stargazer/settings_impl.h b/projects/stargazer/settings_impl.h index 86262808..b3e0f981 100644 --- a/projects/stargazer/settings_impl.h +++ b/projects/stargazer/settings_impl.h @@ -34,12 +34,13 @@ */ -#ifndef SETTINGS_H -#define SETTINGS_H +#ifndef SETTINGS_IMPL_H +#define SETTINGS_IMPL_H #include #include +#include "settings.h" #include "common.h" #include "stg_logger.h" #include "module_settings.h" @@ -55,12 +56,12 @@ dsPeriod_1_6, class STG_LOGGER; class DOTCONFDocumentNode; //----------------------------------------------------------------------------- -class SETTINGS { +class SETTINGS_IMPL : public SETTINGS { public: - SETTINGS(); - SETTINGS(const std::string &); - SETTINGS(const SETTINGS &); - virtual ~SETTINGS(); + SETTINGS_IMPL(); + SETTINGS_IMPL(const std::string &); + SETTINGS_IMPL(const SETTINGS_IMPL &); + virtual ~SETTINGS_IMPL() {} int Reload() { return ReadSettings(); } int ReadSettings(); @@ -68,14 +69,14 @@ public: int GetExecMsgKey() const { return stgExecMsgKey; } unsigned GetExecutersNum() const { return executersNum; } - const std::string & GetDirName(int num) const { return dirName[num]; }; + const std::string & GetDirName(size_t num) const { return dirName[num]; } const std::string & GetConfDir() const { return confDir; } const std::string & GetScriptsDir() const { return scriptsDir; } const std::string & GetRulesFileName() const { return rules; } const std::string & GetLogFileName() const { return logFile; } const std::string & GetPIDFileName() const { return pidFile; } unsigned GetDetailStatWritePeriod() const - { return detailStatWritePeriod; }; + { return detailStatWritePeriod; } unsigned GetStatWritePeriod() const { return statWritePeriod * 60; } unsigned GetDayFee() const { return dayFee; } bool GetFullFee() const { return fullFee; } diff --git a/projects/stargazer/store_loader.cpp b/projects/stargazer/store_loader.cpp index f012acd4..dbb6d36e 100644 --- a/projects/stargazer/store_loader.cpp +++ b/projects/stargazer/store_loader.cpp @@ -33,9 +33,9 @@ #include "store_loader.h" #include "common.h" #include "store.h" -#include "settings.h" +#include "settings_impl.h" -STORE_LOADER::STORE_LOADER(const SETTINGS & settings) +STORE_LOADER::STORE_LOADER(const SETTINGS_IMPL & settings) : isLoaded(false), handle(NULL), plugin(NULL), @@ -52,16 +52,17 @@ Unload(); bool STORE_LOADER::Load() { -printfd(__FILE__, "STORE_LOADER::Load()\n"); if (isLoaded) { + errorStr = "Store plugin '" + pluginFileName + "' was alredy loaded!"; + printfd(__FILE__, "STORE_LOADER::Load() - %s\n", errorStr.c_str()); return false; } if (pluginFileName.empty()) { errorStr = "Empty store plugin filename"; - printfd(__FILE__, "STORE_LOADER::Load - %s\n", errorStr.c_str()); + printfd(__FILE__, "STORE_LOADER::Load() - %s\n", errorStr.c_str()); return true; } @@ -71,7 +72,7 @@ if (!handle) { errorStr = "Error loading plugin '" + pluginFileName + "': '" + dlerror() + "'"; - printfd(__FILE__, "STORE_LOADER::Load - %s\n", errorStr.c_str()); + printfd(__FILE__, "STORE_LOADER::Load() - %s\n", errorStr.c_str()); return true; } @@ -81,8 +82,8 @@ STORE * (*GetStore)(); GetStore = (STORE * (*)())dlsym(handle, "GetStore"); if (!GetStore) { - errorStr = "GetStore not found."; - printfd(__FILE__, "STORE_LOADER::Load - %s\n", errorStr.c_str()); + errorStr = std::string("GetStore() not found! ") + dlerror(); + printfd(__FILE__, "STORE_LOADER::Load() - %s\n", errorStr.c_str()); return true; } @@ -90,8 +91,8 @@ plugin = GetStore(); if (!plugin) { - errorStr = "NULL store plugin"; - printfd(__FILE__, "STORE_LOADER::Load - %s\n"); + errorStr = "Plugin was not created!"; + printfd(__FILE__, "STORE_LOADER::Load() - %s\n"); return true; } @@ -99,7 +100,7 @@ plugin->SetSettings(storeSettings); if (plugin->ParseSettings()) { errorStr = plugin->GetStrError(); - printfd(__FILE__, "Failed to parse settings. Plugin reports: '%s'\n", errorStr.c_str()); + printfd(__FILE__, "STORE_LOADER::Load() - Failed to parse settings. Plugin reports: '%s'\n", errorStr.c_str()); return true; } @@ -111,15 +112,15 @@ bool STORE_LOADER::Unload() printfd(__FILE__, "STORE_LOADER::Unload()\n"); if (!isLoaded) { - return false; + return true; } if (dlclose(handle)) { - errorStr = "Failed to unload plugin: '"; + errorStr = "Failed to unload plugin '"; + errorStr += pluginFileName + "': "; errorStr += dlerror(); - errorStr += "'"; - printfd(__FILE__, "STORE_LOADER::Unload - %s\n", errorStr.c_str()); + printfd(__FILE__, "STORE_LOADER::Unload() - %s\n", errorStr.c_str()); return true; } diff --git a/projects/stargazer/store_loader.h b/projects/stargazer/store_loader.h index 1f624e1a..a9bb3a44 100644 --- a/projects/stargazer/store_loader.h +++ b/projects/stargazer/store_loader.h @@ -37,11 +37,11 @@ #include "noncopyable.h" class STORE; -class SETTINGS; +class SETTINGS_IMPL; class STORE_LOADER : private NONCOPYABLE { public: - STORE_LOADER(const SETTINGS & settings); + STORE_LOADER(const SETTINGS_IMPL & settings); ~STORE_LOADER(); bool Load(); diff --git a/projects/stargazer/user_impl.cpp b/projects/stargazer/user_impl.cpp index eace1afb..ae77da4f 100644 --- a/projects/stargazer/user_impl.cpp +++ b/projects/stargazer/user_impl.cpp @@ -41,13 +41,13 @@ #include "user_impl.h" #include "users.h" #include "common.h" -#include "settings.h" +#include "settings_impl.h" #include "script_executer.h" #include "tariff.h" #include "tariffs.h" #include "admin.h" -USER_IMPL::USER_IMPL(const SETTINGS * s, +USER_IMPL::USER_IMPL(const SETTINGS_IMPL * s, const STORE * st, const TARIFFS * t, const ADMIN * a, diff --git a/projects/stargazer/user_impl.h b/projects/stargazer/user_impl.h index ba69ced1..7019c3c9 100644 --- a/projects/stargazer/user_impl.h +++ b/projects/stargazer/user_impl.h @@ -48,6 +48,7 @@ class TARIFF; class TARIFFS; class ADMIN; class USER_IMPL; +class SETTINGS_IMPL; //----------------------------------------------------------------------------- class USER_ID_GENERATOR { friend class USER_IMPL; @@ -102,7 +103,7 @@ friend class CHG_TARIFF_NOTIFIER; friend class CHG_CASH_NOTIFIER; friend class CHG_IP_NOTIFIER; public: - USER_IMPL(const SETTINGS * settings, + USER_IMPL(const SETTINGS_IMPL * settings, const STORE * store, const TARIFFS * tariffs, const ADMIN * sysAdmin, @@ -230,7 +231,7 @@ private: TRAFF_STAT traffStat; std::pair traffStatSaved; - const SETTINGS * settings; + const SETTINGS_IMPL * settings; std::set authorizedBy; diff --git a/projects/stargazer/users_impl.cpp b/projects/stargazer/users_impl.cpp index d2c9d7cc..e58e7224 100644 --- a/projects/stargazer/users_impl.cpp +++ b/projects/stargazer/users_impl.cpp @@ -52,7 +52,7 @@ extern const volatile time_t stgTime; //#define USERS_DEBUG 1 //----------------------------------------------------------------------------- -USERS_IMPL::USERS_IMPL(SETTINGS * s, STORE * st, TARIFFS * t, const ADMIN * sa) +USERS_IMPL::USERS_IMPL(SETTINGS_IMPL * s, STORE * st, TARIFFS * t, const ADMIN * sa) : users(), usersToDelete(), userIPNotifiersBefore(), diff --git a/projects/stargazer/users_impl.h b/projects/stargazer/users_impl.h index b9df5981..7a2fc0f9 100644 --- a/projects/stargazer/users_impl.h +++ b/projects/stargazer/users_impl.h @@ -39,7 +39,7 @@ $Author: faust $ #include "os_int.h" #include "store.h" -#include "settings.h" +#include "settings_impl.h" #include "users.h" #include "user.h" #include "user_impl.h" @@ -92,7 +92,7 @@ class USERS_IMPL : private NONCOPYABLE, public USERS { friend class PROPERTY_NOTIFER_IP_AFTER; public: - USERS_IMPL(SETTINGS * s, STORE * store, TARIFFS * tariffs, const ADMIN * sysAdmin); + USERS_IMPL(SETTINGS_IMPL * s, STORE * store, TARIFFS * tariffs, const ADMIN * sysAdmin); virtual ~USERS_IMPL(); int FindByName(const std::string & login, USER_PTR * user); @@ -151,7 +151,7 @@ private: std::map ipIndex; std::map loginIndex; - SETTINGS * settings; + SETTINGS_IMPL * settings; TARIFFS * tariffs; STORE * store; const ADMIN * sysAdmin;