Fledge
An open source edge computing platform for industrial users
plugin_manager.h
1 #ifndef PLUGIN_MANAGER_H
2 #define PLUGIN_MANAGER_H
3 /*
4  * Fledge storage service.
5  *
6  * Copyright (c) 2017, 2018 OSisoft, LLC
7  *
8  * Released under the Apache 2.0 Licence
9  *
10  * Author: Mark Riddoch, Massimiliano Pinto
11  */
12 
13 #include <plugin_api.h>
14 #include <plugin_handle.h>
15 #include <logger.h>
16 #include <string>
17 #include <list>
18 #include <map>
19 #include <vector>
20 
21 typedef enum PluginType
22 {
23  PLUGIN_TYPE_ID_STORAGE,
24  PLUGIN_TYPE_ID_OTHER
25 } tPluginType;
26 
27 enum PLUGIN_TYPE {
28  BINARY_PLUGIN,
29  PYTHON_PLUGIN,
30  JSON_PLUGIN
31 };
32 
33 
41  public:
42  static PluginManager *getInstance();
43  PLUGIN_HANDLE loadPlugin(const std::string& name,
44  const std::string& type);
45  void unloadPlugin(PLUGIN_HANDLE handle);
46  void* resolveSymbol(PLUGIN_HANDLE handle,
47  const std::string& symbol);
48  PLUGIN_HANDLE findPluginByName(const std::string& name);
49  PLUGIN_HANDLE findPluginByType(const std::string& type);
51  *getInfo(const PLUGIN_HANDLE);
52  void getInstalledPlugins(const std::string& type,
53  std::list<std::string>& plugins);
54  void setPluginType(tPluginType type);
55  PLUGIN_TYPE getPluginImplType(const PLUGIN_HANDLE hndl) { return pluginImplTypes[hndl]; }
56  std::vector<std::string> getPluginsByFlags(const std::string& type, unsigned int flags);
57  public:
58  static PluginManager* instance;
59 
60  private:
61  PluginManager();
62  std::string findPlugin(std::string name, std::string _type, std::string _plugin_path, PLUGIN_TYPE type);
63 
64  private:
65  std::list<PLUGIN_HANDLE> plugins;
66  std::map<std::string, PLUGIN_HANDLE> pluginNames;
67  std::map<std::string, std::string> pluginTypes;
68  std::map<PLUGIN_HANDLE, PLUGIN_TYPE> pluginImplTypes;
69  std::map<PLUGIN_HANDLE, PLUGIN_INFORMATION *>
70  pluginInfo;
71  std::map<PLUGIN_HANDLE, PluginHandle*>
72  pluginHandleMap;
73  Logger* logger;
74  tPluginType m_pluginType;
75 };
76 
77 #endif
Fledge Logger class used to log to syslog.
Definition: logger.h:26
static PluginManager * getInstance()
PluginManager Singleton implementation.
Definition: plugin_manager.cpp:43
The manager for plugins.
Definition: plugin_manager.h:40
std::vector< std::string > getPluginsByFlags(const std::string &type, unsigned int flags)
Return a list of plugins matching the criteria of plugin type and plugin flags.
Definition: plugin_manager.cpp:666
PLUGIN_HANDLE loadPlugin(const std::string &name, const std::string &type)
Load a given plugin.
Definition: plugin_manager.cpp:265
void getInstalledPlugins(const std::string &type, std::list< std::string > &plugins)
Get the installed plugins in the given plugin type subdirectory of "plugins" under FLEDGE_ROOT Plugin...
Definition: plugin_manager.cpp:562
void setPluginType(tPluginType type)
Set Plugin Type.
Definition: plugin_manager.cpp:257
The plugin infiornation structure, used to return information from a plugin during the laod and confi...
Definition: plugin_api.h:23
PLUGIN_INFORMATION * getInfo(const PLUGIN_HANDLE)
Return the information for a named plugin.
Definition: plugin_manager.cpp:531
PLUGIN_HANDLE findPluginByType(const std::string &type)
Find a loaded plugin by type.
Definition: plugin_manager.cpp:519
PLUGIN_HANDLE findPluginByName(const std::string &name)
Find a loaded plugin by name.
Definition: plugin_manager.cpp:507
void * resolveSymbol(PLUGIN_HANDLE handle, const std::string &symbol)
Resolve a symbol within the plugin.
Definition: plugin_manager.cpp:543