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

Contents of /smsdaemon/PluginManager.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 137 - (show annotations) (download)
Sun Dec 7 11:08:31 2008 UTC (15 years, 5 months ago) by torben
File size: 1908 byte(s)
ListPlugin.cpp: dont send the plugin descriptions back to user (too much text)

PluginManager.cpp, HostStatusPlugin.(h|cpp), CMakeLists.txt: 
	Add a new plugin which sends server status back to requester (data is from uptime(1) and df(1) )


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

  ViewVC Help
Powered by ViewVC 1.1.20