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

Contents of /smsdaemon/PluginManager.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 45 - (show annotations) (download)
Wed Jun 11 09:00:56 2008 UTC (15 years, 11 months ago) by torben
Original Path: smsdaemon/plugins/PluginManager.cpp
File size: 1508 byte(s)
CMakeLists.txt added a smsdaemon core library in order to ease testing.

The other changes is to make this new library work correctly

1
2 #include "PluginManager.h"
3
4 #include "common.h"
5
6 #include "EchoPlugin.h"
7 #include "SpamPlugin.h"
8 #include "ShellExecPlugin.h"
9
10
11 typedef std::map<std::string, Plugin*>::iterator MapIterator;
12
13 PluginManager::PluginManager()
14 {
15 }
16
17 PluginManager::~PluginManager()
18 {
19 }
20
21
22 void PluginManager::AddPlugin(Plugin* plugin)
23 {
24 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 }
40
41 void PluginManager::LoadPlugins()
42 {
43 Common* cmn = Common::instance();
44
45 static EchoPlugin echo;
46
47 static SpamPlugin spam;
48
49 static ShellExecPlugin wake("wake", "/home/torben/bin/wake");
50
51
52 for(MapIterator it = _plugins.begin(); it != _plugins.end(); ++it)
53 {
54 Plugin* pl = (*it).second;
55 if (pl != 0)
56 cmn->logMessage( std::string("Loaded plugin \"") + pl->GetCommand() + "\" - " + pl->GetDescription() );
57 }
58 }
59
60 Plugin* PluginManager::GetPlugin(const std::string& pluginname)
61 {
62 return _plugins[ pluginname ];
63 }
64
65
66 std::vector<Plugin*> PluginManager::GetPluginList()
67 {
68 typedef std::map<std::string, Plugin*>::iterator MapIterator;
69 std::vector<Plugin*> plugin_list;
70
71 for (MapIterator it = _plugins.begin(); it != _plugins.end(); ++it)
72 {
73 Plugin* pl = (*it).second;
74 plugin_list.push_back(pl);
75 }
76
77
78 return plugin_list;
79 }

  ViewVC Help
Powered by ViewVC 1.1.20