Commit f1963250 authored by Aline Gondim Santos's avatar Aline Gondim Santos

plugin: exposing plugins to linux ui

Change-Id: I5de694b3fe7ebb177c3667cb9feb4aa4950fea7b
parent 3ef91eeb
......@@ -238,6 +238,12 @@ IF(NOT (${ENABLE_VIDEO} MATCHES false))
add_definitions( -DENABLE_VIDEO=true )
ENDIF(NOT (${ENABLE_VIDEO} MATCHES false))
IF(NOT (${ENABLE_PLUGIN} MATCHES false))
MESSAGE(STATUS "PLUGIN enabled")
SET(ENABLE_PLUGIN 1 CACHE BOOLEAN "Enable plugin")
add_definitions( -DENABLE_PLUGIN=true )
ENDIF(NOT (${ENABLE_PLUGIN} MATCHES false))
# ADD_DEFINITIONS(-DQT_DISABLE_DEPRECATED_BEFORE=1)
if (CHK_FREEABLE_BEFORE_ERASE_ACCOUNT)
......@@ -297,6 +303,7 @@ SET( libringclient_LIB_SRCS
src/dbus/instancemanager.cpp
src/dbus/videomanager.cpp
src/dbus/presencemanager.cpp
src/dbus/pluginmanager.cpp
#Default interface implementations
src/globalinstances.cpp
......@@ -305,6 +312,7 @@ SET( libringclient_LIB_SRCS
#Other
src/avmodel.cpp
src/pluginmodel.cpp
src/namedirectory.cpp
src/smartinfohub.cpp
)
......@@ -330,6 +338,7 @@ SET(libringclient_api_LIB_HDRS
src/api/account.h
src/api/lrc.h
src/api/avmodel.h
src/api/pluginmodel.h
src/api/newaccountmodel.h
src/api/peerdiscoverymodel.h
src/api/newcallmodel.h
......@@ -442,6 +451,21 @@ ELSE()
video_dbus_interface
)
# plugin manager interface
SET ( plugin_xml ${dbus_xml_introspecs_path}/cx.ring.Ring.PluginManagerInterface.xml )
SET_SOURCE_FILES_PROPERTIES(
${plugin_xml}
PROPERTIES
CLASSNAME PluginManagerInterface
INCLUDE ${dbus_metatype_path}
)
QT5_ADD_DBUS_INTERFACE(
libringclient_LIB_SRCS
${plugin_xml}
plugin_dbus_interface
)
# instance interface
SET ( instance_xml ${dbus_xml_introspecs_path}/cx.ring.Ring.Instance.xml )
......@@ -477,6 +501,7 @@ IF(${ENABLE_LIBWRAP} MATCHES true AND ${ENABLE_TEST} MATCHES false)
src/qtwrapper/instancemanager_wrap.h
src/qtwrapper/presencemanager_wrap.h
src/qtwrapper/videomanager_wrap.h
src/qtwrapper/pluginmanager_wrap.h
)
ENDIF()
......@@ -593,6 +618,11 @@ INSTALL( FILES ${libringclient_video_LIB_HDRS}
COMPONENT Devel
)
INSTALL( FILES ${libringclient_plugin_LIB_HDRS}
DESTINATION ${INCLUDE_INSTALL_DIR}/libringclient/plugin
COMPONENT Devel
)
INSTALL( FILES ${libringclient_WEB_chatview}
DESTINATION ${INCLUDE_INSTALL_DIR}/libringclient/web-chatview
COMPONENT Devel
......
/****************************************************************************
* Copyright (C) 2017-2020 Savoir-faire Linux Inc. *
* Copyright (C) 2017-2020 Savoir-faire Linux Inc. *
* Author: Nicolas Jäger <nicolas.jager@savoirfairelinux.com> *
* Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> *
* Author : Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
......@@ -36,6 +37,7 @@ class BehaviorController;
class NewAccountModel;
class DataTransferModel;
class AVModel;
class PluginModel;
class LIB_EXPORT Lrc {
public:
......@@ -70,6 +72,12 @@ public:
*/
AVModel& getAVModel() const;
/**
* get a reference on the PLUGIN controller.
* @return a PluginModel&.
*/
PluginModel& getPluginModel() const;
/**
* Inform the daemon that the connectivity changed
*/
......
/****************************************************************************
* Copyright (C) 2018-2020 Savoir-faire Linux Inc. *
* Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library 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 *
* Lesser 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/>. *
***************************************************************************/
#pragma once
// std
#include <memory>
#include <string>
#include <vector>
// Qt
#include <qobject.h>
// LRC
#include "typedefs.h"
namespace lrc
{
namespace api
{
namespace plugin
{
/**
* This class describes current plugin Details
*/
struct PluginDetails
{
QString name = "";
QString path = "";
QString iconPath = "";
bool loaded = false;
};
struct MediaHandlerDetails
{
QString id = "";
QString name = "";
QString iconPath = "";
};
}
class LIB_EXPORT PluginModel : public QObject {
Q_OBJECT
public:
PluginModel();
~PluginModel();
/**
* Enable/disable plugins
* @param if plugin enabled
*/
void setPluginsEnabled(bool enable);
/**
* Get if plugins are enabled
* @return plugins enabled
*/
bool getPluginsEnabled() const;
/**
* Get list of installed plugins
* @return plugins installed
*/
VectorString listAvailablePlugins() const;
/**
* Get list of loaded plugins
* @return plugins loaded
*/
VectorString listLoadedPlugins() const;
/**
* Get details of installed plugin
* @return plugin Details
*/
plugin::PluginDetails getPluginDetails(const QString& path);
/**
* Install plugin
* @return plugin installed
*/
bool installPlugin(const QString& jplPath, bool force);
/**
* Uninstall plugin
* @return plugin uninstalled
*/
bool uninstallPlugin(const QString& rootPath);
/**
* Load plugin
* @return plugin loaded
*/
bool loadPlugin(const QString& path);
/**
* Unload plugin
* @return plugin unloaded
*/
bool unloadPlugin(const QString& path);
/**
* List available Media Handlers
* @return List of available Media Handlers
*/
VectorString listCallMediaHandlers() const;
/**
* Toggle media handler
*/
void toggleCallMediaHandler(const QString& id);
/**
* Verify if there is an active plugin media handler
* @return Map with name and status
*/
MapStringString getCallMediaHandlerStatus();
/**
* Get details of available media handler
* @return Media Handler Details
*/
plugin::MediaHandlerDetails getCallMediaHandlerDetails(const QString& id);
};
} // namespace api
} // namespace lrc
/****************************************************************************
* Copyright (C) 2013-2020 Savoir-faire Linux Inc. *
* Author : Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library 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 *
* Lesser 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/>. *
***************************************************************************/
#include "pluginmanager.h"
#include "../globalinstances.h"
#include "../interfaces/dbuserrorhandleri.h"
PluginManagerInterface& PluginManager::instance()
{
#ifdef ENABLE_LIBWRAP
static auto interface = new PluginManagerInterface();
#else
if (!dbus_metaTypeInit) registerCommTypes();
static auto interface = new PluginManagerInterface("cx.ring.Ring",
"/cx/ring/Ring/PluginManagerInterface",
QDBusConnection::sessionBus());
if (!interface->connection().isConnected()) {
GlobalInstances::dBusErrorHandler().connectionError(
"Error : dring not connected. Service " + interface->service() + " not connected. From presence interface."
);
}
if (!interface->isValid()) {
GlobalInstances::dBusErrorHandler().invalidInterfaceError(
"Error : dring is not available, make sure it is running"
);
}
#endif
return *interface;
}
/****************************************************************************
* Copyright (C) 2012-2020 Savoir-faire Linux Inc. *
* Author : Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library 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 *
* Lesser 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/>. *
***************************************************************************/
#pragma once
#ifdef ENABLE_TEST
// #include "../../test/mocks/pluginmanager_mock.h"
#else
#ifdef ENABLE_LIBWRAP
#include "pluginmanager_wrap.h"
#else
#include "plugin_dbus_interface.h"
#include <QDBusPendingReply>
#endif
#endif
#include <typedefs.h>
namespace PluginManager {
LIB_EXPORT PluginManagerInterface& instance();
}
......@@ -2,6 +2,7 @@
* Copyright (C) 2017-2020 Savoir-faire Linux Inc. *
* Author : Nicolas Jäger <nicolas.jager@savoirfairelinux.com> *
* Author : Sébastien Blin <sebastien.blin@savoirfairelinux.com> *
* Author : Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
......@@ -30,6 +31,7 @@
// Models and database
#include "api/avmodel.h"
#include "api/pluginmodel.h"
#include "api/behaviorcontroller.h"
#include "api/datatransfermodel.h"
#include "api/newaccountmodel.h"
......@@ -62,6 +64,7 @@ public:
std::unique_ptr<NewAccountModel> accountModel;
std::unique_ptr<DataTransferModel> dataTransferModel;
std::unique_ptr<AVModel> AVModel_;
std::unique_ptr<PluginModel> PluginModel_;
};
......@@ -112,6 +115,12 @@ Lrc::getAVModel() const
return *lrcPimpl_->AVModel_;
}
PluginModel&
Lrc::getPluginModel() const
{
return *lrcPimpl_->PluginModel_;
}
void
Lrc::connectivityChanged() const
{
......@@ -215,6 +224,7 @@ LrcPimpl::LrcPimpl(Lrc& linked, MigrationCb& willMigrateCb, MigrationCb& didMigr
, accountModel(std::make_unique<NewAccountModel>(linked, *callbackHandler, *behaviorController, willMigrateCb, didMigrateCb))
, dataTransferModel {std::make_unique<DataTransferModel>()}
, AVModel_ {std::make_unique<AVModel>(*callbackHandler)}
, PluginModel_{std::make_unique<PluginModel>()}
{
}
......
......@@ -29,6 +29,7 @@
#include "api/conversationmodel.h"
#include "api/contact.h"
#include "api/contactmodel.h"
#include "api/pluginmodel.h"
#include "api/lrc.h"
#include "api/newaccountmodel.h"
#include "authority/storagehelper.h"
......@@ -716,6 +717,11 @@ NewCallModelPimpl::slotCallStateChanged(const QString& callId, const QString& st
if (call->status == call::Status::ENDED) {
emit linked.callEnded(callId);
// NOTE: this line stops all mediaHandlers after the end of any call.
// The mediaHandler will be linked with the callID soon and each mediaHandler
// will be activated/deactivated with respect to the callID.
// This modification will allow to remove the next line.
PluginModel().toggleCallMediaHandler("");
} else if (call->status == call::Status::IN_PROGRESS) {
if (previousStatus == call::Status::INCOMING_RINGING
|| previousStatus == call::Status::OUTGOING_RINGING) {
......
/****************************************************************************
* Copyright (C) 2018-2020 Savoir-faire Linux Inc. *
* Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library 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 *
* Lesser 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/>. *
***************************************************************************/
#include "api/pluginmodel.h"
// Std
#include <algorithm> // std::sort
#include <chrono>
#include <csignal>
#include <iomanip> // for std::put_time
#include <fstream>
#include <mutex>
#include <thread>
#include <string>
#include <sstream>
// Qt
#include <QtCore/QStandardPaths>
#include <QtCore/QDir>
#include <QUrl>
// Ring daemon
// LRC
#include "dbus/pluginmanager.h"
namespace lrc
{
using namespace api;
PluginModel::PluginModel()
: QObject()
{}
PluginModel::~PluginModel() {}
void
PluginModel::setPluginsEnabled(bool enable)
{
PluginManager::instance().setPluginsEnabled(enable);
}
bool
PluginModel::getPluginsEnabled() const
{
return PluginManager::instance().getPluginsEnabled();
}
VectorString
PluginModel::listAvailablePlugins() const
{
return VectorString::fromList(PluginManager::instance().listAvailablePlugins());
}
VectorString
PluginModel::listLoadedPlugins() const
{
return VectorString::fromList(PluginManager::instance().listLoadedPlugins());
}
plugin::PluginDetails
PluginModel::getPluginDetails(const QString& path)
{
if (path.isEmpty()) {
return plugin::PluginDetails();
}
MapStringString details = PluginManager::instance().getPluginDetails(path);
plugin::PluginDetails result;
if (!details.empty())
{
result.name = details["name"];
result.path = path;
result.iconPath = details["iconPath"];
}
VectorString loadedPlugins = listLoadedPlugins();
if (std::find(loadedPlugins.begin(), loadedPlugins.end(), result.path) != loadedPlugins.end()) {
result.loaded = true;
}
return result;
}
bool
PluginModel::installPlugin(const QString& jplPath, bool force)
{
if (getPluginsEnabled())
{
return PluginManager::instance().installPlugin(jplPath, force);
}
return false;
}
bool
PluginModel::uninstallPlugin(const QString& rootPath)
{
return PluginManager::instance().uninstallPlugin(rootPath);
}
bool
PluginModel::loadPlugin(const QString& path)
{
bool status = PluginManager::instance().loadPlugin(path);
return status;
}
bool
PluginModel::unloadPlugin(const QString& path)
{
return PluginManager::instance().unloadPlugin(path);
}
VectorString
PluginModel::listCallMediaHandlers() const
{
return VectorString::fromList(PluginManager::instance().listCallMediaHandlers());
}
void
PluginModel::toggleCallMediaHandler(const QString& id)
{
MapStringString toggleInfo = PluginManager::instance().getCallMediaHandlerStatus();
if (toggleInfo["state"] == "true"){
PluginManager::instance().toggleCallMediaHandler(toggleInfo["name"], false);
}
if (!id.isEmpty() && id != toggleInfo["name"]) {
PluginManager::instance().toggleCallMediaHandler(id, true);
}
}
MapStringString
PluginModel::getCallMediaHandlerStatus()
{
return PluginManager::instance().getCallMediaHandlerStatus();
}
plugin::MediaHandlerDetails
PluginModel::getCallMediaHandlerDetails(const QString& id)
{
if (id.isEmpty()) {
return plugin::MediaHandlerDetails();
}
MapStringString mediaHandlerDetails = PluginManager::instance().getCallMediaHandlerDetails(id);
plugin::MediaHandlerDetails result;
if (!mediaHandlerDetails.empty())
{
result.id = id;
result.iconPath = mediaHandlerDetails["iconPath"];
result.name = mediaHandlerDetails["name"];
}
return result;
}
} // namespace lrc
#include "api/moc_pluginmodel.cpp"
#include "pluginmodel.moc"
/******************************************************************************
* Copyright (C) 2014-2020 Savoir-faire Linux Inc. *
* Author : Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library 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 *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the Lesser GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*****************************************************************************/
#pragma once
#include <QtCore/QObject>
#include <QtCore/QByteArray>
#include <QtCore/QList>
#include <QtCore/QMap>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QVariant>
#include <QtCore/QTimer>
#include "typedefs.h"
#include <plugin_manager_interface.h>
#include "conversions_wrap.hpp"
/*
* Proxy class for interface org.ring.Ring.PluginManager
*/
class PluginManagerInterface: public QObject
{
Q_OBJECT
public:
PluginManagerInterface() {}
~PluginManagerInterface() {}
public Q_SLOTS: // METHODS
bool loadPlugin(const QString& path)
{
return DRing::loadPlugin(path.toStdString());
}
bool unloadPlugin(const QString& path)
{
return DRing::unloadPlugin(path.toStdString());
}
MapStringString getPluginDetails(const QString& path)
{
MapStringString temp =
convertMap(DRing::getPluginDetails(path.toStdString()));
return temp;
}
QStringList listAvailablePlugins()
{
return convertStringList(DRing::listAvailablePlugins());
}
QStringList listLoadedPlugins()
{
return convertStringList(DRing::listLoadedPlugins());
}
int installPlugin(const QString& jplPath, bool force)
{
return DRing::installPlugin(jplPath.toStdString(), force);
}
int uninstallPlugin(const QString& pluginRootPath)
{
return DRing::uninstallPlugin(pluginRootPath.toStdString());
}
QStringList listCallMediaHandlers()
{
return convertStringList(DRing::listCallMediaHandlers());
}
void toggleCallMediaHandler(const QString& id, bool toggle)
{
DRing::toggleCallMediaHandler(id.toStdString(), toggle);
}
MapStringString getCallMediaHandlerStatus()
{
return convertMap(DRing::getCallMediaHandlerStatus());
}
MapStringString getCallMediaHandlerDetails(const QString& id)
{
return convertMap(DRing::getCallMediaHandlerDetails(id.toStdString()));
}
void setPluginsEnabled(bool enable)
{
DRing::setPluginsEnabled(enable);
}
bool getPluginsEnabled()
{
return DRing::getPluginsEnabled();
}
};
namespace org {
namespace ring {
namespace Ring {
typedef ::PluginManagerInterface PluginManager;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment