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 : Boris Mikhailenko <stg34@stargazer.dp.ua>
23 $Date: 2010/09/13 05:52:46 $
31 #include "plugin_runner.h"
33 #include "conffiles.h"
35 //-----------------------------------------------------------------------------
36 PLUGIN_RUNNER::PLUGIN_RUNNER(const std::string & pFileName,
37 const MODULE_SETTINGS & ms,
44 : pluginFileName(pFileName),
45 pluginSettingFileName(),
47 isPluginLoaded(false),
60 //-----------------------------------------------------------------------------
61 PLUGIN_RUNNER::PLUGIN_RUNNER(const PLUGIN_RUNNER & rvalue)
62 : pluginFileName(rvalue.pluginFileName),
63 pluginSettingFileName(rvalue.pluginSettingFileName),
64 plugin(rvalue.plugin),
65 isPluginLoaded(rvalue.isPluginLoaded),
66 errorStr(rvalue.errorStr),
67 libHandle(rvalue.libHandle),
68 isRunning(rvalue.isRunning),
69 admins(rvalue.admins),
70 tariffs(rvalue.tariffs),
73 traffCnt(rvalue.traffCnt),
74 stgSettings(rvalue.stgSettings),
75 modSettings(rvalue.modSettings)
78 //-----------------------------------------------------------------------------
79 PLUGIN_RUNNER & PLUGIN_RUNNER::operator=(const PLUGIN_RUNNER & rvalue)
81 pluginFileName = rvalue.pluginFileName;
82 pluginSettingFileName = rvalue.pluginSettingFileName;
83 plugin = rvalue.plugin;
84 isPluginLoaded = rvalue.isPluginLoaded;
85 errorStr = rvalue.errorStr;
86 libHandle = rvalue.libHandle;
87 isRunning = rvalue.isRunning;
88 admins = rvalue.admins;
89 tariffs = rvalue.tariffs;
92 traffCnt = rvalue.traffCnt;
93 stgSettings = rvalue.stgSettings;
94 modSettings = rvalue.modSettings;
98 //-----------------------------------------------------------------------------
99 PLUGIN_RUNNER::~PLUGIN_RUNNER()
108 //-----------------------------------------------------------------------------
109 PLUGIN * PLUGIN_RUNNER::GetPlugin()
113 //-----------------------------------------------------------------------------
114 int PLUGIN_RUNNER::Start()
120 plugin->SetTariffs(tariffs);
121 plugin->SetAdmins(admins);
122 plugin->SetUsers(users);
123 plugin->SetTraffcounter(traffCnt);
124 plugin->SetStore(store);
125 plugin->SetStgSettings(stgSettings);
129 errorStr = plugin->GetStrError();
134 //-----------------------------------------------------------------------------
135 int PLUGIN_RUNNER::Stop()
143 //-----------------------------------------------------------------------------
144 int PLUGIN_RUNNER::Reload()
146 int res = plugin->Reload();
147 errorStr = plugin->GetStrError();
150 //-----------------------------------------------------------------------------
151 bool PLUGIN_RUNNER::IsRunning()
155 return plugin->IsRunning();
157 //-----------------------------------------------------------------------------
158 int PLUGIN_RUNNER::Load()
160 if (!pluginFileName.size())
162 errorStr = "Plugin loading failed. No plugin";
163 printfd(__FILE__, "%s\n", errorStr.c_str());
167 libHandle = dlopen(pluginFileName.c_str(), RTLD_NOW);
171 errorStr = std::string("Plugin loading failed. ") + dlerror();
172 printfd(__FILE__, "%s\n", errorStr.c_str());
176 PLUGIN * (*GetPlugin)();
177 GetPlugin = (PLUGIN * (*)())dlsym(libHandle, "GetPlugin");
180 errorStr = std::string("GetPlugin() not found. ") + dlerror();
183 plugin = GetPlugin();
188 errorStr = "Plugin was not created!";
189 printfd(__FILE__, "%s\n", errorStr.c_str());
193 plugin->SetSettings(modSettings);
194 printfd(__FILE__, "Plugin %s parsesettings\n", plugin->GetVersion().c_str());
195 if (plugin->ParseSettings())
197 errorStr = "Plugin \'" + plugin->GetVersion() + "\' error: " + plugin->GetStrError();
203 //-----------------------------------------------------------------------------
204 int PLUGIN_RUNNER::Unload()
208 if (dlclose(libHandle))
210 errorStr = dlerror();
211 printfd(__FILE__, "Error unloading plugin '%s': '%s'", pluginFileName.c_str(), dlerror());
218 //-----------------------------------------------------------------------------
219 const std::string & PLUGIN_RUNNER::GetStrError() const
223 //-----------------------------------------------------------------------------
224 uint16_t PLUGIN_RUNNER::GetStartPosition() const
226 return plugin->GetStartPosition();
228 //-----------------------------------------------------------------------------
229 uint16_t PLUGIN_RUNNER::GetStopPosition() const
231 return plugin->GetStopPosition();
233 //-----------------------------------------------------------------------------