From: Szymon Jastrzebski Date: Fri, 17 Feb 2017 12:51:50 +0000 (+0100) Subject: [Notification] Method GetNotiHandleFromJson added X-Git-Tag: submit/tizen/20170222.074243~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=54a3bba036e0f0c82c77b5dc510e3c951fd254b1;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Notification] Method GetNotiHandleFromJson added [Verification] TCT Notification tests passed Change-Id: I66bfd8f0ae3a4dc8bf3e7ae0741710d1e5b25445 Signed-off-by: Szymon Jastrzebski --- diff --git a/src/notification/status_notification.cc b/src/notification/status_notification.cc index 13fe62c4..c6d7bf35 100644 --- a/src/notification/status_notification.cc +++ b/src/notification/status_notification.cc @@ -1144,9 +1144,9 @@ PlatformResult StatusNotification::ToJson(int id, return PlatformResult(ErrorCode::NO_ERROR); } -PlatformResult StatusNotification::FromJson(const picojson::object& args, - bool is_update, - picojson::object* out_ptr) { +PlatformResult StatusNotification::GetNotiHandleFromJson(const picojson::object& args, + bool is_update, + notification_h *noti_handle){ LoggerD("Enter"); picojson::object noti_obj = common::FromJson(args, "notification"); @@ -1160,32 +1160,29 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args, return status; int id = NOTIFICATION_PRIV_ID_NONE; - int ret; - notification_h noti_handle = nullptr; - app_control_h app_control = NULL; + app_control_h app_control = nullptr; SCOPE_EXIT { if (app_control) { app_control_destroy(app_control); } - notification_free(noti_handle); }; if (is_update) { id = std::stoi(common::FromJson(noti_obj, "id")); - PlatformResult status = GetNotiHandle(id, ¬i_handle); + PlatformResult status = GetNotiHandle(id, noti_handle); if (status.IsError()) return status; } else { - status = Create(noti_type, ¬i_handle); + status = Create(noti_type, noti_handle); if (status.IsError()) return status; } - status = SetLayout(noti_handle, status_type); + status = SetLayout(*noti_handle, status_type); if (status.IsError()) { return status; } @@ -1195,7 +1192,7 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args, const std::string& value_str = common::FromJson(noti_obj, "iconPath"); std::string real_path = common::FilesystemProvider::Create().GetRealPath(value_str); - status = SetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON, real_path); + status = SetImage(*noti_handle, NOTIFICATION_IMAGE_TYPE_ICON, real_path); if (status.IsError()) { return status; } @@ -1206,7 +1203,7 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args, common::FromJson(noti_obj, "subIconPath"); std::string real_path = common::FilesystemProvider::Create().GetRealPath(value_str); - status = SetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON_SUB, real_path); + status = SetImage(*noti_handle, NOTIFICATION_IMAGE_TYPE_ICON_SUB, real_path); if (status.IsError()) { return status; } @@ -1214,7 +1211,7 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args, if (val.contains("number") && !IsNull(noti_obj, "number")) { long number = (long)common::FromJson(noti_obj, "number"); - status = SetText(noti_handle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, std::to_string(number)); + status = SetText(*noti_handle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, std::to_string(number)); if (status.IsError()) { return status; } @@ -1222,28 +1219,28 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args, if (val.contains("detailInfo") && !IsNull(noti_obj, "detailInfo")) { status = SetDetailInfos( - noti_handle, common::FromJson(noti_obj, "detailInfo")); + *noti_handle, common::FromJson(noti_obj, "detailInfo")); if (status.IsError()) { return status; } } if (val.contains("ledColor") && !IsNull(noti_obj, "ledColor")) { - status = SetLedColor(noti_handle, + status = SetLedColor(*noti_handle, common::FromJson(noti_obj, "ledColor")); if (status.IsError()) { return status; } } - status = SetLedOnPeriod(noti_handle, + status = SetLedOnPeriod(*noti_handle, static_cast(common::FromJson( noti_obj, "ledOnPeriod"))); if (status.IsError()) { return status; } - status = SetLedOffPeriod(noti_handle, + status = SetLedOffPeriod(*noti_handle, static_cast(common::FromJson( noti_obj, "ledOffPeriod"))); if (status.IsError()) { @@ -1255,7 +1252,7 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args, const std::string& value_str = common::FromJson(noti_obj, "backgroundImagePath"); std::string real_path = common::FilesystemProvider::Create().GetRealPath(value_str); - status = SetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_BACKGROUND, real_path); + status = SetImage(*noti_handle, NOTIFICATION_IMAGE_TYPE_BACKGROUND, real_path); if (status.IsError()) { return status; } @@ -1263,7 +1260,7 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args, if (val.contains("thumbnails") && !IsNull(noti_obj, "thumbnails")) { status = SetThumbnails( - noti_handle, common::FromJson(noti_obj, "thumbnails")); + *noti_handle, common::FromJson(noti_obj, "thumbnails")); if (status.IsError()) { return status; } @@ -1273,14 +1270,14 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args, const std::string& value_str = common::FromJson(noti_obj, "soundPath"); std::string real_path = common::FilesystemProvider::Create().GetRealPath(value_str); - status = SetSoundPath(noti_handle, real_path); + status = SetSoundPath(*noti_handle, real_path); if (status.IsError()) { return status; } } status = - SetVibration(noti_handle, common::FromJson(noti_obj, "vibration")); + SetVibration(*noti_handle, common::FromJson(noti_obj, "vibration")); if (status.IsError()) { return status; } @@ -1309,14 +1306,14 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args, const std::string& progress_type = common::FromJson(noti_obj, "progressType"); - status = SetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_LIST_5, progress_type); + status = SetImage(*noti_handle, NOTIFICATION_IMAGE_TYPE_LIST_5, progress_type); if (status.IsError()) { return status; } if (val.contains("progressValue") && !IsNull(noti_obj, "progressValue")) { double progressValue = common::FromJson(noti_obj, "progressValue"); - status = SetProgressValue(noti_handle, progress_type, progressValue, + status = SetProgressValue(*noti_handle, progress_type, progressValue, is_update); if (status.IsError()) { @@ -1324,7 +1321,7 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args, } } - status = SetText(noti_handle, + status = SetText(*noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, common::FromJson(noti_obj, "title")); if (status.IsError()) { @@ -1332,7 +1329,7 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args, } if (val.contains("content") && !IsNull(noti_obj, "content")) { - status = SetText(noti_handle, + status = SetText(*noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, common::FromJson(noti_obj, "content")); if (status.IsError()) { @@ -1340,11 +1337,31 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args, } } - status = SetAppControl(noti_handle, app_control); + status = SetAppControl(*noti_handle, app_control); + + return PlatformResult(ErrorCode::NO_ERROR); +} + +PlatformResult StatusNotification::FromJson(const picojson::object& args, + bool is_update, + picojson::object* out_ptr) { + LoggerD("Enter"); + notification_h noti_handle = nullptr; + int ret; + int id = NOTIFICATION_PRIV_ID_NONE; + + SCOPE_EXIT { + notification_free(noti_handle); + }; + + PlatformResult status = GetNotiHandleFromJson(args, is_update, ¬i_handle); + + if (status.IsError()){ + return status; + } if (is_update) { ret = notification_update(noti_handle); - } else { ret = notification_insert(noti_handle, &id); if (NOTIFICATION_ERROR_NONE != ret) { diff --git a/src/notification/status_notification.h b/src/notification/status_notification.h index ae50e8d6..51aab91f 100644 --- a/src/notification/status_notification.h +++ b/src/notification/status_notification.h @@ -35,6 +35,9 @@ class StatusNotification { notification_h noti_handle, app_control_h app_handle, picojson::object* out_ptr); + static common::PlatformResult GetNotiHandleFromJson(const picojson::object& args, + bool is_update, + notification_h *noti_handle); static common::PlatformResult FromJson(const picojson::object& args, bool is_update, picojson::object* out_ptr);