#include <dlfcn.h>
#include <unistd.h>
-#include <signal.h>
+#include "stg/common.h"
+#include "stg/traffcounter.h"
#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 "services_impl.h"
+#include "corps_impl.h"
//-----------------------------------------------------------------------------
-PLUGIN_RUNNER::PLUGIN_RUNNER(const string & pFileName,
+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,
+ SERVICES_IMPL * svc,
+ CORPORATIONS_IMPL * crp,
TRAFFCOUNTER * tc,
- BASE_STORE * st,
- const SETTINGS * s)
+ STORE * st,
+ const SETTINGS_IMPL * s)
: pluginFileName(pFileName),
pluginSettingFileName(),
plugin(NULL),
admins(a),
tariffs(t),
users(u),
+ services(svc),
+ corps(crp),
store(st),
traffCnt(tc),
stgSettings(s),
admins(rvalue.admins),
tariffs(rvalue.tariffs),
users(rvalue.users),
+ services(rvalue.services),
+ corps(rvalue.corps),
store(rvalue.store),
traffCnt(rvalue.traffCnt),
stgSettings(rvalue.stgSettings),
admins = rvalue.admins;
tariffs = rvalue.tariffs;
users = rvalue.users;
+services = rvalue.services;
+corps = rvalue.corps;
store = rvalue.store;
traffCnt = rvalue.traffCnt;
stgSettings = rvalue.stgSettings;
Unload();
}
-isPluginLoaded = 0;
+isPluginLoaded = false;
}
//-----------------------------------------------------------------------------
-BASE_PLUGIN * PLUGIN_RUNNER::GetPlugin()
+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;
}
//-----------------------------------------------------------------------------
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);
+plugin->SetServices(services);
+plugin->SetCorporations(corps);
plugin->SetTraffcounter(traffCnt);
plugin->SetStore(store);
plugin->SetStgSettings(stgSettings);
errorStr = plugin->GetStrError();
return -1;
}
+
return 0;
}
//-----------------------------------------------------------------------------
int PLUGIN_RUNNER::Stop()
{
-plugin->Stop();
+if (!isPluginLoaded)
+ {
+ errorStr = "Plugin '" + pluginFileName + "' was not loaded yet!";
+ printfd(__FILE__, "PLUGIN_LOADER::Stop() - %s\n", errorStr.c_str());
+ return -1;
+ }
-//if (Unload())
-// return -1;
-return 0;
+if (!plugin)
+ {
+ errorStr = "Plugin '" + pluginFileName + "' was not created!";
+ printfd(__FILE__, "PLUGIN_LOADER::Stop() - %s\n", errorStr.c_str());
+ return -1;
+ }
+
+return plugin->Stop();
}
//-----------------------------------------------------------------------------
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;
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;
}
if (!libHandle)
{
- errorStr = 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;
}
-BASE_PLUGIN * (*GetPlugin)();
-GetPlugin = (BASE_PLUGIN * (*)())dlsym(libHandle, "GetPlugin");
+isPluginLoaded = true;
+
+PLUGIN * (*GetPlugin)();
+GetPlugin = (PLUGIN * (*)())dlsym(libHandle, "GetPlugin");
if (!GetPlugin)
{
- errorStr = string("GetPlugin() not found. ") + dlerror();
+ 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;
}
{
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 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();
-}
-//-----------------------------------------------------------------------------
-