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

Diff of /smsdaemon/PluginManager.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 203 by torben, Fri Dec 19 07:03:34 2008 UTC revision 205 by torben, Fri Dec 19 22:29:25 2008 UTC
# Line 2  Line 2 
2  #include "PluginManager.h"  #include "PluginManager.h"
3    
4  #include "Logger.h"  #include "Logger.h"
5    #include "ConfigFile.h"
6    #include "Common.h"
7    #include "Util.h"
8    
9  #include "plugins/EchoPlugin.h"  #include "plugins/EchoPlugin.h"
10  #include "plugins/SpamPlugin.h"  #include "plugins/SpamPlugin.h"
# Line 48  void PluginManager::AddPlugin(Plugin* pl Line 51  void PluginManager::AddPlugin(Plugin* pl
51          }          }
52  }  }
53    
54  void PluginManager::LoadPlugins()  Plugin* PluginManager::CreatePlugin(const std::string& pluginName, const std::map<std::string,std::string>& args)
55  {  {
56          static EchoPlugin echo;          if (pluginName == "echo")
57                    return new EchoPlugin();
58    
59            if (pluginName == "spam")
60                    return new SpamPlugin();
61    
62            if (pluginName == "tog")
63                    return new TogPlugin();
64    
65            if (pluginName == "status")
66                    return new StatusPlugin();
67    
68            if (pluginName == "list")
69                    return new ListPlugin();
70    
71          static SpamPlugin spam;          if (pluginName == "hoststatus")
72                    return new HostStatusPlugin();
73    
74            if (pluginName == "weather")
75                    return new WeatherPlugin();
76    
77            if (pluginName == "shellexec")
78                    return new ShellExecPlugin(args);
79    
80            if (pluginName == "urltrigger")
81                    return new UrlTriggerPlugin(args);
82            
83            return 0;
84    }
85    
86    void PluginManager::LoadPlugins()
87    {
88    /*
89    
90          static ShellExecPlugin wake("wake", "/usr/local/bin/wake", false, false);          static ShellExecPlugin wake("wake", "/usr/local/bin/wake", false, false);
91          static ShellExecPlugin ping("ping", "nmap -sP 192.168.10.1-255 | grep appears | awk '{print $2}'", false,true);          static ShellExecPlugin ping("ping", "nmap -sP 192.168.10.1-255 | grep appears | awk '{print $2}'", false,true);
92    
         static TogPlugin tog;  
93    
         static StatusPlugin status;  
94    
         static ListPlugin list;  
95    
96          static HostStatusPlugin hoststatus;          static UrlTriggerPlugin urltrigger("tou", "http://t-hoerup.dk/test.php");
97    */
98    
99            std::vector<Value> pluginlist = Common::instance()->GetConfigfile()->GetValues("smsdaemon", "plugin");
100    
101            for (unsigned i=0; i<pluginlist.size(); i++)
102            {
103                    std::string current = pluginlist[i];
104                    
105                    std::string name;
106                    unsigned pos = current.find(' ');
107                    std::map<std::string,std::string> args;
108    
109                    std::string argstr;
110    
111                    if (pos == std::string::npos)
112                    {
113                            name = current;
114                    }
115                    else
116                    {
117                            name = Util::str_trim(current.substr(0,pos));
118                            argstr = Util::str_trim(current.substr(pos+1,1024));
119                            args = ConfigHelper::ParseArguments(argstr);
120                    }
121    
122                    Plugin* pl = 0;
123                    try
124                    {      
125                            pl = CreatePlugin(name, args );
126                    }
127                    catch (std::exception& e)
128                    {
129                            Logger::logMessage(std::string("Failed to load plugin ") + name + " with args: " + argstr);
130                            Logger::logMessage(std::string("Reason: ") + e.what());
131                            continue;
132                    }
133    
134                    if (pl)
135                            AddPlugin(pl);
136                    else
137                            Logger::logMessage( std::string("Unknown plugin: ")+name);
138                    
139            }      
140    
         static WeatherPlugin weather;  
141    
         static UrlTriggerPlugin urltrigger("tou", "http://t-hoerup.dk/test.php");  
142    
143          for (MapIterator it = _plugins.begin(); it != _plugins.end(); ++it)          for (MapIterator it = _plugins.begin(); it != _plugins.end(); ++it)
144          {          {
# Line 77  void PluginManager::LoadPlugins() Line 148  void PluginManager::LoadPlugins()
148          }          }
149  }  }
150    
151    void PluginManager::DestroyPlugins()
152    {
153    }
154    
155  Plugin* PluginManager::GetPlugin(const std::string& pluginname)  Plugin* PluginManager::GetPlugin(const std::string& pluginname)
156  {  {
157          return _plugins[ pluginname ];          return _plugins[ pluginname ];

Legend:
Removed from v.203  
changed lines
  Added in v.205

  ViewVC Help
Powered by ViewVC 1.1.20