From 0b7a97873741627288add16e15212866ebde4a15 Mon Sep 17 00:00:00 2001 From: agsantos Date: Mon, 29 Jun 2020 17:50:22 -0400 Subject: [PATCH] plugin: exposing plugins to linux ui Change-Id: I0919a3a78f4066122773a2ee9ab85d8e406e7e8f --- .../cx.ring.Ring.PluginManagerInterface.xml | 59 ++++++++++++++----- bin/dbus/dbuspluginmanagerinterface.cpp | 24 +++++++- bin/dbus/dbuspluginmanagerinterface.h | 6 +- bin/jni/plugin_manager_interface.i | 22 +++++++ configure.ac | 2 +- src/client/plugin_manager_interface.cpp | 20 ++++++- src/config/yamlparser.cpp | 14 ++++- src/config/yamlparser.h | 4 +- src/dring/plugin_manager_interface.h | 8 ++- src/manager.cpp | 15 +++++ src/manager.h | 8 +++ src/plugin/callservicesmanager.h | 21 ++++++- src/plugin/jamipluginmanager.cpp | 6 ++ src/plugin/jamipluginmanager.h | 4 +- src/preferences.cpp | 40 +++++++++++++ src/preferences.h | 42 +++++++++++++ 16 files changed, 268 insertions(+), 27 deletions(-) diff --git a/bin/dbus/cx.ring.Ring.PluginManagerInterface.xml b/bin/dbus/cx.ring.Ring.PluginManagerInterface.xml index c331f8be1..5dd8e9d7f 100644 --- a/bin/dbus/cx.ring.Ring.PluginManagerInterface.xml +++ b/bin/dbus/cx.ring.Ring.PluginManagerInterface.xml @@ -4,7 +4,7 @@ - + @@ -12,7 +12,7 @@ - + @@ -20,7 +20,7 @@ - + @@ -28,7 +28,8 @@ - + + @@ -37,7 +38,8 @@ - + + @@ -46,7 +48,7 @@ - + @@ -58,7 +60,8 @@ - + + @@ -67,7 +70,7 @@ - + @@ -75,19 +78,19 @@ - + - + - + @@ -97,7 +100,7 @@ - + @@ -105,13 +108,13 @@ - + - + @@ -119,11 +122,37 @@ - + + + + + + + + + Returns true if plugins are enabled, false otherwise + + + + + + + + + + + + + + + + + + diff --git a/bin/dbus/dbuspluginmanagerinterface.cpp b/bin/dbus/dbuspluginmanagerinterface.cpp index 2caa4ea3f..9bc0b098c 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 * @@ -97,8 +97,8 @@ DBusPluginManagerInterface::uninstallPlugin(const std::string& pluginRootPath) return DRing::uninstallPlugin(pluginRootPath); } -std::vector -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 +DBusPluginManagerInterface::getCallMediaHandlerStatus() +{ + return DRing::getCallMediaHandlerStatus(); +} diff --git a/bin/dbus/dbuspluginmanagerinterface.h b/bin/dbus/dbuspluginmanagerinterface.h index 38ee599fc..9fd353660 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 * @@ -67,4 +67,8 @@ class DRING_PUBLIC DBusPluginManagerInterface : std::vector listCallMediaHandlers(); void toggleCallMediaHandler(const std::string& id, const bool& toggle); std::map getCallMediaHandlerDetails(const std::string& id); + + bool getPluginsEnabled(); + void setPluginsEnabled(const bool& state); + std::map getCallMediaHandlerStatus(); }; diff --git a/bin/jni/plugin_manager_interface.i b/bin/jni/plugin_manager_interface.i index c9501b870..330c5c8dd 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 + * + * 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 . + */ + %header %{ #include "dring/dring.h" @@ -20,4 +39,7 @@ int uninstallPlugin(const std::string& pluginRootPath); std::vector listCallMediaHandlers(); void toggleCallMediaHandler(const std::string& id, bool toggle); std::map getCallMediaHandlerDetails(const std::string& id); +bool getPluginsEnabled(); +void setPluginsEnabled(bool state); +std::map getCallMediaHandlerStatus(); } diff --git a/configure.ac b/configure.ac index 5324ef142..e22f96eb0 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 e9dc053fa..e61e7f7e7 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 * * 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 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 getCallMediaHandlerStatus() + { + return jami::Manager::instance().getJamiPluginManager().getCallServicesManager().getCallMediaHandlerStatus(); + } } diff --git a/src/config/yamlparser.cpp b/src/config/yamlparser.cpp index 4c78578e7..c2a6ebb91 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 + * Authors: Alexandre Savard + * Aline Gondim Santos * * 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 return result; } +std::set +parseVector(const YAML::Node &node) +{ + std::set result; + for (const auto &n : node) { + std::string t; + t = n.as(""); + result.emplace(t); + } + return result; +} }} // namespace jami::yaml_utils diff --git a/src/config/yamlparser.h b/src/config/yamlparser.h index 1cea64455..d91ec1643 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 + * Authors: Alexandre Savard + * Aline Gondim Santos * * 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> parseVectorMap(const YAML::Node &node, const std::initializer_list &keys); +std::set 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 07283c990..79cba8596 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 * * 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 listCallMediaHandlers(); DRING_PUBLIC void toggleCallMediaHandler(const std::string& id, bool toggle); DRING_PUBLIC std::map getCallMediaHandlerDetails(const std::string& id); + DRING_PUBLIC bool getPluginsEnabled(); + DRING_PUBLIC void setPluginsEnabled(bool state); + DRING_PUBLIC std::map getCallMediaHandlerStatus(); } - diff --git a/src/manager.cpp b/src/manager.cpp index 1c8e8b8b7..7f26a7b34 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 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 1332292eb..d755acd9f 100644 --- a/src/manager.h +++ b/src/manager.h @@ -8,6 +8,7 @@ * Author: Alexandre Savard * Author: Tristan Matthews * Author: Guillaume Roguez + * Author: Aline Gondim Santos * * 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 b26e8ba20..5d1cc18ff 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 * * 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; using CallMediaHandlerPtr = std::unique_ptr; using AVSubjectSPtr = std::weak_ptr>; +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 getCallMediaHandlerStatus() + { + return { {"name", mediaHandlerToggled_.name}, {"state", mediaHandlerToggled_.state}}; + } + private: /** @@ -213,6 +230,8 @@ private: * It is pushed to this list list */ std::list> callAVsubjects; + + MediaHandlerToggled mediaHandlerToggled_; }; } diff --git a/src/plugin/jamipluginmanager.cpp b/src/plugin/jamipluginmanager.cpp index e23844953..2b879a015 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 @@ -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 38c5847c2..8903b7f6b 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 * * 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 90c6b3e53..83d1d37e8 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -3,6 +3,7 @@ * * Author: Alexandre Savard * Author: Philippe Gorley + * Author: Aline Gondim Santos * * 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 d1b93035d..7188edd4f 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -3,6 +3,7 @@ * * Author: Alexandre Savard * Author: Philippe Gorley + * Author: Aline Gondim Santos * * 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 #include +#include #include 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 getLoadedPlugins() const { + std::vector 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 loadedPlugins_; + constexpr static const char* const CONFIG_LABEL = "plugins"; +}; +#endif // ENABLE_PLUGIN + } // namespace jami #endif