1 |
torben |
196 |
|
2 |
torben |
26 |
#include "PluginManager.h" |
3 |
|
|
|
4 |
torben |
157 |
#include "Logger.h" |
5 |
torben |
26 |
|
6 |
torben |
132 |
#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 |
torben |
137 |
#include "plugins/HostStatusPlugin.h" |
13 |
torben |
188 |
#include "plugins/WeatherPlugin.h" |
14 |
torben |
193 |
#include "plugins/UrlTriggerPlugin.h" |
15 |
torben |
26 |
|
16 |
|
|
typedef std::map<std::string, Plugin*>::iterator MapIterator; |
17 |
|
|
|
18 |
|
|
PluginManager::PluginManager() |
19 |
|
|
{ |
20 |
|
|
} |
21 |
torben |
196 |
|
22 |
torben |
26 |
PluginManager::~PluginManager() |
23 |
|
|
{ |
24 |
|
|
} |
25 |
|
|
|
26 |
|
|
|
27 |
torben |
28 |
void PluginManager::AddPlugin(Plugin* plugin) |
28 |
|
|
{ |
29 |
torben |
35 |
if (plugin != 0) |
30 |
|
|
{ |
31 |
torben |
184 |
if (plugin->IsHelper()) |
32 |
|
|
{ |
33 |
|
|
_helper_plugins.push_back(plugin); |
34 |
|
|
} |
35 |
|
|
else |
36 |
|
|
{ |
37 |
|
|
std::string command = plugin->GetCommand(); |
38 |
torben |
35 |
|
39 |
torben |
184 |
if ( _plugins[ command ] == 0) |
40 |
|
|
_plugins[ command ] = plugin; |
41 |
|
|
else |
42 |
|
|
Logger::logMessage( std::string("AddPlugin() -- already have a plugin called ") + command); |
43 |
|
|
} |
44 |
torben |
35 |
} |
45 |
|
|
else |
46 |
|
|
{ |
47 |
torben |
157 |
Logger::logMessage("AddPlugin() -- cannot register a null pointer"); |
48 |
torben |
35 |
} |
49 |
torben |
28 |
} |
50 |
|
|
|
51 |
torben |
26 |
void PluginManager::LoadPlugins() |
52 |
|
|
{ |
53 |
|
|
static EchoPlugin echo; |
54 |
torben |
28 |
|
55 |
|
|
static SpamPlugin spam; |
56 |
torben |
26 |
|
57 |
torben |
203 |
static ShellExecPlugin wake("wake", "/usr/local/bin/wake", false, false); |
58 |
torben |
107 |
static ShellExecPlugin ping("ping", "nmap -sP 192.168.10.1-255 | grep appears | awk '{print $2}'", false,true); |
59 |
torben |
35 |
|
60 |
torben |
49 |
static TogPlugin tog; |
61 |
|
|
|
62 |
torben |
101 |
static StatusPlugin status; |
63 |
|
|
|
64 |
torben |
114 |
static ListPlugin list; |
65 |
|
|
|
66 |
torben |
137 |
static HostStatusPlugin hoststatus; |
67 |
|
|
|
68 |
torben |
188 |
static WeatherPlugin weather; |
69 |
|
|
|
70 |
torben |
193 |
static UrlTriggerPlugin urltrigger("tou", "http://t-hoerup.dk/test.php"); |
71 |
|
|
|
72 |
torben |
196 |
for (MapIterator it = _plugins.begin(); it != _plugins.end(); ++it) |
73 |
torben |
26 |
{ |
74 |
|
|
Plugin* pl = (*it).second; |
75 |
torben |
35 |
if (pl != 0) |
76 |
torben |
157 |
Logger::logMessage( std::string("Loaded plugin \"") + pl->GetCommand() + "\" - " + pl->GetDescription() ); |
77 |
torben |
26 |
} |
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 |
|
|
} |