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

Contents of /smsdaemon/PluginManager.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 184 - (show annotations) (download)
Fri Dec 12 14:06:11 2008 UTC (15 years, 5 months ago) by torben
File size: 1937 byte(s)
Add the helper plugin concept

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

  ViewVC Help
Powered by ViewVC 1.1.20