From: Grzegorz Rynkowski Date: Wed, 11 Feb 2015 10:36:13 +0000 (+0100) Subject: [systemsetting] Removed try/catch error handling X-Git-Tag: submit/tizen_mobile/20150603.064609~1^2~449 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=990e2af2b0806a4d630de4246a05d06934c04e96;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [systemsetting] Removed try/catch error handling [Problem] C++ exceptions are being used at the source. According to Google C++ Style Guide they are prohibited. [Solution] Use the PlatformResult to handle error. [Verification] Build the code. Change-Id: Ib58920abae920a7250c4943a33e8b85d459b808f Signed-off-by: Grzegorz Rynkowski Signed-off-by: Lukasz Bardeli --- diff --git a/src/systemsetting/systemsetting_instance.cc b/src/systemsetting/systemsetting_instance.cc index 5c7645a..b1d412c 100644 --- a/src/systemsetting/systemsetting_instance.cc +++ b/src/systemsetting/systemsetting_instance.cc @@ -6,9 +6,8 @@ #include -#include "common/picojson.h" #include "common/logger.h" -#include "common/platform_exception.h" +#include "common/picojson.h" #include "common/task-queue.h" #include @@ -54,13 +53,12 @@ void SystemSettingInstance::getProperty(const picojson::value& args, picojson::o auto get = [this, type](const std::shared_ptr& response) -> void { LoggerD("Getting platform value"); - try { - picojson::value result; - getPlatformPropertyValue(type, &result); + picojson::value result = picojson::value(picojson::object()); + PlatformResult status = getPlatformPropertyValue(type, &result); + if(status.IsSuccess()) ReportSuccess(result, response->get()); - } catch (const PlatformException& e) { - ReportError(e, response->get()); - } + else + ReportError(status, &response->get()); }; auto get_response = [this, callback_id](const std::shared_ptr& response) -> void { @@ -74,9 +72,9 @@ void SystemSettingInstance::getProperty(const picojson::value& args, picojson::o (get, get_response, std::shared_ptr(new picojson::value(picojson::object()))); } -void SystemSettingInstance::getPlatformPropertyValue( - const std::string& settingType, picojson::value* out) -{ +PlatformResult SystemSettingInstance::getPlatformPropertyValue( + const std::string& settingType, + picojson::value* out) { picojson::object& result_obj = out->get(); int ret; @@ -104,13 +102,14 @@ void SystemSettingInstance::getPlatformPropertyValue( LoggerD("ret == SYSTEM_SETTINGS_ERROR_NONE"); result_obj.insert(std::make_pair("value", value)); free(value); - break; + return PlatformResult(ErrorCode::NO_ERROR); case SYSTEM_SETTINGS_ERROR_CALL_UNSUPPORTED_API: LoggerD("ret == SYSTEM_SETTINGS_ERROR_CALL_UNSUPPORTED_API"); - throw NotSupportedException("This property is not supported."); + return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, + "This property is not supported."); default: LoggerD("Other error"); - throw UnknownException("Unknown error"); + return PlatformResult(ErrorCode::UNKNOWN_ERR); } } @@ -127,13 +126,11 @@ 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 { - picojson::value result; - setPlatformPropertyValue(type, value, &result); - ReportSuccess(result, response->get()); - } catch (const PlatformException& e) { - ReportError(e, response->get()); - } + PlatformResult status = setPlatformPropertyValue(type, value); + if (status.IsSuccess()) + ReportSuccess(response->get()); + else + ReportError(status, &response->get()); }; auto get_response = [this, callback_id](const std::shared_ptr& response) -> void { @@ -147,11 +144,9 @@ void SystemSettingInstance::setProperty(const picojson::value& args, picojson::o (get, get_response, std::shared_ptr(new picojson::value(picojson::object()))); } -void SystemSettingInstance::setPlatformPropertyValue( - const std::string& settingType, const std::string& settingValue, picojson::value* out) -{ - picojson::object& result_obj = out->get(); - +PlatformResult SystemSettingInstance::setPlatformPropertyValue( + const std::string& settingType, + const std::string& settingValue) { int ret; if (settingType == SETTING_HOME_SCREEN) { ret = system_settings_set_value_string( @@ -174,13 +169,14 @@ void SystemSettingInstance::setPlatformPropertyValue( switch (ret) { case SYSTEM_SETTINGS_ERROR_NONE: LoggerD("ret == SYSTEM_SETTINGS_ERROR_NONE"); - return; + return PlatformResult(ErrorCode::NO_ERROR); case SYSTEM_SETTINGS_ERROR_CALL_UNSUPPORTED_API: LoggerD("ret == SYSTEM_SETTINGS_ERROR_CALL_UNSUPPORTED_API"); - throw NotSupportedException("This property is not supported."); + return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, + "This property is not supported."); default: LoggerD("Other error"); - throw UnknownException("Unknown error"); + return PlatformResult(ErrorCode::UNKNOWN_ERR); } } diff --git a/src/systemsetting/systemsetting_instance.h b/src/systemsetting/systemsetting_instance.h index 08c85cc..8ad8e2b 100644 --- a/src/systemsetting/systemsetting_instance.h +++ b/src/systemsetting/systemsetting_instance.h @@ -6,6 +6,7 @@ #define SYSTEMSETTING_SYSTEMSETTING_INSTANCE_H_ #include "common/extension.h" +#include "common/platform_result.h" namespace extension { namespace systemsetting { @@ -18,11 +19,14 @@ public: private: void getProperty(const picojson::value& args, picojson::object& out); - void getPlatformPropertyValue(const std::string& valueType, picojson::value* out); + common::PlatformResult getPlatformPropertyValue( + const std::string& valueType, + picojson::value* out); void setProperty(const picojson::value& args, picojson::object& out); - void setPlatformPropertyValue(const std::string& settingType, - const std::string& settingValue, picojson::value* out); + common::PlatformResult setPlatformPropertyValue( + const std::string& settingType, + const std::string& settingValue); }; } // namespace systemsetting