From: Pawel Andruszkiewicz Date: Thu, 8 Oct 2015 13:21:34 +0000 (+0200) Subject: [Common] Removed throwing version of method from DBus helper class. X-Git-Tag: submit/tizen/20151026.073646^2^2~38^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3973881fcd6d8fe5adec3d68b665c2ee6915a62a;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Common] Removed throwing version of method from DBus helper class. [Verification] TCT pass rate (Power module) is 100% (auto and manual). Change-Id: I6ad011bd2f608633c4fb753dbcbbc272b01155e3 Signed-off-by: Pawel Andruszkiewicz --- diff --git a/src/common/dbus_operation.cc b/src/common/dbus_operation.cc index 3e027e60..2be83002 100755 --- a/src/common/dbus_operation.cc +++ b/src/common/dbus_operation.cc @@ -24,8 +24,7 @@ #include #include -#include "logger.h" -#include "platform_exception.h" +#include "common/logger.h" #define DBUS_REPLY_TIMEOUT (-1) @@ -179,73 +178,6 @@ DBusOperation::~DBusOperation() { } } -int DBusOperation::InvokeSyncGetInt(const std::string& method, - DBusOperationArguments* args) { - - LoggerD("Enter"); - if (!connection_) { - connection_ = dbus_bus_get_private(DBUS_BUS_SYSTEM, nullptr); - } - - if (!connection_) { - LoggerE("dbus_bus_get_private error"); - throw UnknownException("Failed to get dbus connection"); - } - - DBusMessage* msg = dbus_message_new_method_call(destination_.c_str(), - path_.c_str(), - interface_.c_str(), - method.c_str()); - - if (!msg) { - LoggerE("dbus_message_new_method_call error"); - throw UnknownException("Failed to create dbus message"); - } - - DBusMessageIter iter; - dbus_message_iter_init_append(msg, &iter); - - if (nullptr != args) { - try { - args->AppendVariant(&iter); - } catch (const UnknownException& ex) { - LoggerE("append_variant error"); - dbus_message_unref(msg); - throw UnknownException("Failed to append dbus variable"); - } - } - - DBusError err; - dbus_error_init(&err); - DBusMessage* reply = dbus_connection_send_with_reply_and_block(connection_, - msg, - DBUS_REPLY_TIMEOUT, - &err); - dbus_message_unref(msg); - - if (!reply) { - LoggerE("dbus_connection_send_with_reply_and_block error %s: %s", err.name, err.message); - dbus_error_free(&err); - throw UnknownException("Failed to send request via dbus"); - } - - int result = 0; - dbus_bool_t ret = dbus_message_get_args(reply, - &err, - DBUS_TYPE_INT32, - &result, - DBUS_TYPE_INVALID); - dbus_message_unref(reply); - - if (!ret) { - LoggerE("dbus_message_get_args error %s: %s", err.name, err.message); - dbus_error_free(&err); - throw UnknownException("Failed to get reply from dbus"); - } - - return result; -} - PlatformResult DBusOperation::InvokeSyncGetInt(const std::string& method, DBusOperationArguments* args, int* result) { diff --git a/src/common/dbus_operation.h b/src/common/dbus_operation.h index 7a0d6ab2..72fcb370 100755 --- a/src/common/dbus_operation.h +++ b/src/common/dbus_operation.h @@ -22,7 +22,8 @@ #include #include -#include "platform_result.h" + +#include "common/platform_result.h" namespace common { @@ -73,9 +74,6 @@ class DBusOperation { const std::string& interface); virtual ~DBusOperation(); - int InvokeSyncGetInt(const std::string& method, - DBusOperationArguments* args); - //TODO remove throwing methods when they would be not needed any more. common::PlatformResult InvokeSyncGetInt(const std::string& method, DBusOperationArguments* args, int* result); diff --git a/src/power/power_manager.cc b/src/power/power_manager.cc index 5965b6fa..9788d89d 100755 --- a/src/power/power_manager.cc +++ b/src/power/power_manager.cc @@ -143,9 +143,10 @@ PlatformResult PowerManager::Request(PowerResource resource, PowerState state) { return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "invalid PowerState"); if(current_requested_state_ == POWER_STATE_SCREEN_DIM) { - int ret = PowerPlatformProxy::GetInstance().UnlockState(); - if (ret < 0) { - LoggerE("deviceUnlockState error %d", ret); + int result = 0; + auto error_code = PowerPlatformProxy::GetInstance().UnlockState(&result); + if (!error_code || result < 0) { + LoggerE("deviceUnlockState error %d", result); return PlatformResult(ErrorCode::UNKNOWN_ERR, "device_power_request_unlock error"); } @@ -165,9 +166,10 @@ PlatformResult PowerManager::Request(PowerResource resource, PowerState state) { } case POWER_STATE_SCREEN_DIM: { - ret = PowerPlatformProxy::GetInstance().LockState(); - if (ret < 0) { - LoggerE("device_power_request_lock error %d", ret); + int result = 0; + auto error_code = PowerPlatformProxy::GetInstance().LockState(&result); + if (!error_code || result < 0) { + LoggerE("device_power_request_lock error %d", result); return PlatformResult(ErrorCode::UNKNOWN_ERR, "device_power_request_lock error"); } @@ -244,9 +246,10 @@ PlatformResult PowerManager::Release(PowerResource resource) { LoggerE("Platform return value from dim unlock: %d", ret); if (bright_state_enabled_) { - ret = PowerPlatformProxy::GetInstance().SetBrightnessFromSettings(); - if (DEVICE_ERROR_NONE != ret) { - LoggerE("Platform error while setting restore brightness %d", ret); + int result = 0; + auto error_code = PowerPlatformProxy::GetInstance().SetBrightnessFromSettings(&result); + if (!error_code || DEVICE_ERROR_NONE != result) { + LoggerE("Platform error while setting restore brightness %d", result); return PlatformResult(ErrorCode::UNKNOWN_ERR, "Platform error while setting restore brightness"); } @@ -255,9 +258,10 @@ PlatformResult PowerManager::Release(PowerResource resource) { display_state_e platform_state = DISPLAY_STATE_NORMAL; if(current_requested_state_ == POWER_STATE_SCREEN_DIM) { - ret = PowerPlatformProxy::GetInstance().UnlockState(); - if (DEVICE_ERROR_NONE != ret) { - LoggerE("Failed to UnlockState (%d)", ret); + int result = 0; + auto error_code = PowerPlatformProxy::GetInstance().UnlockState(&result); + if (!error_code || DEVICE_ERROR_NONE != result) { + LoggerE("Failed to UnlockState (%d)", result); } } ret = device_display_get_state(&platform_state); @@ -281,7 +285,15 @@ PlatformResult PowerManager::Release(PowerResource resource) { PlatformResult PowerManager::GetScreenBrightness(double* output) { LoggerD("Enter"); - int brightness = GetPlatformBrightness(); + int brightness = 0; + + auto error_code = GetPlatformBrightness(&brightness); + + if (!error_code) { + LoggerE("Failed to obtain brightness value from platform."); + return error_code; + } + LoggerD("Brightness value: %d", brightness); int max_brightness; @@ -363,9 +375,10 @@ PlatformResult PowerManager::SetScreenState(bool onoff) { PlatformResult PowerManager::RestoreScreenBrightness() { LoggerD("Enter"); - int ret = PowerPlatformProxy::GetInstance().SetBrightnessFromSettings(); - if (DEVICE_ERROR_NONE != ret) { - LoggerE("Platform error while restoring brightness %d", ret); + int result = 0; + auto error_code = PowerPlatformProxy::GetInstance().SetBrightnessFromSettings(&result); + if (!error_code || DEVICE_ERROR_NONE != result) { + LoggerE("Platform error while restoring brightness %d", result); return PlatformResult(ErrorCode::UNKNOWN_ERR, "Platform error while restoring brightness"); } @@ -388,9 +401,10 @@ PlatformResult PowerManager::SetPlatformBrightness(int brightness) { should_be_read_from_cache_ = false; } - int ret = PowerPlatformProxy::GetInstance().SetBrightness(brightness); - if (ret != 0) { - LoggerE("Platform error while setting %d brightness: %d", brightness, ret); + int result = 0; + auto error_code = PowerPlatformProxy::GetInstance().SetBrightness(brightness, &result); + if (!error_code || result != 0) { + LoggerE("Platform error while setting %d brightness: %d", brightness, result); return PlatformResult(ErrorCode::UNKNOWN_ERR, "Platform error while setting brightness."); } @@ -399,15 +413,23 @@ PlatformResult PowerManager::SetPlatformBrightness(int brightness) { return PlatformResult(ErrorCode::NO_ERROR); } -int PowerManager::GetPlatformBrightness(){ +PlatformResult PowerManager::GetPlatformBrightness(int* result) { LoggerD("Entered"); int brightness = 0; - int is_custom_mode = PowerPlatformProxy::GetInstance().IsCustomBrightness(); + int is_custom_mode = 0; + auto error_code = PowerPlatformProxy::GetInstance().IsCustomBrightness(&is_custom_mode); + + if (!error_code) { + LoggerE("Failed to check if custom brightness is set."); + return error_code; + } + if ((is_custom_mode && current_brightness_ != -1) || should_be_read_from_cache_) { LoggerD("return custom brightness %d", current_brightness_); - return current_brightness_; + *result = current_brightness_; + return PlatformResult(ErrorCode::NO_ERROR); } int is_auto_brightness = 0; @@ -420,11 +442,19 @@ int PowerManager::GetPlatformBrightness(){ } } else { LoggerD("Brightness via DBUS"); - brightness = PowerPlatformProxy::GetInstance().GetBrightness(); + error_code = PowerPlatformProxy::GetInstance().GetBrightness(&brightness); + + if (!error_code) { + LoggerE("Failed to obtain brightness via DBUS."); + return error_code; + } } + LoggerD("BRIGHTNESS(%s) %d", is_auto_brightness == 1 ? "auto" : "fix" , brightness); - return brightness; + *result = brightness; + + return PlatformResult(ErrorCode::NO_ERROR); } diff --git a/src/power/power_manager.h b/src/power/power_manager.h index 56191ac5..7af09e48 100755 --- a/src/power/power_manager.h +++ b/src/power/power_manager.h @@ -59,7 +59,7 @@ class PowerManager { static PowerManager* GetInstance(); private: - int GetPlatformBrightness(); + common::PlatformResult GetPlatformBrightness(int* result); common::PlatformResult SetPlatformBrightness(int brightness); common::PlatformResult RestoreSettedBrightness(); diff --git a/src/power/power_platform_proxy.cc b/src/power/power_platform_proxy.cc index 568b71ed..5a9c4703 100755 --- a/src/power/power_platform_proxy.cc +++ b/src/power/power_platform_proxy.cc @@ -45,7 +45,7 @@ PowerPlatformProxy& PowerPlatformProxy::GetInstance() return instance; } -int PowerPlatformProxy::LockState() +common::PlatformResult PowerPlatformProxy::LockState(int* result) { LoggerD("Entered"); DBusOperationArguments args; @@ -54,42 +54,42 @@ int PowerPlatformProxy::LockState() args.AddArgumentString("NULL"); args.AddArgumentInt32(0); - return dbus_op_.InvokeSyncGetInt("lockstate", &args); + return dbus_op_.InvokeSyncGetInt("lockstate", &args, result); } -int PowerPlatformProxy::UnlockState() +common::PlatformResult PowerPlatformProxy::UnlockState(int* result) { LoggerD("Entered"); DBusOperationArguments args; args.AddArgumentString("lcddim"); args.AddArgumentString("keeptimer"); - return dbus_op_.InvokeSyncGetInt("unlockstate", &args); + return dbus_op_.InvokeSyncGetInt("unlockstate", &args, result); } -int PowerPlatformProxy::SetBrightnessFromSettings() +common::PlatformResult PowerPlatformProxy::SetBrightnessFromSettings(int* result) { LoggerD("Entered"); - return dbus_op_.InvokeSyncGetInt("ReleaseBrightness", NULL); + return dbus_op_.InvokeSyncGetInt("ReleaseBrightness", nullptr, result); } -int PowerPlatformProxy::SetBrightness(int val) +common::PlatformResult PowerPlatformProxy::SetBrightness(int val, int* result) { LoggerD("Entered"); DBusOperationArguments args; args.AddArgumentInt32(val); - return dbus_op_.InvokeSyncGetInt("HoldBrightness", &args); + return dbus_op_.InvokeSyncGetInt("HoldBrightness", &args, result); } -int PowerPlatformProxy::GetBrightness() { +common::PlatformResult PowerPlatformProxy::GetBrightness(int* result) { LoggerD("Entered"); - return dbus_op_.InvokeSyncGetInt("CurrentBrightness", NULL); + return dbus_op_.InvokeSyncGetInt("CurrentBrightness", nullptr, result); } -int PowerPlatformProxy::IsCustomBrightness() { +common::PlatformResult PowerPlatformProxy::IsCustomBrightness(int* result) { LoggerD("Entered"); - return dbus_op_.InvokeSyncGetInt("CustomBrightness", NULL); + return dbus_op_.InvokeSyncGetInt("CustomBrightness", nullptr, result); } } // namespace power diff --git a/src/power/power_platform_proxy.h b/src/power/power_platform_proxy.h index 25cacff0..1c42a185 100755 --- a/src/power/power_platform_proxy.h +++ b/src/power/power_platform_proxy.h @@ -24,13 +24,13 @@ namespace power { class PowerPlatformProxy { public: - int LockState(); - int UnlockState(); - int SetBrightnessFromSettings(); - int SetBrightness(int val); + common::PlatformResult LockState(int* result); + common::PlatformResult UnlockState(int* result); + common::PlatformResult SetBrightnessFromSettings(int* result); + common::PlatformResult SetBrightness(int val, int* result); - int GetBrightness(); - int IsCustomBrightness(); + common::PlatformResult GetBrightness(int* result); + common::PlatformResult IsCustomBrightness(int* result); static PowerPlatformProxy& GetInstance(); @@ -38,7 +38,7 @@ class PowerPlatformProxy { PowerPlatformProxy(); virtual ~PowerPlatformProxy(); - common::DBusOperation dbus_op_; + common::DBusOperation dbus_op_; }; } // namespace power