OpenAB  1.0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
PluginManager.hpp
Go to the documentation of this file.
1 /*
2  * This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5  */
10 #ifndef PLUGINMANAGER_H_
11 #define PLUGINMANAGER_H_
12 
13 #include <string>
14 #include <vector>
15 #include <map>
16 
20 namespace OpenAB {
26 {
27  public:
28 
32  static PluginManager& getInstance();
33 
37  virtual ~PluginManager();
38 
46  void scanDirectory(const std::string& path);
47 
53  std::string getDefaultModulesDirectory() const;
54 
63  std::map<std::string, std::string> getListOfPlugins() const;
64 
71  bool isPluginAvailable(const std::string& pluginName) const;
72 
85  template<typename __C, typename __P>
86  __C* getPluginInstance(const std::string& pluginName, const __P& params);
87 
95  template<typename __C>
96  void freePluginInstance(__C* instance);
97 
98 #ifdef TESTING
99  void clean()
100  {
101  pluginsInfo.clear();
102  loadedModulesInfo.clear();
103  pluginInstancesInfo.clear();
104  }
105 
106  std::map<void*, std::string> getPluginInstancesInfo()
107  {
108  return pluginInstancesInfo;
109  }
110 
111  std::vector<std::string> getLoadedModules()
112  {
113  std::vector<std::string> result;
114  std::map<std::string, LoadedModulesInfo>::iterator it;
115  for (it = loadedModulesInfo.begin(); it != loadedModulesInfo.end(); ++it)
116  {
117  result.push_back((*it).first);
118  }
119 
120  return result;
121  }
122 
123 #endif
124  private:
128  PluginManager();
129 
133  PluginManager(PluginManager const &other);
134 
138  PluginManager& operator=(PluginManager const &other);
139 
146  bool loadModule(const std::string& modulePath);
147 
154  bool unloadModule(const std::string& modulePath);
155 
163  std::string getPluginModuleName(const std::string& pluginName) const;
164 
170  static void pluginLoadedCb(const std::string& name);
171 
172  static std::vector<std::string> loadedPlugins;
173 
174 
175  typedef std::map<std::string, std::string> PluginsInfo;
176 
181  PluginsInfo pluginsInfo;
182 
183  struct LoadedModulesInfo
184  {
185  LoadedModulesInfo() :
186  refCount(0),
187  module(NULL)
188  {}
189 
190  LoadedModulesInfo(void* p) :
191  refCount(0),
192  module(p)
193  {}
194 
195  unsigned int refCount;
196  void* module;
197  };
198 
204  std::map<std::string, LoadedModulesInfo> loadedModulesInfo;
205 
210  std::map<void*, std::string> pluginInstancesInfo;
211 
212  static PluginManager instance;
213 };
214 
215 } // namespace OpenAB
217 
218 #endif // PLUGINMANAGER_H_
__C * getPluginInstance(const std::string &pluginName, const __P &params)
Creates instance of a plugin using plugin specific parameters to initialize it.
Definition: PluginManagerTemplates.hpp:13
static PluginManager & getInstance()
Returns instance of PluginManager.
Definition: PluginManager.cpp:179
bool isPluginAvailable(const std::string &pluginName) const
Checks if given plugin is provided by any module.
Definition: PluginManager.cpp:121
void freePluginInstance(__C *instance)
Frees plugin instance created by getPluginInstance function. Apart from removing instance it will che...
Definition: PluginManagerTemplates.hpp:39
std::string getDefaultModulesDirectory() const
Returns default location of OpenAB modules.
Definition: PluginManager.cpp:110
virtual ~PluginManager()
Destructor, virtual by default.
Definition: PluginManager.cpp:31
std::map< std::string, std::string > getListOfPlugins() const
List all available plugins with information about which modules are providing them. Keys in returned map are pluigins names and their values are modules names that are providing them e.g. PBAP /usr/lib/OpenAB/libOpenAB_plugin_input_pbap.so.
Definition: PluginManager.cpp:128
PluginManager provides way to manage OpenAB plugins. Allows to discover modules that are providing Op...
Definition: PluginManager.hpp:25
void scanDirectory(const std::string &path)
Scans directory for OpenAB modules. Updates list of available plugins.
Definition: PluginManager.cpp:46