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