2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author : Maxim Mamontov <faust@stargazer.dp.ua>
23 #include "stg/common.h"
24 #include "stg/store.h"
25 #include "store_loader.h"
26 #include "settings_impl.h"
28 using STG::StoreLoader;
30 StoreLoader::StoreLoader(const SettingsImpl& settings) noexcept
34 storeSettings(settings.GetStoreModuleSettings()),
35 pluginFileName(settings.GetModulesPath() + "/mod_" + storeSettings.moduleName + ".so")
39 StoreLoader::~StoreLoader()
44 bool StoreLoader::load() noexcept
48 errorStr = "Store plugin '" + pluginFileName + "' was already loaded!";
49 printfd(__FILE__, "StoreLoader::load() - %s\n", errorStr.c_str());
53 if (pluginFileName.empty())
55 errorStr = "Empty store plugin filename";
56 printfd(__FILE__, "StoreLoader::load() - %s\n", errorStr.c_str());
60 handle = dlopen(pluginFileName.c_str(), RTLD_NOW);
64 errorStr = "Error loading plugin '"
65 + pluginFileName + "': '" + dlerror() + "'";
66 printfd(__FILE__, "StoreLoader::Load() - %s\n", errorStr.c_str());
72 using Getter = Store* (*)();
73 auto GetStore = reinterpret_cast<Getter>(dlsym(handle, "GetStore"));
76 errorStr = std::string("GetStore() not found! ") + dlerror();
77 printfd(__FILE__, "StoreLoader::load() - %s\n", errorStr.c_str());
85 errorStr = "Plugin was not created!";
86 printfd(__FILE__, "StoreLoader::Load() - %s\n");
90 plugin->SetSettings(storeSettings);
91 if (plugin->ParseSettings())
93 errorStr = plugin->GetStrError();
94 printfd(__FILE__, "StoreLoader::Load() - Failed to parse settings. Plugin reports: '%s'\n", errorStr.c_str());
101 bool StoreLoader::unload() noexcept
110 errorStr = "Failed to unload plugin '";
111 errorStr += pluginFileName + "': ";
112 errorStr += dlerror();
113 printfd(__FILE__, "StoreLoader::Unload() - %s\n", errorStr.c_str());