Skip to content

Commit

Permalink
Merge pull request #494 from fledge-iot/1.9.2RC-FOGL-5977
Browse files Browse the repository at this point in the history
Cherry Pick fix for FOGL-5977
  • Loading branch information
YashTatkondawar authored Oct 2, 2021
2 parents 3273fa8 + d59d450 commit f7a2db7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
17 changes: 16 additions & 1 deletion C/services/common/include/binary_plugin_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <logger.h>
#include <dlfcn.h>
#include <plugin_handle.h>
#include <plugin_manager.h>

/**
* The BinaryPluginHandle class is used to represent an interface to
Expand All @@ -21,13 +22,27 @@
class BinaryPluginHandle : public PluginHandle
{
public:
BinaryPluginHandle(const char *, const char *path) { handle = dlopen(path, RTLD_LAZY|RTLD_GLOBAL); }
// for the Storage plugin
BinaryPluginHandle(const char *name, const char *path, tPluginType type) {
handle = dlopen(path, RTLD_LAZY);

Logger::getLogger()->debug("%s - storage plugin / RTLD_LAZY - name :%s: path :%s:", __FUNCTION__, name, path);
}

// for all the others plugins
BinaryPluginHandle(const char *name, const char *path) {
handle = dlopen(path, RTLD_LAZY|RTLD_GLOBAL);

Logger::getLogger()->debug("%s - other plugin / RTLD_LAZY|RTLD_GLOBAL - name :%s: path :%s:", __FUNCTION__, name, path);
}

~BinaryPluginHandle() { if (handle) dlclose(handle); }
void *GetInfo() { return dlsym(handle, "plugin_info"); }
void *ResolveSymbol(const char* sym) { return dlsym(handle, sym); }
void *getHandle() { return handle; }
private:
PLUGIN_HANDLE handle; // pointer returned by dlopen on plugin shared lib

};

#endif
Expand Down
8 changes: 8 additions & 0 deletions C/services/common/include/plugin_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
#include <list>
#include <map>

typedef enum PluginType
{
PLUGIN_TYPE_ID_STORAGE,
PLUGIN_TYPE_ID_OTHER
} tPluginType;

/**
* The manager for plugins.
*
Expand All @@ -37,6 +43,7 @@ class PluginManager {
*getInfo(const PLUGIN_HANDLE);
void getInstalledPlugins(const std::string& type,
std::list<std::string>& plugins);
void setPluginType(tPluginType type);

public:
static PluginManager* instance;
Expand All @@ -53,6 +60,7 @@ class PluginManager {
std::map<PLUGIN_HANDLE, PluginHandle*>
pluginHandleMap;
Logger* logger;
tPluginType m_pluginType;
};

#endif
18 changes: 17 additions & 1 deletion C/services/common/plugin_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ PluginManager *PluginManager::getInstance()
PluginManager::PluginManager()
{
logger = Logger::getLogger();

m_pluginType = PLUGIN_TYPE_ID_OTHER;
}

enum PLUGIN_TYPE {
Expand Down Expand Up @@ -248,6 +250,13 @@ string findPlugin(string name, string _type, string _plugin_path, PLUGIN_TYPE ty
return "";
}

/**
* Set Plugin Type
*/
void PluginManager::setPluginType(tPluginType type) {
m_pluginType = type;
}

/**
* Load a given plugin
*/
Expand Down Expand Up @@ -343,7 +352,14 @@ char buf[MAXPATHLEN];
strncpy(buf, path.c_str(), sizeof(buf));
if (buf[0] && access(buf, F_OK|R_OK) == 0)
{
pluginHandle = new BinaryPluginHandle(name.c_str(), buf);
if (m_pluginType == PLUGIN_TYPE_ID_STORAGE)
{
pluginHandle = new BinaryPluginHandle(name.c_str(), buf, PLUGIN_TYPE_ID_STORAGE);
} else
{
pluginHandle = new BinaryPluginHandle(name.c_str(), buf);
}

hndl = pluginHandle->getHandle();
if (hndl != NULL)
{
Expand Down
1 change: 1 addition & 0 deletions C/services/storage/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ void StorageService::stop()
bool StorageService::loadPlugin()
{
PluginManager *manager = PluginManager::getInstance();
manager->setPluginType(PLUGIN_TYPE_ID_STORAGE);

const char *plugin = config->getValue("plugin");
if (plugin == NULL)
Expand Down

0 comments on commit f7a2db7

Please sign in to comment.