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

plugins: split always preference for each handler

GitLab: #395
Change-Id: I8347ffe1a37ccf63d30e028e36e7597226d4ae66
parent a1b677ee
No related branches found
No related tags found
No related merge requests found
...@@ -46,18 +46,20 @@ CallServicesManager::createAVSubject(const StreamData& data, AVSubjectSPtr subje ...@@ -46,18 +46,20 @@ CallServicesManager::createAVSubject(const StreamData& data, AVSubjectSPtr subje
for (auto& callMediaHandler : callMediaHandlers_) { for (auto& callMediaHandler : callMediaHandlers_) {
std::size_t found = callMediaHandler->id().find_last_of(DIR_SEPARATOR_CH); std::size_t found = callMediaHandler->id().find_last_of(DIR_SEPARATOR_CH);
auto preferences = PluginPreferencesUtils::getPreferencesValuesMap( bool toggle = PluginPreferencesUtils::getAlwaysPreference(
callMediaHandler->id().substr(0, found)); callMediaHandler->id().substr(0, found),
bool toggle = preferences.at("always") == "1"; callMediaHandler->getCallMediaHandlerDetails().at("name"));
for (const auto& toggledMediaHandlerPair : mediaHandlerToggled_[data.id]) { for (const auto& toggledMediaHandlerPair : mediaHandlerToggled_[data.id]) {
if (toggledMediaHandlerPair.first == (uintptr_t) callMediaHandler.get()) { if (toggledMediaHandlerPair.first == (uintptr_t) callMediaHandler.get()) {
toggle = toggledMediaHandlerPair.second; toggle = toggledMediaHandlerPair.second;
break; break;
} }
} }
#ifndef __ANDROID__
if (toggle) if (toggle)
#ifndef __ANDROID__
toggleCallMediaHandler((uintptr_t) callMediaHandler.get(), data.id, true); toggleCallMediaHandler((uintptr_t) callMediaHandler.get(), data.id, true);
#else
mediaHandlerToggled_[data.id].insert({(uintptr_t) callMediaHandler.get(), true});
#endif #endif
} }
} }
...@@ -76,6 +78,10 @@ CallServicesManager::registerComponentsLifeCycleManagers(PluginManager& pm) ...@@ -76,6 +78,10 @@ CallServicesManager::registerComponentsLifeCycleManagers(PluginManager& pm)
if (!ptr) if (!ptr)
return -1; return -1;
std::size_t found = ptr->id().find_last_of(DIR_SEPARATOR_CH);
PluginPreferencesUtils::addAlwaysHandlerPreference(ptr->getCallMediaHandlerDetails().at(
"name"),
ptr->id().substr(0, found));
callMediaHandlers_.emplace_back(std::move(ptr)); callMediaHandlers_.emplace_back(std::move(ptr));
return 0; return 0;
}; };
......
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
#pragma once #pragma once
#include "noncopyable.h" #include "noncopyable.h"
#include "logger.h"
#include "manager.h"
#include "sip/sipcall.h"
#include "pluginmanager.h" #include "pluginmanager.h"
#include "streamdata.h" #include "streamdata.h"
#include "mediahandler.h" #include "mediahandler.h"
...@@ -138,5 +141,4 @@ private: ...@@ -138,5 +141,4 @@ private:
/// A map of callIds and MediaHandler-status pairs. /// A map of callIds and MediaHandler-status pairs.
std::map<std::string, std::map<uintptr_t, bool>> mediaHandlerToggled_; std::map<std::string, std::map<uintptr_t, bool>> mediaHandlerToggled_;
}; };
} // namespace jami } // namespace jami
...@@ -39,6 +39,9 @@ ChatServicesManager::registerComponentsLifeCycleManagers(PluginManager& pm) ...@@ -39,6 +39,9 @@ ChatServicesManager::registerComponentsLifeCycleManagers(PluginManager& pm)
if (!ptr) if (!ptr)
return -1; return -1;
handlersNameMap_[ptr->getChatHandlerDetails().at("name")] = (uintptr_t) ptr.get(); handlersNameMap_[ptr->getChatHandlerDetails().at("name")] = (uintptr_t) ptr.get();
std::size_t found = ptr->id().find_last_of(DIR_SEPARATOR_CH);
PluginPreferencesUtils::addAlwaysHandlerPreference(ptr->getChatHandlerDetails().at("name"),
ptr->id().substr(0, found));
chatHandlers_.emplace_back(std::move(ptr)); chatHandlers_.emplace_back(std::move(ptr));
return 0; return 0;
}; };
...@@ -106,9 +109,8 @@ ChatServicesManager::publishMessage(pluginMessagePtr& cm) ...@@ -106,9 +109,8 @@ ChatServicesManager::publishMessage(pluginMessagePtr& cm)
for (auto& chatHandler : chatHandlers_) { for (auto& chatHandler : chatHandlers_) {
std::string chatHandlerName = chatHandler->getChatHandlerDetails().at("name"); std::string chatHandlerName = chatHandler->getChatHandlerDetails().at("name");
std::size_t found = chatHandler->id().find_last_of(DIR_SEPARATOR_CH); std::size_t found = chatHandler->id().find_last_of(DIR_SEPARATOR_CH);
auto preferences = PluginPreferencesUtils::getPreferencesValuesMap( bool toggle = PluginPreferencesUtils::getAlwaysPreference(chatHandler->id().substr(0, found),
chatHandler->id().substr(0, found)); chatHandlerName);
bool toggle = preferences.at("always") == "1";
auto allowedIt = chatAllowDenySet.find(chatHandlerName); auto allowedIt = chatAllowDenySet.find(chatHandlerName);
if (allowedIt != chatAllowDenySet.end()) if (allowedIt != chatAllowDenySet.end())
toggle = (*allowedIt).second; toggle = (*allowedIt).second;
......
...@@ -183,8 +183,6 @@ PluginPreferencesUtils::getPreferencesValuesMap(const std::string& rootPath) ...@@ -183,8 +183,6 @@ PluginPreferencesUtils::getPreferencesValuesMap(const std::string& rootPath)
rmap[pair.first] = pair.second; rmap[pair.first] = pair.second;
} }
rmap.emplace("always", "0");
return rmap; return rmap;
} }
...@@ -258,4 +256,59 @@ PluginPreferencesUtils::getAllowDenyListPreferences(ChatHandlerList& list) ...@@ -258,4 +256,59 @@ PluginPreferencesUtils::getAllowDenyListPreferences(ChatHandlerList& list)
} }
} }
} }
void
PluginPreferencesUtils::addAlwaysHandlerPreference(const std::string& handlerName,
const std::string& rootPath)
{
std::string filePath = getPreferencesConfigFilePath(rootPath);
Json::Value root;
{
std::lock_guard<std::mutex> guard(fileutils::getFileLock(filePath));
std::ifstream file(filePath);
Json::CharReaderBuilder rbuilder;
Json::Value preference;
rbuilder["collectComments"] = false;
std::string errs;
std::set<std::string> keys;
std::vector<std::map<std::string, std::string>> preferences;
if (file) {
bool ok = Json::parseFromStream(rbuilder, file, &root, &errs);
if (ok && root.isArray()) {
for (const auto& child : root)
if (child.get("key", "None").asString() == handlerName + "Always")
return;
}
preference["key"] = handlerName + "Always";
preference["type"] = "Switch";
preference["defaultValue"] = "0";
preference["title"] = "Automatically turn " + handlerName + " on";
preference["summary"] = handlerName + " will take effect immediatly";
root.append(preference);
file.close();
}
}
std::lock_guard<std::mutex> guard(fileutils::getFileLock(filePath));
std::ofstream outFile(filePath);
if (outFile) {
outFile << root.toStyledString();
outFile.close();
}
}
bool
PluginPreferencesUtils::getAlwaysPreference(const std::string& rootPath, std::string& handlerName)
{
auto preferences = getPreferences(rootPath);
auto preferencesValues = getPreferencesValuesMap(rootPath);
for (const auto& preference : preferences) {
auto key = preference.at("key");
if (preference.at("type") == "Switch" && key == handlerName + "Always"
&& preferencesValues.find(key)->second == "1")
return true;
}
return false;
}
} // namespace jami } // namespace jami
...@@ -57,6 +57,11 @@ public: ...@@ -57,6 +57,11 @@ public:
static void getAllowDenyListPreferences(ChatHandlerList& list); static void getAllowDenyListPreferences(ChatHandlerList& list);
static void addAlwaysHandlerPreference(const std::string& handlerName,
const std::string& rootPath);
static bool getAlwaysPreference(const std::string& rootPath, std::string& handlerName);
private: private:
PluginPreferencesUtils() {} PluginPreferencesUtils() {}
~PluginPreferencesUtils() {} ~PluginPreferencesUtils() {}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment