[Notification] skeleton for FromJson and ToJson methods 48/138548/2
authorPiotr Kosko <p.kosko@samsung.com>
Thu, 6 Jul 2017 13:01:50 +0000 (15:01 +0200)
committerPiotr Kosko <p.kosko@samsung.com>
Fri, 28 Jul 2017 12:51:13 +0000 (14:51 +0200)
[Feature]
  - prepared *FromJson and ToJson methods
  - extracted common methods to remove code duplication

[Verification] Passrate didn't change

Change-Id: Idf6fa7f28bcd62af4b16c17906c85ee8fd3a4eb6
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
src/notification/common_notification.cc
src/notification/common_notification.h
src/notification/notification_manager.cc
src/notification/status_notification.cc
src/notification/user_notification.cc
src/notification/user_notification.h

index 233d424..3f9f4df 100644 (file)
@@ -95,10 +95,10 @@ PlatformResult CommonNotification::SetLayout(notification_h noti_handle,
     noti_layout = NOTIFICATION_LY_ONGOING_PROGRESS;
   }
   int ret = notification_set_layout(noti_handle, noti_layout);
-  if (ret != NOTIFICATION_ERROR_NONE) {
+  if (NOTIFICATION_ERROR_NONE != ret) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                          "Set notification layout error",
-                          ("Set notification layout error: %d", ret));
+                              "Set notification layout error",
+                              ("Set notification layout error: %d", ret));
   }
 
   return PlatformResult(ErrorCode::NO_ERROR);
@@ -120,7 +120,7 @@ static bool ServiceExtraDataCb(app_control_h service,
   SCOPE_EXIT { free(value); };
 
   int ret = app_control_get_extra_data_array(service, key, &value, &length);
-  if (ret != APP_CONTROL_ERROR_NONE) {
+  if (APP_CONTROL_ERROR_NONE != ret) {
     LoggerE("Get app control extra data error: %d", ret);
     return true;
   }
@@ -150,18 +150,18 @@ PlatformResult CommonNotification::Create(notification_type_e noti_type,
   *noti_handle = notification_create(noti_type);
   if (!*noti_handle) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                          "Cannot make new notification object");
+                              "Cannot make new notification object");
   }
 
   if (NOTIFICATION_TYPE_ONGOING == noti_type) {
     int ret = notification_set_display_applist(
         *noti_handle,
         NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY |
-            NOTIFICATION_DISPLAY_APP_INDICATOR);
-    if (ret != NOTIFICATION_ERROR_NONE) {
+        NOTIFICATION_DISPLAY_APP_INDICATOR);
+    if (NOTIFICATION_ERROR_NONE != ret) {
       return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                            "Cannot set notification display applist",
-                            ("Cannot make new notification object: %d", ret));
+                                "Cannot set notification display applist",
+                                ("Cannot make new notification object: %d", ret));
     }
   }
 
@@ -188,7 +188,7 @@ PlatformResult CommonNotification::StatusTypeFromPlatform(
     }
   } else {
     return LogAndCreateResult(ErrorCode::NOT_FOUND_ERR,
-                          "Notification type not found");
+                              "Notification type not found");
   }
 
   return PlatformResult(ErrorCode::NO_ERROR);
@@ -204,8 +204,8 @@ PlatformResult CommonNotification::StatusTypeToPlatform(
     *noti_type = NOTIFICATION_TYPE_ONGOING;
   } else {
     return LogAndCreateResult(ErrorCode::TYPE_MISMATCH_ERR,
-                          "Invalide notification type",
-                          ("Invalide noti type: %s", type.c_str()));
+                              "Invalide notification type",
+                              ("Invalide noti type: %s", type.c_str()));
   }
 
   return PlatformResult(ErrorCode::NO_ERROR);
@@ -220,11 +220,10 @@ PlatformResult CommonNotification::GetImage(
 
   *image_path = "";
 
-  if (notification_get_image(noti_handle, image_type, &path) !=
-      NOTIFICATION_ERROR_NONE) {
+  if (NOTIFICATION_ERROR_NONE != notification_get_image(noti_handle, image_type, &path)) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                          "Get notification image error",
-                          ("Get notification image error, image_type: %d", image_type));
+                              "Get notification image error",
+                              ("Get notification image error, image_type: %d", image_type));
   }
   if (path) {
     *image_path = path;
@@ -239,11 +238,11 @@ PlatformResult CommonNotification::SetImage(
     const std::string& image_path) {
   LoggerD("Enter");
   int ret = notification_set_image(noti_handle, image_type, image_path.c_str());
-  if (ret != NOTIFICATION_ERROR_NONE) {
+  if (NOTIFICATION_ERROR_NONE != ret) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                          "Set notification image error",
-                          ("Set notification image error, image_type: %d, error: %d",
-                                      image_type, ret));
+                              "Set notification image error",
+                              ("Set notification image error, image_type: %d, error: %d",
+                                  image_type, ret));
   }
 
   return PlatformResult(ErrorCode::NO_ERROR);
@@ -257,11 +256,10 @@ PlatformResult CommonNotification::GetText(notification_h noti_handle,
 
   *noti_text = "";
 
-  if (notification_get_text(noti_handle, text_type, &text) !=
-      NOTIFICATION_ERROR_NONE) {
+  if (NOTIFICATION_ERROR_NONE != notification_get_text(noti_handle, text_type, &text)) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                          "Get notification text error",
-                          ("Get notification text error, text_type: %d", text_type));
+                              "Get notification text error",
+                              ("Get notification text error, text_type: %d", text_type));
   }
 
   if (text)
@@ -279,11 +277,11 @@ PlatformResult CommonNotification::SetText(notification_h noti_handle,
                                   noti_text.c_str(),
                                   NULL,
                                   NOTIFICATION_VARIABLE_TYPE_NONE);
-  if (ret != NOTIFICATION_ERROR_NONE) {
+  if (NOTIFICATION_ERROR_NONE != ret) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                          "Set notification text error",
-                          ("Set notification text error, text_type: %d, error: %d",
-                                      text_type, ret));
+                              "Set notification text error",
+                              ("Set notification text error, text_type: %d, error: %d",
+                                  text_type, ret));
   }
 
   return PlatformResult(ErrorCode::NO_ERROR);
@@ -374,7 +372,7 @@ PlatformResult CommonNotification::SetDetailInfos(
 
     if (idx > info_map_size) {
       return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR,
-                            "Too many values in notification detailInfo array");
+                                "Too many values in notification detailInfo array");
     }
   }
 
@@ -387,10 +385,9 @@ PlatformResult CommonNotification::GetLedColor(notification_h noti_handle,
   unsigned int color = 0;
   notification_led_op_e type = NOTIFICATION_LED_OP_ON;
 
-  if (notification_get_led(noti_handle, &type, (int*)&color) !=
-      NOTIFICATION_ERROR_NONE) {
+  if (NOTIFICATION_ERROR_NONE != notification_get_led(noti_handle, &type, (int*)&color)) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                          "Get notification led displaying option error");
+                              "Get notification led displaying option error");
   }
 
   *led_color = "";
@@ -423,8 +420,8 @@ PlatformResult CommonNotification::SetLedColor(notification_h noti_handle,
 
   if (!IsColorFormatNumberic(color_str)) {
     return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR,
-                          "Led color is not numeric value",
-                          ("Led color is not numeric value: %s", color_str.c_str()));
+                              "Led color is not numeric value",
+                              ("Led color is not numeric value: %s", color_str.c_str()));
   }
 
   std::stringstream stream;
@@ -442,10 +439,10 @@ PlatformResult CommonNotification::SetLedColor(notification_h noti_handle,
     type = NOTIFICATION_LED_OP_OFF;
 
   int ret = notification_set_led(noti_handle, type, static_cast<int>(color));
-  if (ret != NOTIFICATION_ERROR_NONE) {
+  if (NOTIFICATION_ERROR_NONE != ret) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                          "Set notification led color eror",
-                          ("Set notification led color eror: %d", ret));
+                              "Set notification led color eror",
+                              ("Set notification led color eror: %d", ret));
   }
 
   return PlatformResult(ErrorCode::NO_ERROR);
@@ -458,10 +455,9 @@ PlatformResult CommonNotification::GetLedPeriod(notification_h noti_handle,
   int on_time = 0;
   int off_time = 0;
 
-  if (notification_get_led_time_period(noti_handle, &on_time, &off_time) !=
-      NOTIFICATION_ERROR_NONE) {
+  if (NOTIFICATION_ERROR_NONE != notification_get_led_time_period(noti_handle, &on_time, &off_time)) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                          "Get notification led on/off period error");
+                              "Get notification led on/off period error");
   }
 
   if (on_period)
@@ -482,10 +478,10 @@ PlatformResult CommonNotification::SetLedOnPeriod(notification_h noti_handle,
 
   int ret =
       notification_set_led_time_period(noti_handle, on_period, off_period);
-  if (ret != NOTIFICATION_ERROR_NONE) {
+  if (NOTIFICATION_ERROR_NONE != ret) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                          "Set notification led on period error",
-                          ("Set notification led on period error: %d", ret));
+                              "Set notification led on period error",
+                              ("Set notification led on period error: %d", ret));
   }
 
   return PlatformResult(ErrorCode::NO_ERROR);
@@ -501,10 +497,10 @@ PlatformResult CommonNotification::SetLedOffPeriod(notification_h noti_handle,
 
   int ret =
       notification_set_led_time_period(noti_handle, on_period, off_period);
-  if (ret != NOTIFICATION_ERROR_NONE) {
+  if (NOTIFICATION_ERROR_NONE != ret) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                          "Set notification led off period error",
-                          ("Set notification led off period error: %d", ret));
+                              "Set notification led off period error",
+                              ("Set notification led off period error: %d", ret));
   }
 
   return PlatformResult(ErrorCode::NO_ERROR);
@@ -550,7 +546,7 @@ PlatformResult CommonNotification::SetThumbnails(notification_h noti_handle,
 
     if (idx > thumbnails_map_size) {
       return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR,
-                            "Too many values in notification thumbnail array");
+                                "Too many values in notification thumbnail array");
     }
   }
 
@@ -565,10 +561,9 @@ PlatformResult CommonNotification::GetSoundPath(notification_h noti_handle,
   const char* path = NULL;
   notification_sound_type_e type = NOTIFICATION_SOUND_TYPE_NONE;
 
-  if (notification_get_sound(noti_handle, &type, &path) !=
-      NOTIFICATION_ERROR_NONE) {
+  if (NOTIFICATION_ERROR_NONE != notification_get_sound(noti_handle, &type, &path)) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                          "Get notification sound error");
+                              "Get notification sound error");
   }
 
   LoggerD("Sound type = %d", type);
@@ -587,10 +582,10 @@ PlatformResult CommonNotification::SetSoundPath(notification_h noti_handle,
   LoggerD("Enter");
   int ret = notification_set_sound(
       noti_handle, NOTIFICATION_SOUND_TYPE_USER_DATA, sound_path.c_str());
-  if (ret != NOTIFICATION_ERROR_NONE) {
+  if (NOTIFICATION_ERROR_NONE != ret) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                          "Set notification sound error",
-                          ("Set notification sound error: %d", ret));
+                              "Set notification sound error",
+                              ("Set notification sound error: %d", ret));
   }
 
   LoggerD("Sound path = %s", sound_path.c_str());
@@ -603,10 +598,9 @@ PlatformResult CommonNotification::GetVibration(notification_h noti_handle,
   LoggerD("Enter");
   notification_vibration_type_e vib_type = NOTIFICATION_VIBRATION_TYPE_NONE;
 
-  if (notification_get_vibration(noti_handle, &vib_type, NULL) !=
-      NOTIFICATION_ERROR_NONE) {
+  if (NOTIFICATION_ERROR_NONE != notification_get_vibration(noti_handle, &vib_type, NULL)) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                          "Get notification vibration error");
+                              "Get notification vibration error");
   }
 
   if (NOTIFICATION_VIBRATION_TYPE_DEFAULT == vib_type ||
@@ -635,10 +629,10 @@ PlatformResult CommonNotification::SetVibration(notification_h noti_handle,
     }
 
     int ret = notification_set_vibration(noti_handle, vib_type, NULL);
-    if (ret != NOTIFICATION_ERROR_NONE) {
+    if (NOTIFICATION_ERROR_NONE != ret) {
       return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                            "Set notification vibration error",
-                            ("Set notification vibration error: %d", ret));
+                                "Set notification vibration error",
+                                ("Set notification vibration error: %d", ret));
     }
   }
 
@@ -663,10 +657,10 @@ PlatformResult CommonNotification::GetApplicationControl(
   };
 
   int ret = app_control_get_operation(app_handle, &operation);
-  if (ret != APP_CONTROL_ERROR_NONE) {
+  if (APP_CONTROL_ERROR_NONE != ret) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                          "Get application control operation error",
-                          ("Get application control operation error: %d", ret));
+                              "Get application control operation error",
+                              ("Get application control operation error: %d", ret));
   }
   if (operation) {
     out["operation"] = picojson::value(operation);
@@ -675,7 +669,7 @@ PlatformResult CommonNotification::GetApplicationControl(
 
   if (app_control_get_uri(app_handle, &uri) != APP_CONTROL_ERROR_NONE) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                          "Get application control uri error");
+                              "Get application control uri error");
   }
   if (uri) {
     out["uri"] = picojson::value(uri);
@@ -684,7 +678,7 @@ PlatformResult CommonNotification::GetApplicationControl(
 
   if (app_control_get_mime(app_handle, &mime) != APP_CONTROL_ERROR_NONE) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                          "Get application control mime error");
+                              "Get application control mime error");
   }
   if (mime) {
     out["mime"] = picojson::value(mime);
@@ -694,7 +688,7 @@ PlatformResult CommonNotification::GetApplicationControl(
   if (app_control_get_category(app_handle, &category) !=
       APP_CONTROL_ERROR_NONE) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                          "Get application control category error");
+                              "Get application control category error");
   }
   if (category) {
     out["category"] = picojson::value(category);
@@ -703,10 +697,10 @@ PlatformResult CommonNotification::GetApplicationControl(
 
   picojson::array app_control_data = picojson::array();
   if (app_control_foreach_extra_data(
-          app_handle, ServiceExtraDataCb, (void*)&app_control_data) !=
-      APP_CONTROL_ERROR_NONE) {
+      app_handle, ServiceExtraDataCb, (void*)&app_control_data) !=
+          APP_CONTROL_ERROR_NONE) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                          "Get application control data error");
+                              "Get application control data error");
   }
   out["data"] = picojson::value(app_control_data);
 
@@ -727,29 +721,29 @@ PlatformResult CommonNotification::SetApplicationControl(
   } else {
     ret = app_control_set_operation(app_handle, APP_CONTROL_OPERATION_DEFAULT);
   }
-  if (ret != APP_CONTROL_ERROR_NONE) {
+  if (APP_CONTROL_ERROR_NONE != ret) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                          "Set application control operation error",
-                          ("Set application control operation error: %d", ret));
+                              "Set application control operation error",
+                              ("Set application control operation error: %d", ret));
   }
 
   if (val.contains("uri") && !IsNull(app_ctrl, "uri")) {
     const std::string& uri = common::FromJson<std::string>(app_ctrl, "uri");
     ret = app_control_set_uri(app_handle, uri.c_str());
-    if (ret != APP_CONTROL_ERROR_NONE) {
+    if (APP_CONTROL_ERROR_NONE != ret) {
       return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                            "Set application control uri error",
-                            ("Set application control uri error: %d", ret));
+                                "Set application control uri error",
+                                ("Set application control uri error: %d", ret));
     }
   }
 
   if (val.contains("mime") && !IsNull(app_ctrl, "mime")) {
     const std::string& mime = common::FromJson<std::string>(app_ctrl, "mime");
     ret = app_control_set_mime(app_handle, mime.c_str());
-    if (ret != APP_CONTROL_ERROR_NONE) {
+    if (APP_CONTROL_ERROR_NONE != ret) {
       return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                            "Set application control mime error",
-                            ("Set application control mime error: %d", ret));
+                                "Set application control mime error",
+                                ("Set application control mime error: %d", ret));
     }
   }
 
@@ -757,10 +751,10 @@ PlatformResult CommonNotification::SetApplicationControl(
     const std::string& category =
         common::FromJson<std::string>(app_ctrl, "category");
     ret = app_control_set_category(app_handle, category.c_str());
-    if (ret != APP_CONTROL_ERROR_NONE) {
+    if (APP_CONTROL_ERROR_NONE != ret) {
       return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                            "Set application control category error",
-                            ("Set application control category error: %d", ret));
+                                "Set application control category error",
+                                ("Set application control category error: %d", ret));
     }
   }
 
@@ -787,10 +781,10 @@ PlatformResult CommonNotification::SetApplicationControl(
     }
     ret = app_control_add_extra_data_array(
         app_handle, key.c_str(), arrayValue, values.size());
-    if (ret != APP_CONTROL_ERROR_NONE) {
+    if (APP_CONTROL_ERROR_NONE != ret) {
       return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                            "Set application control extra data error",
-                            ("Set application control extra data error: %d", ret));
+                                "Set application control extra data error",
+                                ("Set application control extra data error: %d", ret));
     }
   }
 
@@ -823,7 +817,7 @@ PlatformResult CommonNotification::SetApplicationId(app_control_h app_handle,
                                                     const std::string& app_id) {
   LoggerD("Enter");
   int ret = app_control_set_app_id(app_handle, app_id.c_str());
-  if (ret != APP_CONTROL_ERROR_NONE) {
+  if (APP_CONTROL_ERROR_NONE != ret) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Set applicaiton ID error",
                               ("Set applicaiton ID error: %d", ret));
   }
@@ -841,23 +835,21 @@ PlatformResult CommonNotification::GetProgressValue(
   double tmp_progress_value = 0.0;
 
   if (progess_type == kProgressTypeByte) {
-    if (notification_get_size(noti_handle, &tmp_progress_value) !=
-        NOTIFICATION_ERROR_NONE) {
+    if (NOTIFICATION_ERROR_NONE != notification_get_size(noti_handle, &tmp_progress_value)) {
       return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                            "Get notification size error");
+                                "Get notification size error");
     }
   } else if (progess_type == kProgressTypePercentage) {
-    if (notification_get_progress(noti_handle, &tmp_progress_value) !=
-        NOTIFICATION_ERROR_NONE) {
+    if (NOTIFICATION_ERROR_NONE != notification_get_progress(noti_handle, &tmp_progress_value)) {
       return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                            "Get notification progress error");
+                                "Get notification progress error");
     }
     // native api uses range 0-1, but webapi expects 0-100, so we need to multiply result with 100
     tmp_progress_value *= 100;
   } else {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                          "Unknown notification progress type",
-                          ("Unknown notification progress type: %s ", progess_type.c_str()));
+                              "Unknown notification progress type",
+                              ("Unknown notification progress type: %s ", progess_type.c_str()));
   }
 
   LOGGER(DEBUG) << "Progress " << progess_type << " = " << tmp_progress_value;
@@ -879,7 +871,7 @@ PlatformResult CommonNotification::SetProgressValue(
 
     if (is_update) {
       ret = notification_update_size(noti_handle, NOTIFICATION_PRIV_ID_NONE,
-          progress_value);
+                                     progress_value);
     }
   } else if (progress_type == kProgressTypePercentage) {
     // native api uses range 0-1, but webapi expects 0-100, so we need to divide by 100
@@ -887,18 +879,18 @@ PlatformResult CommonNotification::SetProgressValue(
 
     if (is_update) {
       ret = notification_update_progress(noti_handle, NOTIFICATION_PRIV_ID_NONE,
-          progress_value);
+                                         progress_value);
     }
   } else {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                          "Unknown notification progress type",
-                          ("Unknown notification progress type: %s ", progress_type.c_str()));
+                              "Unknown notification progress type",
+                              ("Unknown notification progress type: %s ", progress_type.c_str()));
   }
 
-  if (ret != NOTIFICATION_ERROR_NONE) {
+  if (NOTIFICATION_ERROR_NONE != ret) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                          "Set notification progress/size error",
-                          ("Set notification progress/size error: %d", ret));
+                              "Set notification progress/size error",
+                              ("Set notification progress/size error: %d", ret));
   }
 
   return PlatformResult(ErrorCode::NO_ERROR);
@@ -909,10 +901,9 @@ PlatformResult CommonNotification::GetPostedTime(notification_h noti_handle,
   LoggerD("Enter");
   *posted_time = 0;
 
-  if (notification_get_insert_time(noti_handle, posted_time) !=
-      NOTIFICATION_ERROR_NONE) {
+  if (NOTIFICATION_ERROR_NONE != notification_get_insert_time(noti_handle, posted_time)) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                          "Get notification posted time error");
+                              "Get notification posted time error");
   }
 
   return PlatformResult(ErrorCode::NO_ERROR);
@@ -924,7 +915,7 @@ PlatformResult CommonNotification::GetNotiHandle(int id,
   *noti_handle = notification_load(NULL, id);
   if (NULL == *noti_handle) {
     return LogAndCreateResult(ErrorCode::NOT_FOUND_ERR,
-                          "Not found or removed notification id");
+                              "Not found or removed notification id");
   }
 
   return PlatformResult(ErrorCode::NO_ERROR);
@@ -937,10 +928,10 @@ PlatformResult CommonNotification::GetAppControl(notification_h noti_handle,
       notification_get_launch_option(noti_handle,
                                      NOTIFICATION_LAUNCH_OPTION_APP_CONTROL,
                                      static_cast<void*>(app_control));
-  if (ret != NOTIFICATION_ERROR_NONE) {
+  if (NOTIFICATION_ERROR_NONE != ret) {
     return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR,
-                          "Notification get launch option error",
-                          ("Notification get launch option error: %d", ret));
+                              "Notification get launch option error",
+                              ("Notification get launch option error: %d", ret));
   }
 
   return PlatformResult(ErrorCode::NO_ERROR);
@@ -950,10 +941,10 @@ PlatformResult CommonNotification::CreateAppControl(
     app_control_h* app_control) {
   LoggerD("Enter");
   int ret = app_control_create(app_control);
-  if (ret != APP_CONTROL_ERROR_NONE) {
+  if (APP_CONTROL_ERROR_NONE != ret) {
     return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR,
-                          "Application create error",
-                          ("Application create error: %d", ret));
+                              "Application create error",
+                              ("Application create error: %d", ret));
   }
 
   return PlatformResult(ErrorCode::NO_ERROR);
@@ -966,10 +957,10 @@ PlatformResult CommonNotification::SetAppControl(notification_h noti_handle,
       notification_set_launch_option(noti_handle,
                                      NOTIFICATION_LAUNCH_OPTION_APP_CONTROL,
                                      static_cast<void*>(app_control));
-  if (ret != APP_CONTROL_ERROR_NONE) {
+  if (APP_CONTROL_ERROR_NONE != ret) {
     return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR,
-                          "Notification set launch option error",
-                          ("Notification set launch option error: %d", ret));
+                              "Notification set launch option error",
+                              ("Notification set launch option error: %d", ret));
   }
 
   return PlatformResult(ErrorCode::NO_ERROR);
@@ -993,9 +984,9 @@ common::PlatformResult CommonNotification::UpdateNotificationAfterPost(
 }
 
 PlatformResult CommonNotification::PostNotification(const picojson::object& args,
-                                            bool is_update,
-                                            picojson::object* out_ptr,
-                                            GetHandleFromJsonFun getHandle) {
+                                                    bool is_update,
+                                                    picojson::object* out_ptr,
+                                                    GetHandleFromJsonFun getHandle) {
   LoggerD("Enter");
   notification_h noti_handle = nullptr;
   int ret = NOTIFICATION_ERROR_NONE;
@@ -1007,7 +998,7 @@ PlatformResult CommonNotification::PostNotification(const picojson::object& args
 
   PlatformResult status = getHandle(args, is_update, &noti_handle);
 
-  if (status.IsError()){
+  if (status.IsError()) {
     return status;
   }
 
@@ -1032,5 +1023,113 @@ PlatformResult CommonNotification::PostNotification(const picojson::object& args
 }
 
 
+PlatformResult CommonNotification::AddCommonMembersToJson(int id, notification_h noti_handle,
+                                                          picojson::object* out_ptr) {
+  LoggerD("Enter");
+  picojson::object& out = *out_ptr;
+
+  out["id"] = picojson::value(std::to_string(id));
+  out["type"] = picojson::value("STATUS");
+
+  time_t posted_time = 0;
+  PlatformResult ret = GetPostedTime(noti_handle, &posted_time);
+  CHECK_ERROR(ret);
+  out["postedTime"] =
+      picojson::value(static_cast<double>(posted_time) * 1000.0);
+
+  std::string value_str;
+  ret = GetText(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, &value_str);
+  CHECK_ERROR(ret);
+  out["title"] = picojson::value(value_str);
+
+  ret = GetText(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, &value_str);
+  CHECK_ERROR(ret);
+  if (value_str.length()) {
+    out["content"] = picojson::value(value_str);
+  }
+
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult CommonNotification::AddTypeToJson(notification_h noti_handle, const std::string& key,
+                                                 picojson::object* out_ptr, std::string* noti_type_str) {
+  LoggerD("Enter");
+  picojson::object& out = *out_ptr;
+  // Notification type
+  notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
+  int ret = notification_get_type(noti_handle, &noti_type);
+  if (NOTIFICATION_ERROR_NONE != ret) {
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+                              "Notification get type error",
+                              ("Notification get type error: %d", ret));
+  }
+
+  notification_ly_type_e noti_layout = NOTIFICATION_LY_NONE;
+  ret = notification_get_layout(noti_handle, &noti_layout);
+  if (NOTIFICATION_ERROR_NONE != ret) {
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+                              "Notification get layout error",
+                              ("Notification get layout error: %d", ret));
+  }
+
+  PlatformResult status = StatusTypeFromPlatform(noti_type, noti_layout, noti_type_str);
+  CHECK_ERROR(status);
+  out[key] = picojson::value(*noti_type_str);
+
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult CommonNotification::InitNotiFromJson(const picojson::object& noti_obj,
+                                                    bool is_update,
+                                                    notification_h* noti_handle) {
+  LoggerD("Enter");
+  notification_h tmp_noti = nullptr;
+
+  const std::string& status_type =
+      common::FromJson<std::string>(noti_obj, "statusType");
+
+  notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
+  PlatformResult status = StatusTypeToPlatform(status_type, &noti_type);
+  CHECK_ERROR(status);
+
+  if (is_update) {
+    int id = std::stoi(common::FromJson<std::string>(noti_obj, "id"));
+
+    status = GetNotiHandle(id, &tmp_noti);
+    CHECK_ERROR(status);
+  } else {
+    status = Create(noti_type, &tmp_noti);
+    CHECK_ERROR(status);
+  }
+  std::unique_ptr<std::remove_pointer<notification_h>::type, int(*)(notification_h)>
+  tmp_noti_ptr(tmp_noti, &notification_free); // automatically release the memory
+
+  status = SetLayout(tmp_noti, status_type);
+  CHECK_ERROR(status);
+
+  *noti_handle = tmp_noti_ptr.release();
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+
+PlatformResult CommonNotification::SetCommonMembersFromJson(const picojson::value& noti_value,
+                                                            notification_h noti_handle) {
+  LoggerD("Enter");
+  const picojson::object& noti_obj = noti_value.get<picojson::object>();
+  PlatformResult status = SetText(noti_handle,
+                                  NOTIFICATION_TEXT_TYPE_TITLE,
+                                  common::FromJson<std::string>(noti_obj, "title"));
+  CHECK_ERROR(status);
+
+  if (noti_value.contains("content") && !IsNull(noti_obj, "content")) {
+    status = SetText(noti_handle,
+                     NOTIFICATION_TEXT_TYPE_CONTENT,
+                     common::FromJson<std::string>(noti_obj, "content"));
+    CHECK_ERROR(status);
+  }
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+
 }  // namespace notification
 }  // namespace extension
index 69b7101..86fa4bc 100644 (file)
 namespace extension {
 namespace notification {
 
+#define CHECK_ERROR(ret) \
+    if (ret.IsError()) { \
+      return ret; \
+    }
+
 const std::string kProgressTypePercentage = "PERCENTAGE";
 const std::string kProgressTypeByte = "BYTE";
 
@@ -42,11 +47,11 @@ typedef std::function<common::PlatformResult(const picojson::object& args,
 class CommonNotification {
  public:
   XW_EXPORT static common::PlatformResult GetAppControl(notification_h noti_handle,
-                                              app_control_h* app_control);
+                                                        app_control_h* app_control);
   static common::PlatformResult GetNotiHandle(int id,
                                               notification_h* noti_handle);
   XW_EXPORT static common::PlatformResult SetAppControl(notification_h noti_handle,
-                                              app_control_h app_control);
+                                                        app_control_h app_control);
 
   static const InformationEnumMap info_map_;
   static const InformationEnumMap info_sub_map_;
@@ -130,12 +135,25 @@ class CommonNotification {
 
   static bool IsColorFormatNumberic(const std::string& color);
   static common::PlatformResult UpdateNotificationAfterPost(notification_h noti_handle, int id,
-                                                    picojson::object* out_ptr);
+                                                            picojson::object* out_ptr);
+
+  // ToJson section
+  static common::PlatformResult AddCommonMembersToJson(int id, notification_h noti_handle,
+                                                       picojson::object* out_ptr);
+  static common::PlatformResult AddTypeToJson(notification_h noti_handle, const std::string& key,
+                                              picojson::object* out_ptr, std::string* noti_type_str);
+
+  // FromJson section
+  static common::PlatformResult InitNotiFromJson(const picojson::object& args, bool is_update,
+                                                 notification_h* noti_handle);
+  static common::PlatformResult SetCommonMembersFromJson(const picojson::value& noti_val,
+                                                         notification_h noti_handle);
+
+
   static common::PlatformResult PostNotification(const picojson::object& args,
                                                  bool is_update,
                                                  picojson::object* out_ptr,
                                                  GetHandleFromJsonFun getHandle);
-
  protected:
   CommonNotification();
   virtual ~CommonNotification();
index 81e7b00..121117e 100644 (file)
@@ -86,7 +86,7 @@ PlatformResult NotificationManager::Remove(const picojson::object& args) {
   int id = std::stoi(FromJson<std::string>(args, "id"));
 
   int ret = notification_delete_by_priv_id(NULL, NOTIFICATION_TYPE_NONE, id);
-  if (ret != NOTIFICATION_ERROR_NONE) {
+  if (NOTIFICATION_ERROR_NONE != ret) {
     return LogAndCreateResult(ErrorCode::NOT_FOUND_ERR,
                           "Cannot remove notification error",
                           ("Cannot remove notification error: %d", ret));
@@ -98,14 +98,14 @@ PlatformResult NotificationManager::Remove(const picojson::object& args) {
 PlatformResult NotificationManager::RemoveAll() {
   LoggerD("Enter");
   int ret = notification_delete_all(NOTIFICATION_TYPE_NOTI);
-  if (ret != NOTIFICATION_ERROR_NONE) {
+  if (NOTIFICATION_ERROR_NONE != ret) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
                           "Notification noti remove all failed",
                           ("Notification remove all failed: %d", ret));
   }
 
   ret = notification_delete_all(NOTIFICATION_TYPE_ONGOING);
-  if (ret != NOTIFICATION_ERROR_NONE) {
+  if (NOTIFICATION_ERROR_NONE != ret) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
                           "Notification ongoing remove all failed",
                           ("Notification remove all failed: %d", ret));
@@ -255,7 +255,7 @@ PlatformResult NotificationManager::PlayLEDCustomEffect(
 
   int ret;
   ret = device_led_play_custom(timeOn, timeOff, color, platformFlags);
-  if (ret != DEVICE_ERROR_NONE) {
+  if (DEVICE_ERROR_NONE != ret) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Cannot play LED custom effect",
                               ("Cannot play LED custom effect: ",ret));
   }
@@ -267,7 +267,7 @@ PlatformResult NotificationManager::StopLEDCustomEffect() {
   LoggerD("Enter");
 
   int ret = device_led_stop_custom();
-  if (ret != DEVICE_ERROR_NONE) {
+  if (DEVICE_ERROR_NONE != ret) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Cannot stop LED custom effect",
                               ("Cannot stop LED custom effect: ",ret));
   }
@@ -287,12 +287,12 @@ common::PlatformResult NotificationManager::SaveTemplate(const picojson::object&
   // TODO use UserNotification method
   PlatformResult status = StatusNotification::GetNotiHandleFromJson(args, false, &noti_handle);
 
-  if (status.IsError()){
+  if (status.IsError()) {
     return status;
   }
 
   ret = notification_save_as_template(noti_handle, name.c_str());
-  if (ret != NOTIFICATION_ERROR_NONE) {
+  if (NOTIFICATION_ERROR_NONE != ret) {
     LoggerD("Error: %d (%s)", ret, get_error_message(ret));
     if (ret == NOTIFICATION_ERROR_MAX_EXCEEDED) {
       return LogAndCreateResult(ErrorCode::QUOTA_EXCEEDED_ERR,
index 7b1d0e2..b87b4d4 100644 (file)
@@ -39,35 +39,13 @@ PlatformResult StatusNotification::ToJson(int id,
   LoggerD("Enter");
   picojson::object& out = *out_ptr;
 
-  out["id"] = picojson::value(std::to_string(id));
-  out["type"] = picojson::value("STATUS");
-
-  // Nitification type
-  notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
-  int ret = notification_get_type(noti_handle, &noti_type);
-  if (ret != NOTIFICATION_ERROR_NONE) {
-    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                              "Notification get type error",
-                              ("Notification get type error: %d", ret));
-  }
-
-  notification_ly_type_e noti_layout = NOTIFICATION_LY_NONE;
-  ret = notification_get_layout(noti_handle, &noti_layout);
-  if (ret != NOTIFICATION_ERROR_NONE) {
-    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                              "Notification get layout error",
-                              ("Notification get layout error: %d", ret));
-  }
+  CHECK_ERROR(AddCommonMembersToJson(id, noti_handle, out_ptr));
 
   std::string noti_type_str;
-  PlatformResult status =
-      StatusTypeFromPlatform(noti_type, noti_layout, &noti_type_str);
-  if (status.IsError())
-    return status;
-  out["statusType"] = picojson::value(noti_type_str);
+  CHECK_ERROR(AddTypeToJson(noti_handle, "statusType", out_ptr, &noti_type_str));
 
   std::string value_str;
-  status = GetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON, &value_str);
+  PlatformResult status = GetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON, &value_str);
   if (status.IsError())
     return status;
   if (value_str.length()) {
@@ -178,44 +156,16 @@ PlatformResult StatusNotification::ToJson(int id,
     return status;
   out["progressValue"] = picojson::value(progress_value);
 
-  time_t posted_time;
-  status = GetPostedTime(noti_handle, &posted_time);
-  if (status.IsError())
-    return status;
-  out["postedTime"] =
-      picojson::value(static_cast<double>(posted_time) * 1000.0);
-
-  status = GetText(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, &value_str);
-  if (status.IsError())
-    return status;
-  out["title"] = picojson::value(value_str);
-
-  status = GetText(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, &value_str);
-  if (status.IsError())
-    return status;
-  if (value_str.length()) {
-    out["content"] = picojson::value(value_str);
-  }
-
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
 PlatformResult StatusNotification::GetNotiHandleFromJson(const picojson::object& args,
                                                          bool is_update,
-                                                         notification_h *noti_handle){
+                                                         notification_h *noti_handle) {
   LoggerD("Enter");
   picojson::object noti_obj =
       common::FromJson<picojson::object>(args, "notification");
-
-  const std::string& status_type =
-      common::FromJson<std::string>(noti_obj, "statusType");
-
-  notification_type_e noti_type;
-  PlatformResult status = StatusTypeToPlatform(status_type, &noti_type);
-  if (status.IsError())
-    return status;
-
-  int id = NOTIFICATION_PRIV_ID_NONE;
+  picojson::value noti_val(noti_obj);
 
   app_control_h app_control = nullptr;
 
@@ -225,114 +175,105 @@ PlatformResult StatusNotification::GetNotiHandleFromJson(const picojson::object&
     }
   };
 
-  if (is_update) {
-    id = std::stoi(common::FromJson<std::string>(noti_obj, "id"));
+  notification_h tmp_noti = nullptr;
+  PlatformResult status = InitNotiFromJson(noti_obj, is_update, &tmp_noti);
+  CHECK_ERROR(status);
+  std::unique_ptr<std::remove_pointer<notification_h>::type, int(*)(notification_h)>
+      tmp_noti_ptr(tmp_noti, &notification_free); // automatically release the memory
 
-    PlatformResult status = GetNotiHandle(id, noti_handle);
-    if (status.IsError())
-      return status;
+  status = SetCommonMembersFromJson(noti_val, tmp_noti);
+  CHECK_ERROR(status);
 
-  } else {
-    status = Create(noti_type, noti_handle);
-    if (status.IsError())
-      return status;
-  }
 
-  status = SetLayout(*noti_handle, status_type);
-  if (status.IsError()) {
-    return status;
-  }
-
-  picojson::value val(noti_obj);
-  if (val.contains("iconPath") && !IsNull(noti_obj, "iconPath")) {
+  if (noti_val.contains("iconPath") && !IsNull(noti_obj, "iconPath")) {
     const std::string& value_str = common::FromJson<std::string>(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(tmp_noti, NOTIFICATION_IMAGE_TYPE_ICON, real_path);
     if (status.IsError()) {
       return status;
     }
   }
 
-  if (val.contains("subIconPath") && !IsNull(noti_obj, "subIconPath")) {
+  if (noti_val.contains("subIconPath") && !IsNull(noti_obj, "subIconPath")) {
     const std::string& value_str =
         common::FromJson<std::string>(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(tmp_noti, NOTIFICATION_IMAGE_TYPE_ICON_SUB, real_path);
     if (status.IsError()) {
       return status;
     }
   }
 
-  if (val.contains("number") && !IsNull(noti_obj, "number")) {
+  if (noti_val.contains("number") && !IsNull(noti_obj, "number")) {
     long number = (long)common::FromJson<double>(noti_obj, "number");
-    status = SetText(*noti_handle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, std::to_string(number));
+    status = SetText(tmp_noti, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, std::to_string(number));
     if (status.IsError()) {
       return status;
     }
   }
 
-  if (val.contains("detailInfo") && !IsNull(noti_obj, "detailInfo")) {
+  if (noti_val.contains("detailInfo") && !IsNull(noti_obj, "detailInfo")) {
     status = SetDetailInfos(
-        *noti_handle, common::FromJson<picojson::array>(noti_obj, "detailInfo"));
+        tmp_noti, common::FromJson<picojson::array>(noti_obj, "detailInfo"));
     if (status.IsError()) {
       return status;
     }
   }
 
-  if (val.contains("ledColor") && !IsNull(noti_obj, "ledColor")) {
-    status = SetLedColor(*noti_handle,
+  if (noti_val.contains("ledColor") && !IsNull(noti_obj, "ledColor")) {
+    status = SetLedColor(tmp_noti,
                          common::FromJson<std::string>(noti_obj, "ledColor"));
     if (status.IsError()) {
       return status;
     }
   }
 
-  status = SetLedOnPeriod(*noti_handle,
+  status = SetLedOnPeriod(tmp_noti,
                           static_cast<unsigned long>(common::FromJson<double>(
                               noti_obj, "ledOnPeriod")));
   if (status.IsError()) {
     return status;
   }
 
-  status = SetLedOffPeriod(*noti_handle,
+  status = SetLedOffPeriod(tmp_noti,
                            static_cast<unsigned long>(common::FromJson<double>(
                                noti_obj, "ledOffPeriod")));
   if (status.IsError()) {
     return status;
   }
 
-  if (val.contains("backgroundImagePath")
+  if (noti_val.contains("backgroundImagePath")
       && !IsNull(noti_obj, "backgroundImagePath")) {
     const std::string& value_str = common::FromJson<std::string>(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(tmp_noti, NOTIFICATION_IMAGE_TYPE_BACKGROUND, real_path);
     if (status.IsError()) {
       return status;
     }
   }
 
-  if (val.contains("thumbnails") && !IsNull(noti_obj, "thumbnails")) {
+  if (noti_val.contains("thumbnails") && !IsNull(noti_obj, "thumbnails")) {
     status = SetThumbnails(
-        *noti_handle, common::FromJson<picojson::array>(noti_obj, "thumbnails"));
+        tmp_noti, common::FromJson<picojson::array>(noti_obj, "thumbnails"));
     if (status.IsError()) {
       return status;
     }
   }
 
-  if (val.contains("soundPath") && !IsNull(noti_obj, "soundPath")) {
+  if (noti_val.contains("soundPath") && !IsNull(noti_obj, "soundPath")) {
     const std::string& value_str = common::FromJson<std::string>(noti_obj, "soundPath");
     std::string real_path = common::FilesystemProvider::Create().GetRealPath(value_str);
 
-    status = SetSoundPath(*noti_handle, real_path);
+    status = SetSoundPath(tmp_noti, real_path);
     if (status.IsError()) {
       return status;
     }
   }
 
-  status = SetVibration(*noti_handle, common::FromJson<bool>(noti_obj, "vibration"));
+  status = SetVibration(tmp_noti, common::FromJson<bool>(noti_obj, "vibration"));
   if (status.IsError()) {
     return status;
   }
@@ -342,7 +283,7 @@ PlatformResult StatusNotification::GetNotiHandleFromJson(const picojson::object&
     return status;
   }
 
-  if (val.contains("appControl") && !IsNull(noti_obj, "appControl")) {
+  if (noti_val.contains("appControl") && !IsNull(noti_obj, "appControl")) {
     status = SetApplicationControl(
         app_control,
         common::FromJson<picojson::object>(noti_obj, "appControl"));
@@ -351,7 +292,7 @@ PlatformResult StatusNotification::GetNotiHandleFromJson(const picojson::object&
     }
   }
 
-  if (val.contains("appId") && !IsNull(noti_obj, "appId")) {
+  if (noti_val.contains("appId") && !IsNull(noti_obj, "appId")) {
     status = SetApplicationId(app_control,
                               common::FromJson<std::string>(noti_obj, "appId"));
     if (status.IsError()) {
@@ -361,43 +302,30 @@ PlatformResult StatusNotification::GetNotiHandleFromJson(const picojson::object&
 
   const std::string& progress_type =
       common::FromJson<std::string>(noti_obj, "progressType");
-  status = SetImage(*noti_handle, NOTIFICATION_IMAGE_TYPE_LIST_5, progress_type);
+  status = SetImage(tmp_noti, NOTIFICATION_IMAGE_TYPE_LIST_5, progress_type);
   if (status.IsError()) {
     return status;
   }
 
   double progressValue;
-  if (val.contains("progressValue") && !IsNull(noti_obj, "progressValue")) {
+  if (noti_val.contains("progressValue") && !IsNull(noti_obj, "progressValue")) {
     progressValue = common::FromJson<double>(noti_obj, "progressValue");
   }
   else {
     progressValue = -1;
   }
 
-  status = SetProgressValue(*noti_handle, progress_type, progressValue,
+  status = SetProgressValue(tmp_noti, progress_type, progressValue,
                             is_update);
 
   if (status.IsError()) {
     return status;
   }
 
-  status = SetText(*noti_handle,
-                   NOTIFICATION_TEXT_TYPE_TITLE,
-                   common::FromJson<std::string>(noti_obj, "title"));
-  if (status.IsError()) {
-    return status;
-  }
-
-  if (val.contains("content") && !IsNull(noti_obj, "content")) {
-    status = SetText(*noti_handle,
-                     NOTIFICATION_TEXT_TYPE_CONTENT,
-                     common::FromJson<std::string>(noti_obj, "content"));
-    if (status.IsError()) {
-      return status;
-    }
-  }
+  status = SetAppControl(tmp_noti, app_control);
+  CHECK_ERROR(status);
 
-  status = SetAppControl(*noti_handle, app_control);
+  *noti_handle = tmp_noti_ptr.release();
 
   return PlatformResult(ErrorCode::NO_ERROR);
 }
index 0d5cacd..147aa69 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "notification/user_notification.h"
 
+#include "common/converter.h"
 #include "common/logger.h"
 #include "common/scope_exit.h"
 
@@ -35,27 +36,206 @@ PlatformResult UserNotification::ToJson(int id,
                                         app_control_h app_handle,
                                         picojson::object* out_ptr) {
   LoggerD("Enter");
+  PlatformResult ret = AddCommonMembersToJson(id, noti_handle, out_ptr);
+  CHECK_ERROR(ret);
+
+  std::string noti_type_str;
+  ret = AddTypeToJson(noti_handle, "userType", out_ptr, &noti_type_str);
+  CHECK_ERROR(ret);
+
+  ret = AddTextContentsToJson(noti_handle, out_ptr);
+  CHECK_ERROR(ret);
+
+  ret = AddImagesToJson(noti_handle, out_ptr);
+  CHECK_ERROR(ret);
+
+  ret = AddThumbnailsToJson(noti_handle, out_ptr);
+  CHECK_ERROR(ret);
+
+  ret = AddActionsToJson(noti_handle, out_ptr);
+  CHECK_ERROR(ret);
+
+  ret = AddGroupContentsToJson(noti_handle, out_ptr);
+  CHECK_ERROR(ret);
+
+  ret = AddLedsToJson(noti_handle, out_ptr);
+  CHECK_ERROR(ret);
+
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult UserNotification::GetNotiHandleFromJson(const picojson::object& args,
+                                                       bool is_update,
+                                                       notification_h *noti_handle) {
+  LoggerD("Enter");
+  picojson::object noti_obj =
+      common::FromJson<picojson::object>(args, "notification");
+  picojson::value noti_val(noti_obj);
+
+  notification_h tmp_noti = nullptr;
+  PlatformResult status = InitNotiFromJson(noti_obj, is_update, &tmp_noti);
+  CHECK_ERROR(status);
+  std::unique_ptr<std::remove_pointer<notification_h>::type, int(*)(notification_h)>
+  tmp_noti_ptr(tmp_noti, &notification_free); // automatically release the memory
+
+  status = SetCommonMembersFromJson(noti_val, tmp_noti);
+  CHECK_ERROR(status);
+
+  status = SetTextContentsFromJson(noti_val, tmp_noti);
+  CHECK_ERROR(status);
+
+  status = SetImagesFromJson(noti_val, tmp_noti);
+  CHECK_ERROR(status);
+
+  status = SetThumbnailsFromJson(noti_val, tmp_noti);
+  CHECK_ERROR(status);
+
+  status = SetActionsFromJson(noti_val, tmp_noti);
+  CHECK_ERROR(status);
+
+  status = SetGroupContentsFromJson(noti_val, tmp_noti);
+  CHECK_ERROR(status);
+
+  status = SetLedsFromJson(noti_val, tmp_noti);
+  CHECK_ERROR(status);
+
+  *noti_handle = tmp_noti_ptr.release();
+
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult UserNotification::PostUserNotification(const picojson::object& args,
+                                                      bool is_update,
+                                                      picojson::object* out_ptr) {
+  LoggerD("Enter");
+  return PostNotification(args, is_update, out_ptr, GetNotiHandleFromJson);
+}
+
+PlatformResult UserNotification::AddTextContentsToJson(notification_h noti_handle,
+                                                       picojson::object* out_ptr) {
+  LoggerD("Enter");
+  picojson::object& out = *out_ptr;
+
+  picojson::value text_contents = picojson::value(picojson::object());
+  picojson::object& text_contents_obj = text_contents.get<picojson::object>();
+
+  out["textContents"] = text_contents;
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult UserNotification::AddImagesToJson(notification_h noti_handle,
+                                                 picojson::object* out_ptr) {
+  LoggerD("Enter");
+  picojson::object& out = *out_ptr;
+
+  picojson::value text_contents = picojson::value(picojson::object());
+  picojson::object& text_contents_obj = text_contents.get<picojson::object>();
+
+  out["images"] = text_contents;
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult UserNotification::AddThumbnailsToJson(notification_h noti_handle,
+                                                     picojson::object* out_ptr) {
+  LoggerD("Enter");
+  picojson::object& out = *out_ptr;
+
+  picojson::value text_contents = picojson::value(picojson::object());
+  picojson::object& text_contents_obj = text_contents.get<picojson::object>();
+
+  out["thumbnails"] = text_contents;
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult UserNotification::AddActionsToJson(notification_h noti_handle,
+                                                  picojson::object* out_ptr) {
+  LoggerD("Enter");
+  picojson::object& out = *out_ptr;
+
+  picojson::value text_contents = picojson::value(picojson::object());
+  picojson::object& text_contents_obj = text_contents.get<picojson::object>();
+
+  out["actions"] = text_contents;
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult UserNotification::AddGroupContentsToJson(notification_h noti_handle,
+                                                        picojson::object* out_ptr) {
+  LoggerD("Enter");
+  picojson::object& out = *out_ptr;
+
+  picojson::value text_contents = picojson::value(picojson::object());
+  picojson::object& text_contents_obj = text_contents.get<picojson::object>();
+
+  out["groupContents"] = text_contents;
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult UserNotification::AddLedsToJson(notification_h noti_handle,
+                                               picojson::object* out_ptr) {
+  LoggerD("Enter");
+  picojson::object& out = *out_ptr;
+
+  picojson::value text_contents = picojson::value(picojson::object());
+  picojson::object& text_contents_obj = text_contents.get<picojson::object>();
+
+  out["leds"] = text_contents;
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult UserNotification::SetTextContentsFromJson(const picojson::value& noti_value,
+                                                         notification_h noti_handle) {
+  LoggerD("Enter");
+
   return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR,
                             "Not implemented yet",
                             ("Not implemented yet"));
 }
 
-PlatformResult UserNotification::GetNotiHandleFromJson(const picojson::object& args,
-                                                         bool is_update,
-                                                         notification_h *noti_handle){
+PlatformResult UserNotification::SetImagesFromJson(const picojson::value& noti_value,
+                                                   notification_h noti_handle) {
   LoggerD("Enter");
+
   return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR,
                             "Not implemented yet",
                             ("Not implemented yet"));
 }
 
-PlatformResult UserNotification::PostUserNotification(const picojson::object& args,
-                                            bool is_update,
-                                            picojson::object* out_ptr) {
+PlatformResult UserNotification::SetThumbnailsFromJson(const picojson::value& noti_value,
+                                                       notification_h noti_handle) {
   LoggerD("Enter");
-  return PostNotification(args, is_update, out_ptr, GetNotiHandleFromJson);
+
+  return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR,
+                            "Not implemented yet",
+                            ("Not implemented yet"));
+}
+
+PlatformResult UserNotification::SetActionsFromJson(const picojson::value& noti_value,
+                                                    notification_h noti_handle) {
+  LoggerD("Enter");
+
+  return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR,
+                            "Not implemented yet",
+                            ("Not implemented yet"));
+}
+
+PlatformResult UserNotification::SetGroupContentsFromJson(const picojson::value& noti_value,
+                                                          notification_h noti_handle) {
+  LoggerD("Enter");
+
+  return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR,
+                            "Not implemented yet",
+                            ("Not implemented yet"));
 }
 
+PlatformResult UserNotification::SetLedsFromJson(const picojson::value& noti_value,
+                                                 notification_h noti_handle) {
+  LoggerD("Enter");
+
+  return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR,
+                            "Not implemented yet",
+                            ("Not implemented yet"));
+}
 
 }  // namespace notification
 }  // namespace extension
index a0fb44e..4a5f284 100644 (file)
@@ -34,6 +34,32 @@ class UserNotification : public CommonNotification {
   static common::PlatformResult PostUserNotification(const picojson::object& args,
                                                      bool is_update,
                                                      picojson::object* out_ptr);
+
+  static common::PlatformResult AddTextContentsToJson(notification_h noti_handle,
+                                                      picojson::object* out_ptr);
+  static common::PlatformResult AddImagesToJson(notification_h noti_handle,
+                                                picojson::object* out_ptr);
+  static common::PlatformResult AddThumbnailsToJson(notification_h noti_handle,
+                                                    picojson::object* out_ptr);
+  static common::PlatformResult AddActionsToJson(notification_h noti_handle,
+                                                 picojson::object* out_ptr);
+  static common::PlatformResult AddGroupContentsToJson(notification_h noti_handle,
+                                                       picojson::object* out_ptr);
+  static common::PlatformResult AddLedsToJson(notification_h noti_handle,
+                                              picojson::object* out_ptr);
+
+  static common::PlatformResult SetTextContentsFromJson(const picojson::value& noti_val,
+                                                        notification_h noti_handle);
+  static common::PlatformResult SetImagesFromJson(const picojson::value& noti_val,
+                                                  notification_h noti_handle);
+  static common::PlatformResult SetThumbnailsFromJson(const picojson::value& noti_val,
+                                                      notification_h noti_handle);
+  static common::PlatformResult SetActionsFromJson(const picojson::value& noti_val,
+                                                   notification_h noti_handle);
+  static common::PlatformResult SetGroupContentsFromJson(const picojson::value& noti_val,
+                                                         notification_h noti_handle);
+  static common::PlatformResult SetLedsFromJson(const picojson::value& noti_val,
+                                                notification_h noti_handle);
  private:
   UserNotification();
   virtual ~UserNotification();