#include <dlfcn.h>
+#include "stg/common.h"
+#include "stg/store.h"
#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),
bool STORE_LOADER::Load()
{
-printfd(__FILE__, "STORE_LOADER::Load()\n");
if (isLoaded)
{
+ errorStr = "Store plugin '" + pluginFileName + "' was already 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;
}
{
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;
}
isLoaded = true;
-BASE_STORE * (*GetStore)();
-GetStore = (BASE_STORE * (*)())dlsym(handle, "GetStore");
+STORE * (*GetStore)();
+GetStore = reinterpret_cast<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;
}
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;
}
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;
}
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;
}