Fledge
An open source edge computing platform for industrial users
binary_plugin_handle.h
1 
2 #ifndef _BINARY_PLUGIN_HANDLE_H
3 #define _BINARY_PLUGIN_HANDLE_H
4 /*
5  * Fledge plugin handle related
6  *
7  * Copyright (c) 2018 OSisoft, LLC
8  *
9  * Released under the Apache 2.0 Licence
10  *
11  * Author: Amandeep Singh Arora
12  */
13 #include <logger.h>
14 #include <dlfcn.h>
15 #include <plugin_handle.h>
16 #include <plugin_manager.h>
17 
23 {
24  public:
25  // for the Storage plugin
26  BinaryPluginHandle(const char *name, const char *path, tPluginType type) {
27  dlerror(); // Clear the existing error
28  handle = dlopen(path, RTLD_LAZY);
29  if (!handle)
30  {
31  Logger::getLogger()->error("Unable to load storage plugin %s, %s",
32  name, dlerror());
33  }
34 
35  Logger::getLogger()->debug("%s - storage plugin / RTLD_LAZY - name :%s: path :%s:", __FUNCTION__, name, path);
36  }
37 
38  // for all the others plugins
39  BinaryPluginHandle(const char *name, const char *path) {
40  dlerror(); // Clear the existing error
41  handle = dlopen(path, RTLD_LAZY|RTLD_GLOBAL);
42  if (!handle)
43  {
44  Logger::getLogger()->error("Unable to load plugin %s, %s",
45  name, dlerror());
46  }
47 
48  Logger::getLogger()->debug("%s - other plugin / RTLD_LAZY|RTLD_GLOBAL - name :%s: path :%s:", __FUNCTION__, name, path);
49  }
50 
51  ~BinaryPluginHandle() { if (handle) dlclose(handle); }
52  void *GetInfo() { return dlsym(handle, "plugin_info"); }
53  void *ResolveSymbol(const char* sym) { return dlsym(handle, sym); }
54  void *getHandle() { return handle; }
55  private:
56  PLUGIN_HANDLE handle; // pointer returned by dlopen on plugin shared lib
57 
58 };
59 
60 #endif
61 
The PluginHandle class is used to represent an opaque handle to a plugin instance.
Definition: plugin_handle.h:24
The BinaryPluginHandle class is used to represent an interface to a plugin that is available in a bin...
Definition: binary_plugin_handle.h:22