[Common] Removed throwing version of method from DBus helper class.
authorPawel Andruszkiewicz <p.andruszkie@samsung.com>
Thu, 8 Oct 2015 13:21:34 +0000 (15:21 +0200)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Thu, 8 Oct 2015 14:53:07 +0000 (16:53 +0200)
[Verification] TCT pass rate (Power module) is 100% (auto and manual).

Change-Id: I6ad011bd2f608633c4fb753dbcbbc272b01155e3
Signed-off-by: Pawel Andruszkiewicz <p.andruszkie@samsung.com>
src/common/dbus_operation.cc
src/common/dbus_operation.h
src/power/power_manager.cc
src/power/power_manager.h
src/power/power_platform_proxy.cc
src/power/power_platform_proxy.h

index 3e027e600a8169c2015ff54c7dec1a69723e5e58..2be8300223559d97be819a827f87368c94c02820 100755 (executable)
@@ -24,8 +24,7 @@
 #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)
 
@@ -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) {
 
index 7a0d6ab2e7f0a796ec4101aa3b4c5b623d5a162f..72fcb370158fa12b48f82b305b191d5922d497de 100755 (executable)
@@ -22,7 +22,8 @@
 #include <set>
 
 #include <dbus/dbus.h>
-#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);
 
index 5965b6fa51f05c1489dea73fdc6d7d193cdbe3d5..9788d89da28125e983459411387c7e770913e3a1 100755 (executable)
@@ -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);
 }
 
 
index 56191ac522611ebe47e2b0e7118bf00c393a330c..7af09e48d58f22d05f49d68702d5817aa79aa845 100755 (executable)
@@ -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();
 
index 568b71ed02bd277ac48b95b9c2f33690c9ba60f2..5a9c4703d99933fec3aeead100b535274f21911a 100755 (executable)
@@ -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
index 25cacff05174e6b224297fed02ac6c6e0bad0178..1c42a1855f4dae228c61cee59dacccc1a4b3c73b 100755 (executable)
@@ -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