Skip to content
Snippets Groups Projects
Commit 010b9124 authored by Aline Gondim Santos's avatar Aline Gondim Santos Committed by Aline Gondim Santos
Browse files

plugins: internalize reload logic

Reload plugins libraries after setting or resetting preferences.
Previously unloading and reloading should be done by client.

GitLab: #418
Change-Id: Ib6938cfe63c2d6a6336adee4994da6a54be7ecd8
parent eacce164
No related branches found
No related tags found
No related merge requests found
......@@ -185,17 +185,22 @@ CallServicesManager::getCallMediaHandlerStatus(const std::string& callId)
return ret;
}
void
bool
CallServicesManager::setPreference(const std::string& key,
const std::string& value,
const std::string& scopeStr)
const std::string& rootPath)
{
bool status {true};
for (auto& mediaHandler : callMediaHandlers_) {
if (scopeStr.find(mediaHandler->getCallMediaHandlerDetails()["name"]) != std::string::npos) {
if (mediaHandler->id().find(rootPath) != std::string::npos) {
if (mediaHandler->preferenceMapHasKey(key)) {
mediaHandler->setPreferenceAttribute(key, value);
status &= false;
}
}
}
return status;
}
void
CallServicesManager::clearCallHandlerMaps(const std::string& callId)
......
......@@ -103,9 +103,9 @@ public:
std::vector<std::string> getCallMediaHandlerStatus(const std::string& callId);
void setPreference(const std::string& key,
bool setPreference(const std::string& key,
const std::string& value,
const std::string& scopeStr);
const std::string& rootPath);
void clearCallHandlerMaps(const std::string& callId);
......
......@@ -178,16 +178,21 @@ ChatServicesManager::getChatHandlerDetails(const std::string& chatHandlerIdStr)
return {};
}
void
bool
ChatServicesManager::setPreference(const std::string& key,
const std::string& value,
const std::string& scopeStr)
const std::string& rootPath)
{
bool status {true};
for (auto& chatHandler : chatHandlers_) {
if (scopeStr.find(chatHandler->getChatHandlerDetails()["name"]) != std::string::npos) {
if (chatHandler->id().find(rootPath) != std::string::npos) {
if (chatHandler->preferenceMapHasKey(key)) {
chatHandler->setPreferenceAttribute(key, value);
status &= false;
}
}
}
return status;
}
void
......
......@@ -58,9 +58,9 @@ public:
*/
std::map<std::string, std::string> getChatHandlerDetails(const std::string& chatHandlerIdStr);
void setPreference(const std::string& key,
bool setPreference(const std::string& key,
const std::string& value,
const std::string& scopeStr);
const std::string& rootPath);
private:
void toggleChatHandler(const uintptr_t chatHandlerId,
......
......@@ -334,35 +334,47 @@ JamiPluginManager::setPluginPreference(const std::string& rootPath,
std::map<std::string, std::string> pluginPreferencesMap
= PluginPreferencesUtils::getPreferencesValuesMap(rootPath);
auto find = pluginPreferencesMap.find(key);
if (find != pluginPreferencesMap.end()) {
std::vector<std::map<std::string, std::string>> preferences
= PluginPreferencesUtils::getPreferences(rootPath);
bool force {pm_.checkLoadedPlugin(rootPath)};
for (auto& preference : preferences) {
if (!preference["key"].compare(key)) {
callsm_.setPreference(key, value, preference["scope"]);
chatsm_.setPreference(key, value, preference["scope"]);
force &= callsm_.setPreference(key, value, rootPath);
force &= chatsm_.setPreference(key, value, rootPath);
break;
}
}
if (force)
unloadPlugin(rootPath);
auto find = pluginPreferencesMap.find(key);
if (find != pluginPreferencesMap.end()) {
pluginUserPreferencesMap[key] = value;
const std::string preferencesValuesFilePath = PluginPreferencesUtils::valuesFilePath(
rootPath);
std::lock_guard<std::mutex> guard(fileutils::getFileLock(preferencesValuesFilePath));
std::ofstream fs(preferencesValuesFilePath, std::ios::binary);
if (!fs.good()) {
if (force) {
loadPlugin(rootPath);
}
return false;
}
try {
msgpack::pack(fs, pluginUserPreferencesMap);
return true;
} catch (const std::exception& e) {
JAMI_ERR() << e.what();
if (force) {
loadPlugin(rootPath);
}
return false;
}
}
return false;
if (force) {
loadPlugin(rootPath);
}
return true;
}
std::map<std::string, std::string>
......@@ -374,7 +386,14 @@ JamiPluginManager::getPluginPreferencesValuesMap(const std::string& rootPath)
bool
JamiPluginManager::resetPluginPreferencesValuesMap(const std::string& rootPath)
{
return PluginPreferencesUtils::resetPreferencesValuesMap(rootPath);
bool loaded {pm_.checkLoadedPlugin(rootPath)};
if (loaded)
unloadPlugin(rootPath);
auto status = PluginPreferencesUtils::resetPreferencesValuesMap(rootPath);
if (loaded) {
loadPlugin(rootPath);
}
return status;
}
std::map<std::string, std::string>
......
......@@ -59,7 +59,7 @@ public:
if (!handle_) {
return false;
}
return ::dlclose(handle_.release());
return !(::dlclose(handle_.release()));
}
void* getSymbol(const char* name) const
......
......@@ -30,6 +30,7 @@
#include <mutex>
#include <string>
#include <vector>
#include <list>
#include <inttypes.h>
......@@ -44,7 +45,7 @@ public:
using ServiceFunction = std::function<int32_t(const DLPlugin*, void*)>;
using ComponentFunction = std::function<int32_t(void*)>;
// A vector to a pair<componentType, componentPtr>
using ComponentTypePtrVector = std::vector<std::pair<std::string, void*>>;
using ComponentTypePtrVector = std::list<std::pair<std::string, void*>>;
private:
struct ObjectFactory
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment