Commit e2b4da05 authored by Aline Gondim Santos's avatar Aline Gondim Santos Committed by Aline Gondim Santos

plugin: code cleanup

Change-Id: I5573606fae39567caf9026e9b1253b33588ab292
parent 60194fac
......@@ -43,25 +43,27 @@ DBusPluginManagerInterface::togglePlugin(const std::string& path, const bool& to
DRing::togglePlugin(path, toggle);
}
std::map<std::string,std::string>
std::map<std::string, std::string>
DBusPluginManagerInterface::getPluginDetails(const std::string& path)
{
return DRing::getPluginDetails(path);
}
std::vector<std::map<std::string,std::string>>
std::vector<std::map<std::string, std::string>>
DBusPluginManagerInterface::getPluginPreferences(const std::string& path)
{
return DRing::getPluginPreferences(path);
}
bool
DBusPluginManagerInterface::setPluginPreference(const std::string& path, const std::string& key, const std::string& value)
DBusPluginManagerInterface::setPluginPreference(const std::string& path,
const std::string& key,
const std::string& value)
{
return DRing::setPluginPreference(path, key, value);
}
std::map<std::string,std::string>
std::map<std::string, std::string>
DBusPluginManagerInterface::getPluginPreferencesValues(const std::string& path)
{
return DRing::getPluginPreferencesValues(path);
......@@ -109,7 +111,7 @@ DBusPluginManagerInterface::toggleCallMediaHandler(const std::string& id, const
DRing::toggleCallMediaHandler(id, toggle);
}
std::map<std::string,std::string>
std::map<std::string, std::string>
DBusPluginManagerInterface::getCallMediaHandlerDetails(const std::string& id)
{
return DRing::getCallMediaHandlerDetails(id);
......@@ -127,7 +129,7 @@ DBusPluginManagerInterface::setPluginsEnabled(const bool& state)
DRing::setPluginsEnabled(state);
}
std::map<std::string,std::string>
std::map<std::string, std::string>
DBusPluginManagerInterface::getCallMediaHandlerStatus()
{
return DRing::getCallMediaHandlerStatus();
......
......@@ -27,7 +27,7 @@
#include "dring/def.h"
#include "dbus_cpp.h"
#if __GNUC__ >= 5 || (__GNUC__ >=4 && __GNUC_MINOR__ >= 6)
#if __GNUC__ >= 5 || (__GNUC__ >= 4 && __GNUC_MINOR__ >= 6)
/* This warning option only exists for gcc 4.6.0 and greater. */
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#endif
......@@ -38,37 +38,39 @@
#pragma GCC diagnostic warning "-Wignored-qualifiers"
#pragma GCC diagnostic warning "-Wunused-parameter"
#if __GNUC__ >= 5 || (__GNUC__ >=4 && __GNUC_MINOR__ >= 6)
#if __GNUC__ >= 5 || (__GNUC__ >= 4 && __GNUC_MINOR__ >= 6)
/* This warning option only exists for gcc 4.6.0 and greater. */
#pragma GCC diagnostic warning "-Wunused-but-set-variable"
#endif
class DRING_PUBLIC DBusPluginManagerInterface :
public cx::ring::Ring::PluginManagerInterface_adaptor,
public DBus::IntrospectableAdaptor,
public DBus::ObjectAdaptor
class DRING_PUBLIC DBusPluginManagerInterface
: public cx::ring::Ring::PluginManagerInterface_adaptor,
public DBus::IntrospectableAdaptor,
public DBus::ObjectAdaptor
{
public:
DBusPluginManagerInterface(DBus::Connection& connection);
public:
DBusPluginManagerInterface(DBus::Connection& connection);
// Methods
bool loadPlugin(const std::string& path);
bool unloadPlugin(const std::string& path);
void togglePlugin(const std::string& path, const bool& toggle);
std::map<std::string,std::string> getPluginDetails(const std::string& path);
std::vector<std::map<std::string,std::string>> getPluginPreferences(const std::string& path);
bool setPluginPreference(const std::string& path, const std::string& key, const std::string& value);
std::map<std::string,std::string> getPluginPreferencesValues(const std::string& path);
bool resetPluginPreferencesValues(const std::string& path);
std::vector<std::string> listAvailablePlugins();
std::vector<std::string> listLoadedPlugins();
int installPlugin(const std::string& jplPath, const bool& force);
int uninstallPlugin(const std::string& pluginRootPath);
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);
// Methods
bool loadPlugin(const std::string& path);
bool unloadPlugin(const std::string& path);
void togglePlugin(const std::string& path, const bool& toggle);
std::map<std::string, std::string> getPluginDetails(const std::string& path);
std::vector<std::map<std::string, std::string>> getPluginPreferences(const std::string& path);
bool setPluginPreference(const std::string& path,
const std::string& key,
const std::string& value);
std::map<std::string, std::string> getPluginPreferencesValues(const std::string& path);
bool resetPluginPreferencesValues(const std::string& path);
std::vector<std::string> listAvailablePlugins();
std::vector<std::string> listLoadedPlugins();
int installPlugin(const std::string& jplPath, const bool& force);
int uninstallPlugin(const std::string& pluginRootPath);
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();
bool getPluginsEnabled();
void setPluginsEnabled(const bool& state);
std::map<std::string, std::string> getCallMediaHandlerStatus();
};
......@@ -36,12 +36,13 @@ namespace DRing {
DRING_PUBLIC bool loadPlugin(const std::string& path);
DRING_PUBLIC bool unloadPlugin(const std::string& path);
DRING_PUBLIC void togglePlugin(const std::string& path, bool toggle);
DRING_PUBLIC std::map<std::string,std::string> getPluginDetails(const std::string& path);
DRING_PUBLIC std::vector<std::map<std::string,std::string>> getPluginPreferences(const std::string& path);
DRING_PUBLIC std::map<std::string, std::string> getPluginDetails(const std::string& path);
DRING_PUBLIC std::vector<std::map<std::string, std::string>> getPluginPreferences(
const std::string& path);
DRING_PUBLIC bool setPluginPreference(const std::string& path,
const std::string& key,
const std::string& value);
DRING_PUBLIC std::map<std::string,std::string> getPluginPreferencesValues(const std::string& path);
const std::string& key,
const std::string& value);
DRING_PUBLIC std::map<std::string, std::string> getPluginPreferencesValues(const std::string& path);
DRING_PUBLIC bool resetPluginPreferencesValues(const std::string& path);
DRING_PUBLIC std::vector<std::string> listAvailablePlugins();
DRING_PUBLIC std::vector<std::string> listLoadedPlugins();
......@@ -49,8 +50,8 @@ DRING_PUBLIC int installPlugin(const std::string& jplPath, bool force);
DRING_PUBLIC int uninstallPlugin(const std::string& pluginRootPath);
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 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();
}
DRING_PUBLIC std::map<std::string, std::string> getCallMediaHandlerStatus();
} // namespace DRing
......@@ -150,23 +150,23 @@ uncompressJplFunction(const std::string& relativeFileName)
std::string
convertArrayToString(const Json::Value& jsonArray)
{
std::string stringArray = "[";
for (int i = 0; i < static_cast<int>(jsonArray.size()) - 1; i++) {
if (jsonArray[i].isString()) {
stringArray += jsonArray[i].asString() + ",";
} else if (jsonArray[i].isArray()) {
stringArray += convertArrayToString(jsonArray[i]) + ",";
std::string stringArray = "";
if (jsonArray.size()) {
for (unsigned i = 0; i < jsonArray.size() - 1; i++) {
if (jsonArray[i].isString()) {
stringArray += jsonArray[i].asString() + ",";
} else if (jsonArray[i].isArray()) {
stringArray += convertArrayToString(jsonArray[i]) + ",";
}
}
}
int lastIndex = static_cast<int>(jsonArray.size()) - 1;
if (jsonArray[lastIndex].isString()) {
stringArray += jsonArray[lastIndex].asString();
unsigned lastIndex = jsonArray.size() - 1;
if (jsonArray[lastIndex].isString()) {
stringArray += jsonArray[lastIndex].asString();
}
}
stringArray += "]";
return stringArray;
}
......@@ -337,11 +337,10 @@ JamiPluginManager::unloadPlugin(const std::string& rootPath)
void
JamiPluginManager::togglePlugin(const std::string& rootPath, bool toggle)
{
//This function should not be used as is
//One should modify it to perform plugin install followed by load
//rootPath should be the jplpath!
try
{
// This function should not be used as is
// One should modify it to perform plugin install followed by load
// rootPath should be the jplpath!
try {
std::string soPath = getPluginDetails(rootPath).at("soPath");
// remove the previous plugin object if it was registered
pm_.destroyPluginComponents(soPath);
......@@ -382,16 +381,21 @@ JamiPluginManager::getPluginPreferences(const std::string& rootPath)
if (file) {
bool ok = Json::parseFromStream(rbuilder, file, &root, &errs);
if (ok && root.isArray()) {
for (int i = 0; i < static_cast<int>(root.size()); i++) {
const Json::Value jsonPreference = root[i];
for (unsigned i = 0; i < root.size(); i++) {
const Json::Value& jsonPreference = root[i];
std::string category = jsonPreference.get("category", "NoCategory").asString();
std::string type = jsonPreference.get("type", "None").asString();
std::string key = jsonPreference.get("key", "None").asString();
if (type != "None" && key != "None") {
if (keys.find(key) == keys.end()) {
const auto& preferenceAttributes = parsePreferenceConfig(jsonPreference,
type);
// If the parsing of the attributes was successful, commit the map and the key
auto preferenceAttributes = parsePreferenceConfig(jsonPreference, type);
// If the parsing of the attributes was successful, commit the map and the keys
auto defaultValue = preferenceAttributes.find("defaultValue");
if (type == "Path" && defaultValue != preferenceAttributes.end()) {
defaultValue->second = rootPath + DIR_SEPARATOR_STR
+ defaultValue->second;
}
if (!preferenceAttributes.empty()) {
preferences.push_back(std::move(preferenceAttributes));
keys.insert(key);
......@@ -448,7 +452,6 @@ JamiPluginManager::setPluginPreference(const std::string& rootPath,
const std::string& key,
const std::string& value)
{
bool returnValue = false;
std::map<std::string, std::string> pluginUserPreferencesMap = getPluginUserPreferencesValuesMap(
rootPath);
std::map<std::string, std::string> pluginPreferencesMap = getPluginPreferencesValuesMap(
......@@ -473,14 +476,13 @@ JamiPluginManager::setPluginPreference(const std::string& rootPath,
try {
std::lock_guard<std::mutex> guard(fileutils::getFileLock(preferencesValuesFilePath));
msgpack::pack(fs, pluginUserPreferencesMap);
returnValue = true;
return true;
} catch (const std::exception& e) {
returnValue = false;
JAMI_ERR() << e.what();
return false;
}
}
return returnValue;
return false;
}
std::map<std::string, std::string>
......
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