diff --git a/bin/dbus/cx.ring.Ring.PluginManagerInterface.xml b/bin/dbus/cx.ring.Ring.PluginManagerInterface.xml index c331f8be19bb1c8d2285e33ed437cd30f984bcef..5dd8e9d7fe0cd5bb3a955ea4892d5864b89e2527 100644 --- a/bin/dbus/cx.ring.Ring.PluginManagerInterface.xml +++ b/bin/dbus/cx.ring.Ring.PluginManagerInterface.xml @@ -4,7 +4,7 @@ <interface name="cx.ring.Ring.PluginManagerInterface"> <!-- METHODS !--> <method name="loadPlugin" tp:name-for-bindings="loadPlugin"> - <tp:added version="0.0.0"/> + <tp:added version="9.2.0"/> <arg type="s" name="path" direction="in"> </arg> <arg type="b" name="loaded" direction="out"> @@ -12,7 +12,7 @@ </method> <method name="unloadPlugin" tp:name-for-bindings="unloadPlugin"> - <tp:added version="0.0.0"/> + <tp:added version="9.2.0"/> <arg type="s" name="path" direction="in"> </arg> <arg type="b" name="unloaded" direction="out"> @@ -20,7 +20,7 @@ </method> <method name="togglePlugin" tp:name-for-bindings="togglePlugin"> - <tp:added version="0.0.0"/> + <tp:added version="9.2.0"/> <arg type="s" name="path" direction="in"> </arg> <arg type="b" name="toggle" direction="in"> @@ -28,7 +28,8 @@ </method> <method name="getPluginDetails" tp:name-for-bindings="getPluginDetails"> - <tp:added version="0.0.0"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="MapStringString"/> + <tp:added version="9.2.0"/> <arg type="s" name="path" direction="in"> </arg> <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="MapStringString"/> @@ -37,7 +38,8 @@ </method> <method name="getPluginPreferences" tp:name-for-bindings="getPluginPreferences"> - <tp:added version="0.0.0"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="VectorMapStringString"/> + <tp:added version="9.2.0"/> <arg type="s" name="path" direction="in"> </arg> <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="VectorMapStringString"/> @@ -46,7 +48,7 @@ </method> <method name="setPluginPreference" tp:name-for-bindings="setPluginPreference"> - <tp:added version="0.0.0"/> + <tp:added version="9.2.0"/> <arg type="s" name="path" direction="in"> </arg> <arg type="s" name="key" direction="in"> @@ -58,7 +60,8 @@ </method> <method name="getPluginPreferencesValues" tp:name-for-bindings="getPluginPreferencesValues"> - <tp:added version="0.0.0"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="MapStringString"/> + <tp:added version="9.2.0"/> <arg type="s" name="path" direction="in"> </arg> <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="MapStringString"/> @@ -67,7 +70,7 @@ </method> <method name="resetPluginPreferencesValues" tp:name-for-bindings="resetPluginPreferencesValues"> - <tp:added version="0.0.0"/> + <tp:added version="9.2.0"/> <arg type="s" name="path" direction="in"> </arg> <arg type="b" name="reset" direction="out"> @@ -75,19 +78,19 @@ </method> <method name="listAvailablePlugins" tp:name-for-bindings="listAvailablePlugins"> - <tp:added version="0.0.0"/> + <tp:added version="9.2.0"/> <arg type="as" name="availablePlugins" direction="out"> </arg> </method> <method name="listLoadedPlugins" tp:name-for-bindings="listLoadedPlugins"> - <tp:added version="0.0.0"/> + <tp:added version="9.2.0"/> <arg type="as" name="LoadedPlugins" direction="out"> </arg> </method> <method name="installPlugin" tp:name-for-bindings="installPlugin"> - <tp:added version="0.0.0"/> + <tp:added version="9.2.0"/> <arg type="s" name="jplPath" direction="in"> </arg> <arg type="b" name="force" direction="in"> @@ -97,7 +100,7 @@ </method> <method name="uninstallPlugin" tp:name-for-bindings="uninstallPlugin"> - <tp:added version="0.0.0"/> + <tp:added version="9.2.0"/> <arg type="s" name="pluginRootPath" direction="in"> </arg> <arg type="i" name="uninstaled" direction="out"> @@ -105,13 +108,13 @@ </method> <method name="listCallMediaHandlers" tp:name-for-bindings="listCallMediaHandlers"> - <tp:added version="0.0.0"/> + <tp:added version="9.2.0"/> <arg type="as" name="listCallMediaHandlers" direction="out"> </arg> </method> <method name="toggleCallMediaHandler" tp:name-for-bindings="toggleCallMediaHandler"> - <tp:added version="0.0.0"/> + <tp:added version="9.2.0"/> <arg type="s" name="id" direction="in"> </arg> <arg type="b" name="toggle" direction="in"> @@ -119,11 +122,37 @@ </method> <method name="getCallMediaHandlerDetails" tp:name-for-bindings="getCallMediaHandlerDetails"> - <tp:added version="0.0.0"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="MapStringString"/> + <tp:added version="9.2.0"/> <arg type="s" name="id" direction="in"> </arg> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="MapStringString"/> <arg type="a{ss}" name="CallMediaHandlerDetails" direction="out"> </arg> </method> + + <method name="getPluginsEnabled" tp:name-for-bindings="getPluginsEnabled"> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="Bool"/> + <tp:added version="9.3.0"/> + <arg type="b" name="state" direction="out"> + <tp:docstring>Returns true if plugins are enabled, false otherwise</tp:docstring> + </arg> + </method> + + <method name="setPluginsEnabled" tp:name-for-bindings="setPluginsEnabled"> + <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="Bool"/> + <tp:added version="9.3.0"/> + <arg type="b" name="state" direction="in"> + </arg> + </method> + + <method name="getCallMediaHandlerStatus" tp:name-for-bindings="getCallMediaHandlerStatus"> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="MapStringString"/> + <tp:added version="9.3.0"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="MapStringString"/> + <arg type="a{ss}" name="getCallMediaHandlerStatus" direction="out"> + </arg> + </method> + </interface> </node> diff --git a/bin/dbus/dbuspluginmanagerinterface.cpp b/bin/dbus/dbuspluginmanagerinterface.cpp index 2caa4ea3fe5e54b5b83a60b503143d1bd85eb758..9bc0b098cb91ab7b36c427fe2a0eac5a1d9a56c1 100644 --- a/bin/dbus/dbuspluginmanagerinterface.cpp +++ b/bin/dbus/dbuspluginmanagerinterface.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2020 Savoir-faire Linux Inc. + * Copyright (C) 2020 Savoir-faire Linux Inc. * * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> * @@ -97,8 +97,8 @@ DBusPluginManagerInterface::uninstallPlugin(const std::string& pluginRootPath) return DRing::uninstallPlugin(pluginRootPath); } -std::vector<std::string> -DBusPluginManagerInterface::listCallMediaHandlers( ) +auto +DBusPluginManagerInterface::listCallMediaHandlers() -> decltype(DRing::listCallMediaHandlers()) { return DRing::listCallMediaHandlers(); } @@ -114,3 +114,21 @@ DBusPluginManagerInterface::getCallMediaHandlerDetails(const std::string& id) { return DRing::getCallMediaHandlerDetails(id); } + +bool +DBusPluginManagerInterface::getPluginsEnabled() +{ + return DRing::getPluginsEnabled(); +} + +void +DBusPluginManagerInterface::setPluginsEnabled(const bool& state) +{ + DRing::setPluginsEnabled(state); +} + +std::map<std::string,std::string> +DBusPluginManagerInterface::getCallMediaHandlerStatus() +{ + return DRing::getCallMediaHandlerStatus(); +} diff --git a/bin/dbus/dbuspluginmanagerinterface.h b/bin/dbus/dbuspluginmanagerinterface.h index 38ee599fcf66ae9578e2fc8ec6fef128a620200e..9fd353660adf5e6ca5bf359b6ab48e26052fd8a6 100644 --- a/bin/dbus/dbuspluginmanagerinterface.h +++ b/bin/dbus/dbuspluginmanagerinterface.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2020 Savoir-faire Linux Inc. + * Copyright (C) 2020 Savoir-faire Linux Inc. * * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> * @@ -67,4 +67,8 @@ class DRING_PUBLIC DBusPluginManagerInterface : std::vector<std::string> listCallMediaHandlers(); void toggleCallMediaHandler(const std::string& id, const bool& toggle); std::map<std::string,std::string> getCallMediaHandlerDetails(const std::string& id); + + bool getPluginsEnabled(); + void setPluginsEnabled(const bool& state); + std::map<std::string,std::string> getCallMediaHandlerStatus(); }; diff --git a/bin/jni/plugin_manager_interface.i b/bin/jni/plugin_manager_interface.i index c9501b8708756864d5c6b318c1ddeff465e92bcd..330c5c8dd54765a328dc66ae42f57909c28d945c 100644 --- a/bin/jni/plugin_manager_interface.i +++ b/bin/jni/plugin_manager_interface.i @@ -1,3 +1,22 @@ +/* + * Copyright (C) 2020 Savoir-faire Linux Inc. + * + * Authors: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + %header %{ #include "dring/dring.h" @@ -20,4 +39,7 @@ int uninstallPlugin(const std::string& pluginRootPath); std::vector<std::string> listCallMediaHandlers(); void toggleCallMediaHandler(const std::string& id, bool toggle); std::map<std::string,std::string> getCallMediaHandlerDetails(const std::string& id); +bool getPluginsEnabled(); +void setPluginsEnabled(bool state); +std::map<std::string,std::string> getCallMediaHandlerStatus(); } diff --git a/configure.ac b/configure.ac index 5324ef142684ebddbcfaafe8bb454b8580a25b7e..e22f96eb05815eea4348a5893c2cd4e4f8d9a3d2 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ dnl Jami - configure.ac for automake 1.9 and autoconf 2.59 dnl Process this file with autoconf to produce a configure script. AC_PREREQ([2.65]) -AC_INIT([Jami Daemon],[9.2.0],[ring@gnu.org],[jami]) +AC_INIT([Jami Daemon],[9.3.0],[ring@gnu.org],[jami]) AC_COPYRIGHT([[Copyright (c) Savoir-faire Linux 2004-2019]]) AC_REVISION([$Revision$]) diff --git a/src/client/plugin_manager_interface.cpp b/src/client/plugin_manager_interface.cpp index e9dc053faf2729c266ae6c446e1be30abfd2e117..e61e7f7e7afe492e961114a145116b366531cf0c 100644 --- a/src/client/plugin_manager_interface.cpp +++ b/src/client/plugin_manager_interface.cpp @@ -1,5 +1,7 @@ /* - * Copyright (C) 2004-2020 Savoir-faire Linux Inc. + * Copyright (C) 2020 Savoir-faire Linux Inc. + * + * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -92,4 +94,20 @@ namespace DRing std::map<std::string,std::string> getCallMediaHandlerDetails(const std::string& id) { return jami::Manager::instance().getJamiPluginManager().getCallServicesManager().getCallMediaHandlerDetails(id); } + + bool getPluginsEnabled() + { + return jami::Manager::instance().pluginPreferences.getPluginsEnabled(); + } + + void setPluginsEnabled(bool state) + { + jami::Manager::instance().pluginPreferences.setPluginsEnabled(state); + jami::Manager::instance().saveConfig(); + } + + std::map<std::string,std::string> getCallMediaHandlerStatus() + { + return jami::Manager::instance().getJamiPluginManager().getCallServicesManager().getCallMediaHandlerStatus(); + } } diff --git a/src/config/yamlparser.cpp b/src/config/yamlparser.cpp index 4c78578e7a0c2bc0beed5017b5a980da6bd6a438..c2a6ebb91e2c510397e5fba2ff0574c6ac80431d 100644 --- a/src/config/yamlparser.cpp +++ b/src/config/yamlparser.cpp @@ -1,7 +1,8 @@ /* * Copyright (C) 2004-2020 Savoir-faire Linux Inc. * - * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> + * Authors: Alexandre Savard <alexandre.savard@savoirfairelinux.com> + * Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -47,4 +48,15 @@ parseVectorMap(const YAML::Node &node, const std::initializer_list<std::string> return result; } +std::set<std::string> +parseVector(const YAML::Node &node) +{ + std::set<std::string> result; + for (const auto &n : node) { + std::string t; + t = n.as<std::string>(""); + result.emplace(t); + } + return result; +} }} // namespace jami::yaml_utils diff --git a/src/config/yamlparser.h b/src/config/yamlparser.h index 1cea644554f5ab9f8f299d40499a060a0dbebeb9..d91ec1643ed66e2031b782dbacd480f443b1c62b 100644 --- a/src/config/yamlparser.h +++ b/src/config/yamlparser.h @@ -1,7 +1,8 @@ /* * Copyright (C) 2004-2020 Savoir-faire Linux Inc. * - * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> + * Authors: Alexandre Savard <alexandre.savard@savoirfairelinux.com> + * Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -50,5 +51,6 @@ void parsePath(const YAML::Node &node, const char *key, std::string& path, const std::vector<std::map<std::string, std::string>> parseVectorMap(const YAML::Node &node, const std::initializer_list<std::string> &keys); +std::set<std::string> parseVector(const YAML::Node &node); }} // namespace jami::yaml_utils diff --git a/src/dring/plugin_manager_interface.h b/src/dring/plugin_manager_interface.h index 07283c9905a5cc0a4edaff5493f33dbd1affc5bb..79cba85966e817051fa5a22147922f0bfc321830 100644 --- a/src/dring/plugin_manager_interface.h +++ b/src/dring/plugin_manager_interface.h @@ -1,5 +1,7 @@ /* - * Copyright (C) 2004-2020 Savoir-faire Linux Inc. + * Copyright (C) 2020 Savoir-faire Linux Inc. + * + * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -47,5 +49,7 @@ namespace DRing DRING_PUBLIC std::vector<std::string> listCallMediaHandlers(); DRING_PUBLIC void toggleCallMediaHandler(const std::string& id, bool toggle); DRING_PUBLIC std::map<std::string,std::string> getCallMediaHandlerDetails(const std::string& id); + DRING_PUBLIC bool getPluginsEnabled(); + DRING_PUBLIC void setPluginsEnabled(bool state); + DRING_PUBLIC std::map<std::string,std::string> getCallMediaHandlerStatus(); } - diff --git a/src/manager.cpp b/src/manager.cpp index 1c8e8b8b7efb6c2ee0d949c8e789d57229229b7b..7f26a7b342b681cfdca2dbc346c93da969a40097 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -698,6 +698,9 @@ Manager::Manager() , shortcutPreferences() #ifdef ENABLE_VIDEO , videoPreferences() +#endif +#ifdef ENABLE_PLUGIN + , pluginPreferences() #endif , callFactory() , accountFactory() @@ -1701,6 +1704,9 @@ Manager::saveConfig() audioPreference.serialize(out); #ifdef ENABLE_VIDEO videoPreferences.serialize(out); +#endif +#ifdef ENABLE_PLUGIN + pluginPreferences.serialize(out); #endif shortcutPreferences.serialize(out); @@ -2755,6 +2761,15 @@ Manager::loadAccountMap(const YAML::Node& node) shortcutPreferences.unserialize(node); #ifdef ENABLE_VIDEO videoPreferences.unserialize(node); +#endif +#ifdef ENABLE_PLUGIN + pluginPreferences.unserialize(node); + + std::vector<std::string> loadedPlugins = pluginPreferences.getLoadedPlugins(); + for (const std::string& plugin : loadedPlugins) + { + jami::Manager::instance().getJamiPluginManager().loadPlugin(plugin); + } #endif } catch (const YAML::Exception &e) { JAMI_ERR("%s: Preferences node unserialize error: ", e.what()); diff --git a/src/manager.h b/src/manager.h index 1332292eb7d81aa7935bd87dda5f4825f57bb1aa..d755acd9f7f5559332d3ecc31e025d892f166991 100644 --- a/src/manager.h +++ b/src/manager.h @@ -8,6 +8,7 @@ * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> * Author: Tristan Matthews <tristan.matthews@savoirfairelinux.com> * Author: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com> + * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -99,6 +100,13 @@ class DRING_TESTABLE Manager { */ ShortcutPreferences shortcutPreferences; +#ifdef ENABLE_PLUGIN + /** + * Plugin preferences + */ + PluginPreferences pluginPreferences; +#endif + #ifdef ENABLE_VIDEO /** * Video preferences diff --git a/src/plugin/callservicesmanager.h b/src/plugin/callservicesmanager.h index b26e8ba2032cc56617c4770170634151053c6821..5d1cc18ff75191944fd315d31ef09994ea067a1b 100644 --- a/src/plugin/callservicesmanager.h +++ b/src/plugin/callservicesmanager.h @@ -1,5 +1,7 @@ /* - * Copyright (C) 2004-2019 Savoir-faire Linux Inc. + * Copyright (C) 2020 Savoir-faire Linux Inc. + * + * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,6 +33,12 @@ using MediaHandlerPtr = std::unique_ptr<MediaHandler>; using CallMediaHandlerPtr = std::unique_ptr<CallMediaHandler>; using AVSubjectSPtr = std::weak_ptr<Observable<AVFrame*>>; +struct MediaHandlerToggled +{ + std::string name = ""; + std::string state = "false"; +}; + class CallServicesManager{ public: @@ -132,9 +140,13 @@ public: if(pair.second && getCallHandlerId(pair.second) == id) { pair.first = toggle; if(pair.first) { + mediaHandlerToggled_.name = id; + mediaHandlerToggled_.state = "true"; listAvailableSubjects(pair.second); } else { pair.second->detach(); + mediaHandlerToggled_.name = ""; + mediaHandlerToggled_.state = "false"; } } } @@ -155,6 +167,11 @@ public: return {}; } + std::map<std::string,std::string> getCallMediaHandlerStatus() + { + return { {"name", mediaHandlerToggled_.name}, {"state", mediaHandlerToggled_.state}}; + } + private: /** @@ -213,6 +230,8 @@ private: * It is pushed to this list list */ std::list<std::pair<const StreamData, AVSubjectSPtr>> callAVsubjects; + + MediaHandlerToggled mediaHandlerToggled_; }; } diff --git a/src/plugin/jamipluginmanager.cpp b/src/plugin/jamipluginmanager.cpp index e23844953447594a38e037fd9ddfa4e0331cd11d..2b879a0158be9820c0e8bf15827f7003a659b235 100644 --- a/src/plugin/jamipluginmanager.cpp +++ b/src/plugin/jamipluginmanager.cpp @@ -26,6 +26,7 @@ //Manager #include "manager.h" +#include "preferences.h" extern "C" { #include <archive.h> @@ -269,6 +270,8 @@ bool JamiPluginManager::loadPlugin(const std::string &rootPath) bool status = pm_.load(getPluginDetails(rootPath).at("soPath")); JAMI_INFO() << "PLUGIN: load status - " << status; + jami::Manager::instance().pluginPreferences.saveStateLoadedPlugins(rootPath, status); + jami::Manager::instance().saveConfig(); return status; } catch(const std::exception& e) @@ -285,6 +288,9 @@ bool JamiPluginManager::unloadPlugin(const std::string &rootPath) bool status = pm_.unload(getPluginDetails(rootPath).at("soPath")); JAMI_INFO() << "PLUGIN: unload status - " << status; + jami::Manager::instance().pluginPreferences.saveStateLoadedPlugins(rootPath, false); + jami::Manager::instance().saveConfig(); + return status; } catch(const std::exception& e) { diff --git a/src/plugin/jamipluginmanager.h b/src/plugin/jamipluginmanager.h index 38c5847c20ba3cb348dba7331652a10be7b2e20b..8903b7f6bb977ed440114193c68d1a7b49c32568 100644 --- a/src/plugin/jamipluginmanager.h +++ b/src/plugin/jamipluginmanager.h @@ -1,5 +1,7 @@ /* - * Copyright (C) 2004-2020 Savoir-faire Linux Inc. + * Copyright (C) 2020 Savoir-faire Linux Inc. + * + * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/preferences.cpp b/src/preferences.cpp index 90c6b3e5331a54910de8874d92ceb947d3d37f42..83d1d37e8c20c27b74497de9fa8be76621b29eb7 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -3,6 +3,7 @@ * * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> * Author: Philippe Gorley <philippe.gorley@savoirfairelinux.com> + * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -146,6 +147,13 @@ static constexpr const char* RECORD_PREVIEW_KEY {"recordPreview"}; static constexpr const char* RECORD_QUALITY_KEY {"recordQuality"}; #endif +#ifdef ENABLE_PLUGIN +// plugin preferences +constexpr const char * const PluginPreferences::CONFIG_LABEL; +static constexpr const char* JAMI_PLUGIN_KEY {"pluginsEnabled"}; +static constexpr const char* JAMI_PLUGINS_LOADED_KEY {"loadedPlugins"}; +#endif + static constexpr int PULSE_LENGTH_DEFAULT {250}; /** Default DTMF length */ #ifndef _MSC_VER static constexpr const char* ALSA_DFT_CARD {"0"}; /** Default sound card index */ @@ -641,4 +649,36 @@ void VideoPreferences::unserialize(const YAML::Node &in) } #endif // ENABLE_VIDEO +#ifdef ENABLE_PLUGIN +PluginPreferences::PluginPreferences() + : pluginsEnabled_(false) +{} + +void PluginPreferences::serialize(YAML::Emitter &out) const +{ + out << YAML::Key << CONFIG_LABEL << YAML::Value << YAML::BeginMap; + out << YAML::Key << JAMI_PLUGIN_KEY << YAML::Value << pluginsEnabled_; + out << YAML::Key << JAMI_PLUGINS_LOADED_KEY << YAML::Value << loadedPlugins_; + out << YAML::EndMap; +} + +void PluginPreferences::unserialize(const YAML::Node &in) +{ + // values may or may not be present + const auto &node = in[CONFIG_LABEL]; + try { + parseValue(node, JAMI_PLUGIN_KEY, pluginsEnabled_); + } catch (...) { + pluginsEnabled_ = false; + } + + const auto &loadedPluginsNode = node[JAMI_PLUGINS_LOADED_KEY]; + try { + loadedPlugins_ = yaml_utils::parseVector(loadedPluginsNode); + } catch (...) { + // loadedPlugins_ = {}; + } +} +#endif // ENABLE_PLUGIN + } // namespace jami diff --git a/src/preferences.h b/src/preferences.h index d1b93035d18f9ab6f202adc7d1a2c4de64ca263e..7188edd4fbcc7f2f2370a72588173be89d41df97 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -3,6 +3,7 @@ * * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> * Author: Philippe Gorley <philippe.gorley@savoirfairelinux.com> + * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,6 +27,7 @@ #include "client/ring_signal.h" #include <string> #include <map> +#include <set> #include <vector> namespace YAML { @@ -522,6 +524,46 @@ class VideoPreferences : public Serializable { }; #endif // ENABLE_VIDEO +#ifdef ENABLE_PLUGIN +class PluginPreferences : public Serializable { + public: + PluginPreferences(); + + void serialize(YAML::Emitter &out) const override; + void unserialize(const YAML::Node &in) override; + + bool getPluginsEnabled() const { + return pluginsEnabled_; + } + + void setPluginsEnabled(bool pluginsEnabled) { + pluginsEnabled_ = pluginsEnabled; + } + + std::vector<std::string> getLoadedPlugins() const { + std::vector<std::string> v(loadedPlugins_.begin(), loadedPlugins_.end()); + return v; + } + + void saveStateLoadedPlugins(std::string plugin, bool loaded) { + if (loaded) { + if (loadedPlugins_.find(plugin) != loadedPlugins_.end()) return; + loadedPlugins_.emplace(plugin); + } + else { + auto it = loadedPlugins_.find(plugin); + if (it != loadedPlugins_.end()) + loadedPlugins_.erase(it); + } + } + + private: + bool pluginsEnabled_; + std::set<std::string> loadedPlugins_; + constexpr static const char* const CONFIG_LABEL = "plugins"; +}; +#endif // ENABLE_PLUGIN + } // namespace jami #endif