From 9db5a43405103fdc5e47876a1c6d1439a0c7cbc2 Mon Sep 17 00:00:00 2001 From: Grzegorz Rynkowski Date: Fri, 6 Feb 2015 15:49:54 +0100 Subject: [PATCH] [systemsetting] Small refactoring Description: Prepared the code to provide returning result status from methods. Verification: Build the code. Change-Id: Ib4128b621c741e666ab597847140ecb5fb6d092c Signed-off-by: Grzegorz Rynkowski --- src/systemsetting/systemsetting_instance.cc | 81 +++++++++++++---------------- src/systemsetting/systemsetting_instance.h | 6 +-- 2 files changed, 38 insertions(+), 49 deletions(-) diff --git a/src/systemsetting/systemsetting_instance.cc b/src/systemsetting/systemsetting_instance.cc index 5fa053d..5c7645a 100644 --- a/src/systemsetting/systemsetting_instance.cc +++ b/src/systemsetting/systemsetting_instance.cc @@ -55,8 +55,8 @@ void SystemSettingInstance::getProperty(const picojson::value& args, picojson::o auto get = [this, type](const std::shared_ptr& response) -> void { LoggerD("Getting platform value"); try { - int platformResult; - picojson::value result = getPlatformPropertyValue(type, platformResult); + picojson::value result; + getPlatformPropertyValue(type, &result); ReportSuccess(result, response->get()); } catch (const PlatformException& e) { ReportError(e, response->get()); @@ -74,14 +74,13 @@ void SystemSettingInstance::getProperty(const picojson::value& args, picojson::o (get, get_response, std::shared_ptr(new picojson::value(picojson::object()))); } -picojson::value SystemSettingInstance::getPlatformPropertyValue( - const std::string &settingType, int &platformResult) +void SystemSettingInstance::getPlatformPropertyValue( + const std::string& settingType, picojson::value* out) { + picojson::object& result_obj = out->get(); + int ret; char *value = NULL; - picojson::value result = picojson::value(picojson::object()); - picojson::object& result_obj = result.get(); - if (settingType == SETTING_HOME_SCREEN) { ret = system_settings_get_value_string( SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, &value); @@ -100,23 +99,19 @@ picojson::value SystemSettingInstance::getPlatformPropertyValue( } // other values (not specified in the documentation) are handled in JS - platformResult = ret; - - if (ret == SYSTEM_SETTINGS_ERROR_NONE) { - LoggerD("ret == SYSTEM_SETTINGS_ERROR_NONE"); - result_obj.insert(std::make_pair("value", value)); - free(value); - } - else if (ret == SYSTEM_SETTINGS_ERROR_CALL_UNSUPPORTED_API) { - LoggerD("ret == SYSTEM_SETTINGS_ERROR_CALL_UNSUPPORTED_API"); - throw NotSupportedException("This property is not supported."); - } - else { - LoggerD("Other error"); - throw UnknownException("Unknown error"); - } - - return result; + switch (ret) { + case SYSTEM_SETTINGS_ERROR_NONE: + LoggerD("ret == SYSTEM_SETTINGS_ERROR_NONE"); + result_obj.insert(std::make_pair("value", value)); + free(value); + break; + case SYSTEM_SETTINGS_ERROR_CALL_UNSUPPORTED_API: + LoggerD("ret == SYSTEM_SETTINGS_ERROR_CALL_UNSUPPORTED_API"); + throw NotSupportedException("This property is not supported."); + default: + LoggerD("Other error"); + throw UnknownException("Unknown error"); + } } void SystemSettingInstance::setProperty(const picojson::value& args, picojson::object& out) @@ -133,8 +128,8 @@ void SystemSettingInstance::setProperty(const picojson::value& args, picojson::o auto get = [this, type, value](const std::shared_ptr& response) -> void { LoggerD("Setting platform value"); try { - int platformResult; - picojson::value result = setPlatformPropertyValue(type, value, platformResult); + picojson::value result; + setPlatformPropertyValue(type, value, &result); ReportSuccess(result, response->get()); } catch (const PlatformException& e) { ReportError(e, response->get()); @@ -152,13 +147,12 @@ void SystemSettingInstance::setProperty(const picojson::value& args, picojson::o (get, get_response, std::shared_ptr(new picojson::value(picojson::object()))); } -picojson::value SystemSettingInstance::setPlatformPropertyValue( - const std::string &settingType, const std::string &settingValue, int &platformResult) +void SystemSettingInstance::setPlatformPropertyValue( + const std::string& settingType, const std::string& settingValue, picojson::value* out) { - int ret; - picojson::value result = picojson::value(picojson::object()); - picojson::object& result_obj = result.get(); + picojson::object& result_obj = out->get(); + int ret; if (settingType == SETTING_HOME_SCREEN) { ret = system_settings_set_value_string( SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, settingValue.c_str()); @@ -177,24 +171,19 @@ picojson::value SystemSettingInstance::setPlatformPropertyValue( } // other values (not specified in the documentation) are handled in JS - platformResult = ret; - - if (ret == SYSTEM_SETTINGS_ERROR_NONE) { - LoggerD("ret == SYSTEM_SETTINGS_ERROR_NONE"); - } - else if (ret == SYSTEM_SETTINGS_ERROR_CALL_UNSUPPORTED_API) { - LoggerD("ret == SYSTEM_SETTINGS_ERROR_CALL_UNSUPPORTED_API"); - throw NotSupportedException("This property is not supported."); + switch (ret) { + case SYSTEM_SETTINGS_ERROR_NONE: + LoggerD("ret == SYSTEM_SETTINGS_ERROR_NONE"); + return; + case SYSTEM_SETTINGS_ERROR_CALL_UNSUPPORTED_API: + LoggerD("ret == SYSTEM_SETTINGS_ERROR_CALL_UNSUPPORTED_API"); + throw NotSupportedException("This property is not supported."); + default: + LoggerD("Other error"); + throw UnknownException("Unknown error"); } - else { - LoggerD("Other error"); - throw UnknownException("Unknown error"); - } - - return result; } - } // namespace systemsetting } // namespace extension diff --git a/src/systemsetting/systemsetting_instance.h b/src/systemsetting/systemsetting_instance.h index d36d25a..08c85cc 100644 --- a/src/systemsetting/systemsetting_instance.h +++ b/src/systemsetting/systemsetting_instance.h @@ -18,11 +18,11 @@ public: private: void getProperty(const picojson::value& args, picojson::object& out); - picojson::value getPlatformPropertyValue(const std::string &valueType, int &platformResult); + void getPlatformPropertyValue(const std::string& valueType, picojson::value* out); void setProperty(const picojson::value& args, picojson::object& out); - picojson::value setPlatformPropertyValue(const std::string &settingType, - const std::string &settingValue, int &platformResult); + void setPlatformPropertyValue(const std::string& settingType, + const std::string& settingValue, picojson::value* out); }; } // namespace systemsetting -- 2.7.4