[systemsetting] Removed try/catch error handling
authorGrzegorz Rynkowski <g.rynkowski@samsung.com>
Wed, 11 Feb 2015 10:36:13 +0000 (11:36 +0100)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Fri, 13 Feb 2015 12:19:03 +0000 (21:19 +0900)
[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 <g.rynkowski@samsung.com>
Signed-off-by: Lukasz Bardeli <l.bardeli@samsung.com>
src/systemsetting/systemsetting_instance.cc
src/systemsetting/systemsetting_instance.h

index 5c7645a..b1d412c 100644 (file)
@@ -6,9 +6,8 @@
 
 #include <memory>
 
-#include "common/picojson.h"
 #include "common/logger.h"
-#include "common/platform_exception.h"
+#include "common/picojson.h"
 #include "common/task-queue.h"
 
 #include <system_settings.h>
@@ -54,13 +53,12 @@ void SystemSettingInstance::getProperty(const picojson::value& args, picojson::o
 
     auto get = [this, type](const std::shared_ptr<picojson::value>& 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<picojson::object>());
-        } catch (const PlatformException& e) {
-            ReportError(e, response->get<picojson::object>());
-        }
+        else
+            ReportError(status, &response->get<picojson::object>());
     };
 
     auto get_response = [this, callback_id](const std::shared_ptr<picojson::value>& response) -> void {
@@ -74,9 +72,9 @@ void SystemSettingInstance::getProperty(const picojson::value& args, picojson::o
         (get, get_response, std::shared_ptr<picojson::value>(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<picojson::object>();
 
     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<picojson::value>& response) -> void {
         LoggerD("Setting platform value");
-        try {
-            picojson::value result;
-            setPlatformPropertyValue(type, value, &result);
-            ReportSuccess(result, response->get<picojson::object>());
-        } catch (const PlatformException& e) {
-            ReportError(e, response->get<picojson::object>());
-        }
+        PlatformResult status = setPlatformPropertyValue(type, value);
+        if (status.IsSuccess())
+            ReportSuccess(response->get<picojson::object>());
+        else
+            ReportError(status, &response->get<picojson::object>());
     };
 
     auto get_response = [this, callback_id](const std::shared_ptr<picojson::value>& response) -> void {
@@ -147,11 +144,9 @@ void SystemSettingInstance::setProperty(const picojson::value& args, picojson::o
         (get, get_response, std::shared_ptr<picojson::value>(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<picojson::object>();
-
+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);
     }
 }
 
index 08c85cc..8ad8e2b 100644 (file)
@@ -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