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

plugin: code cleanup

Change-Id: I5573606fae39567caf9026e9b1253b33588ab292
parent 60194fac
No related branches found
No related tags found
No related merge requests found
......@@ -56,7 +56,9 @@ DBusPluginManagerInterface::getPluginPreferences(const std::string& 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);
}
......
......@@ -43,8 +43,8 @@
#pragma GCC diagnostic warning "-Wunused-but-set-variable"
#endif
class DRING_PUBLIC DBusPluginManagerInterface :
public cx::ring::Ring::PluginManagerInterface_adaptor,
class DRING_PUBLIC DBusPluginManagerInterface
: public cx::ring::Ring::PluginManagerInterface_adaptor,
public DBus::IntrospectableAdaptor,
public DBus::ObjectAdaptor
{
......@@ -57,7 +57,9 @@ class DRING_PUBLIC DBusPluginManagerInterface :
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);
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();
......
......@@ -37,7 +37,8 @@ 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::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);
......@@ -53,4 +54,4 @@ DRING_PUBLIC std::map<std::string,std::string> getCallMediaHandlerDetails(const
DRING_PUBLIC bool getPluginsEnabled();
DRING_PUBLIC void setPluginsEnabled(bool state);
DRING_PUBLIC std::map<std::string, std::string> getCallMediaHandlerStatus();
}
} // namespace DRing
......@@ -150,9 +150,10 @@ uncompressJplFunction(const std::string& relativeFileName)
std::string
convertArrayToString(const Json::Value& jsonArray)
{
std::string stringArray = "[";
std::string stringArray = "";
for (int i = 0; i < static_cast<int>(jsonArray.size()) - 1; i++) {
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()) {
......@@ -160,12 +161,11 @@ convertArrayToString(const Json::Value& jsonArray)
}
}
int lastIndex = static_cast<int>(jsonArray.size()) - 1;
unsigned lastIndex = jsonArray.size() - 1;
if (jsonArray[lastIndex].isString()) {
stringArray += jsonArray[lastIndex].asString();
}
stringArray += "]";
}
return stringArray;
}
......@@ -340,8 +340,7 @@ 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
{
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>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment