--- smsdaemon/PluginManager.cpp 2008/12/19 07:03:34 203 +++ smsdaemon/PluginManager.cpp 2008/12/19 22:29:25 205 @@ -2,6 +2,9 @@ #include "PluginManager.h" #include "Logger.h" +#include "ConfigFile.h" +#include "Common.h" +#include "Util.h" #include "plugins/EchoPlugin.h" #include "plugins/SpamPlugin.h" @@ -48,26 +51,94 @@ } } -void PluginManager::LoadPlugins() +Plugin* PluginManager::CreatePlugin(const std::string& pluginName, const std::map& args) { - static EchoPlugin echo; + if (pluginName == "echo") + return new EchoPlugin(); + + if (pluginName == "spam") + return new SpamPlugin(); + + if (pluginName == "tog") + return new TogPlugin(); + + if (pluginName == "status") + return new StatusPlugin(); + + if (pluginName == "list") + return new ListPlugin(); - static SpamPlugin spam; + if (pluginName == "hoststatus") + return new HostStatusPlugin(); + + if (pluginName == "weather") + return new WeatherPlugin(); + + if (pluginName == "shellexec") + return new ShellExecPlugin(args); + + if (pluginName == "urltrigger") + return new UrlTriggerPlugin(args); + + return 0; +} + +void PluginManager::LoadPlugins() +{ +/* static ShellExecPlugin wake("wake", "/usr/local/bin/wake", false, false); static ShellExecPlugin ping("ping", "nmap -sP 192.168.10.1-255 | grep appears | awk '{print $2}'", false,true); - static TogPlugin tog; - static StatusPlugin status; - static ListPlugin list; - static HostStatusPlugin hoststatus; + static UrlTriggerPlugin urltrigger("tou", "http://t-hoerup.dk/test.php"); +*/ + + std::vector pluginlist = Common::instance()->GetConfigfile()->GetValues("smsdaemon", "plugin"); + + for (unsigned i=0; i args; + + std::string argstr; + + if (pos == std::string::npos) + { + name = current; + } + else + { + name = Util::str_trim(current.substr(0,pos)); + argstr = Util::str_trim(current.substr(pos+1,1024)); + args = ConfigHelper::ParseArguments(argstr); + } + + Plugin* pl = 0; + try + { + pl = CreatePlugin(name, args ); + } + catch (std::exception& e) + { + Logger::logMessage(std::string("Failed to load plugin ") + name + " with args: " + argstr); + Logger::logMessage(std::string("Reason: ") + e.what()); + continue; + } + + if (pl) + AddPlugin(pl); + else + Logger::logMessage( std::string("Unknown plugin: ")+name); + + } - static WeatherPlugin weather; - static UrlTriggerPlugin urltrigger("tou", "http://t-hoerup.dk/test.php"); for (MapIterator it = _plugins.begin(); it != _plugins.end(); ++it) { @@ -77,6 +148,10 @@ } } +void PluginManager::DestroyPlugins() +{ +} + Plugin* PluginManager::GetPlugin(const std::string& pluginname) { return _plugins[ pluginname ];