[Verification] TCT pass rate (Power module) is 100% (auto and manual).
Change-Id: I6ad011bd2f608633c4fb753dbcbbc272b01155e3
Signed-off-by: Pawel Andruszkiewicz <p.andruszkie@samsung.com>
#include <dbus/dbus.h>
#include <dbus/dbus-glib-lowlevel.h>
-#include "logger.h"
-#include "platform_exception.h"
+#include "common/logger.h"
#define DBUS_REPLY_TIMEOUT (-1)
}
}
-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) {
#include <set>
#include <dbus/dbus.h>
-#include "platform_result.h"
+
+#include "common/platform_result.h"
namespace common {
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);
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");
}
}
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");
}
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");
}
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);
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;
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");
}
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.");
}
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;
}
} 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);
}
static PowerManager* GetInstance();
private:
- int GetPlatformBrightness();
+ common::PlatformResult GetPlatformBrightness(int* result);
common::PlatformResult SetPlatformBrightness(int brightness);
common::PlatformResult RestoreSettedBrightness();
return instance;
}
-int PowerPlatformProxy::LockState()
+common::PlatformResult PowerPlatformProxy::LockState(int* result)
{
LoggerD("Entered");
DBusOperationArguments args;
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
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();
PowerPlatformProxy();
virtual ~PowerPlatformProxy();
- common::DBusOperation dbus_op_;
+ common::DBusOperation dbus_op_;
};
} // namespace power