/[projects]/smsdaemon/PluginManager.cpp
ViewVC logotype

Contents of /smsdaemon/PluginManager.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 203 - (show annotations) (download)
Fri Dec 19 07:03:34 2008 UTC (15 years, 5 months ago) by torben
File size: 2115 byte(s)
Util: added another exec wrapper

PlugiinManager,  change  path to wake script

1
2 #include "PluginManager.h"
3
4 #include "Logger.h"
5
6 #include "plugins/EchoPlugin.h"
7 #include "plugins/SpamPlugin.h"
8 #include "plugins/ShellExecPlugin.h"
9 #include "plugins/TogPlugin.h"
10 #include "plugins/StatusPlugin.h"
11 #include "plugins/ListPlugin.h"
12 #include "plugins/HostStatusPlugin.h"
13 #include "plugins/WeatherPlugin.h"
14 #include "plugins/UrlTriggerPlugin.h"
15
16 typedef std::map<std::string, Plugin*>::iterator MapIterator;
17
18 PluginManager::PluginManager()
19 {
20 }
21
22 PluginManager::~PluginManager()
23 {
24 }
25
26
27 void PluginManager::AddPlugin(Plugin* plugin)
28 {
29 if (plugin != 0)
30 {
31 if (plugin->IsHelper())
32 {
33 _helper_plugins.push_back(plugin);
34 }
35 else
36 {
37 std::string command = plugin->GetCommand();
38
39 if ( _plugins[ command ] == 0)
40 _plugins[ command ] = plugin;
41 else
42 Logger::logMessage( std::string("AddPlugin() -- already have a plugin called ") + command);
43 }
44 }
45 else
46 {
47 Logger::logMessage("AddPlugin() -- cannot register a null pointer");
48 }
49 }
50
51 void PluginManager::LoadPlugins()
52 {
53 static EchoPlugin echo;
54
55 static SpamPlugin spam;
56
57 static ShellExecPlugin wake("wake", "/usr/local/bin/wake", false, false);
58 static ShellExecPlugin ping("ping", "nmap -sP 192.168.10.1-255 | grep appears | awk '{print $2}'", false,true);
59
60 static TogPlugin tog;
61
62 static StatusPlugin status;
63
64 static ListPlugin list;
65
66 static HostStatusPlugin hoststatus;
67
68 static WeatherPlugin weather;
69
70 static UrlTriggerPlugin urltrigger("tou", "http://t-hoerup.dk/test.php");
71
72 for (MapIterator it = _plugins.begin(); it != _plugins.end(); ++it)
73 {
74 Plugin* pl = (*it).second;
75 if (pl != 0)
76 Logger::logMessage( std::string("Loaded plugin \"") + pl->GetCommand() + "\" - " + pl->GetDescription() );
77 }
78 }
79
80 Plugin* PluginManager::GetPlugin(const std::string& pluginname)
81 {
82 return _plugins[ pluginname ];
83 }
84
85
86 std::vector<Plugin*> PluginManager::GetPluginList()
87 {
88 typedef std::map<std::string, Plugin*>::iterator MapIterator;
89 std::vector<Plugin*> plugin_list;
90
91 for (MapIterator it = _plugins.begin(); it != _plugins.end(); ++it)
92 {
93 Plugin* pl = (*it).second;
94 plugin_list.push_back(pl);
95 }
96
97
98 return plugin_list;
99 }

  ViewVC Help
Powered by ViewVC 1.1.20