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