[Notification] added C++ stubs for UserNotification 66/137566/2
authorPiotr Kosko <p.kosko@samsung.com>
Wed, 5 Jul 2017 12:42:40 +0000 (14:42 +0200)
committerPiotr Kosko <p.kosko@samsung.com>
Fri, 28 Jul 2017 12:21:08 +0000 (14:21 +0200)
[Verification] Code compiles without error.
  TCT passrate didn't change.

Change-Id: I83deb2c0ce692ee67c86213d3a9552dadceb7bb9
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
src/notification/common_notification.cc
src/notification/common_notification.h
src/notification/notification.gyp
src/notification/notification_instance.cc
src/notification/notification_manager.cc
src/notification/notification_manager.h
src/notification/status_notification.cc
src/notification/status_notification.h
src/notification/user_notification.cc [new file with mode: 0644]
src/notification/user_notification.h [new file with mode: 0644]

index ccaa6c75cc0ed72797598113f48fa0050e4bbda9..233d42428016fa85e344be1d34f62149b02a83e7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2015-2017 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
  *    you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
 
 #include "notification/common_notification.h"
 
-#include <notification.h>
 #include <notification_internal.h>
 #include <app_control_internal.h>
 
@@ -976,5 +975,62 @@ PlatformResult CommonNotification::SetAppControl(notification_h noti_handle,
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
+common::PlatformResult CommonNotification::UpdateNotificationAfterPost(
+    notification_h noti_handle, int id, picojson::object* out_ptr) {
+  time_t posted_time;
+  PlatformResult status = GetPostedTime(noti_handle, &posted_time);
+  if (status.IsError()) {
+    return status;
+  }
+
+  picojson::object& out = *out_ptr;
+  out["postedTime"] =
+      picojson::value(static_cast<double>(posted_time) * 1000.0);
+  out["id"] = picojson::value(std::to_string(id));
+  out["type"] = picojson::value("STATUS");
+
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult CommonNotification::PostNotification(const picojson::object& args,
+                                            bool is_update,
+                                            picojson::object* out_ptr,
+                                            GetHandleFromJsonFun getHandle) {
+  LoggerD("Enter");
+  notification_h noti_handle = nullptr;
+  int ret = NOTIFICATION_ERROR_NONE;
+  int id = NOTIFICATION_PRIV_ID_NONE;
+
+  SCOPE_EXIT {
+    notification_free(noti_handle);
+  };
+
+  PlatformResult status = getHandle(args, is_update, &noti_handle);
+
+  if (status.IsError()){
+    return status;
+  }
+
+  if (is_update) {
+    ret = notification_update(noti_handle);
+    if (NOTIFICATION_ERROR_NONE != ret) {
+      return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR,
+                                "Update notification error",
+                                ("Update notification error: %d", ret));
+    }
+    return PlatformResult(ErrorCode::NO_ERROR);
+  } else {
+    ret = notification_insert(noti_handle, &id);
+    if (NOTIFICATION_ERROR_NONE != ret) {
+      return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+                                "Cannot insert notification",
+                                ("Cannot insert notification: %d", ret));
+    }
+  }
+
+  return UpdateNotificationAfterPost(noti_handle, id, out_ptr);
+}
+
+
 }  // namespace notification
 }  // namespace extension
index 591e998998990ccf765ef7b9e6df16071caef32e..69b71019d7be1d32d8076684a2f8272f992c569b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2015-2017 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
  *    you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
 
 #include <notification.h>
 #include <app_control.h>
+#include <functional>
 
 #include "common/picojson.h"
 #include "common/platform_result.h"
@@ -34,6 +35,10 @@ const std::string kProgressTypeByte = "BYTE";
 typedef std::map<int, notification_text_type_e> InformationEnumMap;
 typedef std::map<int, notification_image_type_e> ImageEnumMap;
 
+typedef std::function<common::PlatformResult(const picojson::object& args,
+                                             bool is_update,
+                                             notification_h *noti_handle)> GetHandleFromJsonFun;
+
 class CommonNotification {
  public:
   XW_EXPORT static common::PlatformResult GetAppControl(notification_h noti_handle,
@@ -124,6 +129,13 @@ class CommonNotification {
   static common::PlatformResult CreateAppControl(app_control_h* app_control);
 
   static bool IsColorFormatNumberic(const std::string& color);
+  static common::PlatformResult UpdateNotificationAfterPost(notification_h noti_handle, int id,
+                                                    picojson::object* out_ptr);
+  static common::PlatformResult PostNotification(const picojson::object& args,
+                                                 bool is_update,
+                                                 picojson::object* out_ptr,
+                                                 GetHandleFromJsonFun getHandle);
+
  protected:
   CommonNotification();
   virtual ~CommonNotification();
index 6374a5d722aa1ba1951c7e462f5f12621265c038..32a8fd945c77ba44006334a3c7fa9de294819b31 100755 (executable)
@@ -19,6 +19,8 @@
         'notification_manager.cc',
         'status_notification.cc',
         'status_notification.h',
+        'user_notification.cc',
+        'user_notification.h',
         'common_notification.cc',
         'common_notification.h'
       ],
index a4ffee981157d704e3441b5f169491a9ef10dec5..5447733ac0cdadbbcc8866833c3e712d94703556 100644 (file)
@@ -16,8 +16,6 @@
 
 #include "notification/notification_instance.h"
 
-#include <functional>
-
 #include "common/logger.h"
 #include "common/picojson.h"
 #include "common/platform_result.h"
@@ -155,17 +153,9 @@ void NotificationInstance::NotificationManagerGet(const picojson::value& args,
   LoggerD("Enter");
   picojson::value val{picojson::object{}};
 
-  using namespace std::placeholders;
-  std::function <PlatformResult(const picojson::object& args, picojson::object&)> impl {};
-  if (args.contains("newImpl") && args.get("newImpl").get<bool>()) {
-    LoggerD("New implementation");
-    impl = std::bind(&NotificationManager::GetUserNoti, manager_, _1, _2);
-  } else {
-    LoggerW("Deprecated object used");
-    impl = std::bind(&NotificationManager::Get, manager_, _1, _2);
-  }
-
-  PlatformResult status = impl(args.get<picojson::object>(), val.get<picojson::object>());
+  PlatformResult status = manager_->Get(
+      args.get<picojson::object>(), val.get<picojson::object>(),
+      args.contains("newImpl") && args.get("newImpl").get<bool>());
 
   if (status.IsSuccess()) {
     ReportSuccess(val, out);
@@ -180,17 +170,9 @@ void NotificationInstance::NotificationManagerGetAll(
   LoggerD("Enter");
   picojson::value val{picojson::array{}};
 
-  using namespace std::placeholders;
-  std::function <PlatformResult(picojson::array&)> impl {};
-  if (args.contains("newImpl") && args.get("newImpl").get<bool>()) {
-    LoggerD("New implementation");
-    impl = std::bind(&NotificationManager::GetAllUserNoti, manager_, _1);
-  } else {
-    LoggerW("Deprecated object used");
-    impl = std::bind(&NotificationManager::GetAll, manager_, _1);
-  }
-
-  PlatformResult status = impl(val.get<picojson::array>());
+  PlatformResult status = manager_->GetAll(
+      val.get<picojson::array>(),
+      args.contains("newImpl") && args.get("newImpl").get<bool>());
 
   if (status.IsSuccess()) {
     ReportSuccess(val, out);
index 6079a9d4ad4e6cb76f09b702942b1ef129b154ff..81e7b004fa4e9e7bfcfd5a4578f4107dc0def656 100644 (file)
@@ -30,6 +30,7 @@
 #include "common/scope_exit.h"
 
 #include "notification/status_notification.h"
+#include "notification/user_notification.h"
 #include "notification/common_notification.h"
 
 namespace extension {
@@ -54,7 +55,7 @@ NotificationManager* NotificationManager::GetInstance() {
 PlatformResult NotificationManager::Post(const picojson::object& args,
                                          picojson::object& out) {
   LoggerD("Enter");
-  return StatusNotification::FromJson(args, false, &out);
+  return StatusNotification::PostStatusNotification(args, false, &out);
 }
 
 PlatformResult NotificationManager::PostUserNoti(const picojson::object& args,
@@ -68,7 +69,7 @@ PlatformResult NotificationManager::PostUserNoti(const picojson::object& args,
 
 PlatformResult NotificationManager::Update(const picojson::object& args) {
   LoggerD("Enter");
-  return StatusNotification::FromJson(args, true, NULL);
+  return StatusNotification::PostStatusNotification(args, true, NULL);
 }
 
 PlatformResult NotificationManager::UpdateUserNoti(const picojson::object& args) {
@@ -114,7 +115,7 @@ PlatformResult NotificationManager::RemoveAll() {
 }
 
 PlatformResult NotificationManager::Get(const picojson::object& args,
-                                        picojson::object& out) {
+                                        picojson::object& out, bool is_new_impl) {
   LoggerD("Enter");
   int id;
   try {
@@ -147,7 +148,12 @@ PlatformResult NotificationManager::Get(const picojson::object& args,
     LoggerE("Failed: GetAppControl");
     return status;
   }
-  status = StatusNotification::ToJson(id, noti_handle, app_control, &out);
+
+  if (!is_new_impl) {
+    status = StatusNotification::ToJson(id, noti_handle, app_control, &out);
+  } else {
+    status = UserNotification::ToJson(id, noti_handle, app_control, &out);
+  }
   if (status.IsError())
   {
     LoggerE("Failed: ToJson");
@@ -156,16 +162,7 @@ PlatformResult NotificationManager::Get(const picojson::object& args,
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
-PlatformResult NotificationManager::GetUserNoti(const picojson::object& args,
-                                        picojson::object& out) {
-  LoggerD("Enter");
-  // TODO implement
-  return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR,
-                            "Not implemented yet",
-                            ("Not implemented yet"));
-}
-
-PlatformResult NotificationManager::GetAll(picojson::array& out) {
+PlatformResult NotificationManager::GetAll(picojson::array& out, bool is_new_impl) {
   LoggerD("Enter");
   notification_h noti = nullptr;
   notification_list_h noti_list = nullptr;
@@ -219,8 +216,13 @@ PlatformResult NotificationManager::GetAll(picojson::array& out) {
 
       picojson::object noti_item = picojson::object();
 
-      status =
-          StatusNotification::ToJson(noti_priv, noti, app_control, &noti_item);
+      if (!is_new_impl) {
+        status =
+            StatusNotification::ToJson(noti_priv, noti, app_control, &noti_item);
+      } else {
+        status =
+            UserNotification::ToJson(noti_priv, noti, app_control, &noti_item);
+      }
       if (status.IsError())
         return status;
 
@@ -233,14 +235,6 @@ PlatformResult NotificationManager::GetAll(picojson::array& out) {
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
-PlatformResult NotificationManager::GetAllUserNoti(picojson::array& out) {
-  LoggerD("Enter");
-  // TODO implement
-  return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR,
-                            "Not implemented yet",
-                            ("Not implemented yet"));
-}
-
 PlatformResult NotificationManager::PlayLEDCustomEffect(
     const picojson::object& args) {
   LoggerD("Enter");
@@ -290,6 +284,7 @@ common::PlatformResult NotificationManager::SaveTemplate(const picojson::object&
     notification_free(noti_handle);
   };
 
+  // TODO use UserNotification method
   PlatformResult status = StatusNotification::GetNotiHandleFromJson(args, false, &noti_handle);
 
   if (status.IsError()){
@@ -331,6 +326,7 @@ common::PlatformResult NotificationManager::CreateFromTemplate(const picojson::o
     notification_free(noti_handle);
   };
 
+  // TODO use UserNotification method
   PlatformResult status = StatusNotification::ToJson(0, noti_handle, nullptr, &out);
   if (status.IsError())
   {
index 770cc7e84f062b6ae14321264975f6e68732563c..6ba779dfb40ea0382ebb624efff6e9c85b77090e 100644 (file)
@@ -38,11 +38,8 @@ class NotificationManager {
   common::PlatformResult Remove(const picojson::object& args);
   common::PlatformResult RemoveAll();
   common::PlatformResult Get(const picojson::object& args,
-                             picojson::object& out);
-  common::PlatformResult GetUserNoti(const picojson::object& args,
-                                     picojson::object& out);
-  common::PlatformResult GetAll(picojson::array& out);
-  common::PlatformResult GetAllUserNoti(picojson::array& out);
+                             picojson::object& out, bool is_new_impl = false);
+  common::PlatformResult GetAll(picojson::array& out, bool is_new_impl = false);
 
   common::PlatformResult PlayLEDCustomEffect(const picojson::object& args);
   common::PlatformResult StopLEDCustomEffect();
index f2378ca554536027f9ef8c484f19ac2d47e329c8..7b1d0e29c4a5154da9816b1f59da3b7f333cceef 100644 (file)
 
 #include "notification/status_notification.h"
 
-#include <notification.h>
-#include <notification_internal.h>
-#include <app_control_internal.h>
-
 #include "common/converter.h"
 #include "common/logger.h"
 #include "common/scope_exit.h"
@@ -406,56 +402,11 @@ PlatformResult StatusNotification::GetNotiHandleFromJson(const picojson::object&
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
-PlatformResult StatusNotification::FromJson(const picojson::object& args,
+PlatformResult StatusNotification::PostStatusNotification(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, &noti_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) {
-      return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                                "Cannot insert notification");
-    }
-  }
-  if (ret != NOTIFICATION_ERROR_NONE) {
-    return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR,
-                              "Post/Update notification error",
-                              ("Post/Update notification error: %d", ret));
-  }
-
-  time_t posted_time;
-  status = GetPostedTime(noti_handle, &posted_time);
-  if (status.IsError()) {
-    return status;
-  }
-
-  if (is_update) {
-    return PlatformResult(ErrorCode::NO_ERROR);
-  }
-
-  picojson::object& out = *out_ptr;
-  out["id"] = picojson::value(std::to_string(id));
-  out["postedTime"] =
-      picojson::value(static_cast<double>(posted_time) * 1000.0);
-  out["type"] = picojson::value("STATUS");
-
-  return PlatformResult(ErrorCode::NO_ERROR);
+  return PostNotification(args, is_update, out_ptr, GetNotiHandleFromJson);
 }
 
 }  // namespace notification
index fccf002955cf1328f218e31ab5e8587be02e5d21..33607298df452dca71bb13a54962b36b8c0b19de 100644 (file)
@@ -30,9 +30,6 @@
 namespace extension {
 namespace notification {
 
-typedef std::map<int, notification_text_type_e> InformationEnumMap;
-typedef std::map<int, notification_image_type_e> ImageEnumMap;
-
 class StatusNotification : public CommonNotification {
  public:
   XW_EXPORT static common::PlatformResult ToJson(int id,
@@ -42,7 +39,7 @@ class StatusNotification : public CommonNotification {
   XW_EXPORT static common::PlatformResult GetNotiHandleFromJson(const picojson::object& args,
                                          bool is_update,
                                          notification_h *noti_handle);
-  static common::PlatformResult FromJson(const picojson::object& args,
+  static common::PlatformResult PostStatusNotification(const picojson::object& args,
                                          bool is_update,
                                          picojson::object* out_ptr);
  private:
diff --git a/src/notification/user_notification.cc b/src/notification/user_notification.cc
new file mode 100644 (file)
index 0000000..0d5cacd
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#include "notification/user_notification.h"
+
+#include "common/logger.h"
+#include "common/scope_exit.h"
+
+namespace extension {
+namespace notification {
+
+using namespace common;
+
+UserNotification::UserNotification() {
+}
+
+UserNotification::~UserNotification() {
+}
+
+PlatformResult UserNotification::ToJson(int id,
+                                        notification_h noti_handle,
+                                        app_control_h app_handle,
+                                        picojson::object* out_ptr) {
+  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){
+  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) {
+  LoggerD("Enter");
+  return PostNotification(args, is_update, out_ptr, GetNotiHandleFromJson);
+}
+
+
+}  // namespace notification
+}  // namespace extension
diff --git a/src/notification/user_notification.h b/src/notification/user_notification.h
new file mode 100644 (file)
index 0000000..a0fb44e
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#ifndef NOTIFICATION_USER_NOTIFICATION_H_
+#define NOTIFICATION_USER_NOTIFICATION_H_
+
+#include "notification/common_notification.h"
+
+namespace extension {
+namespace notification {
+
+class UserNotification : public CommonNotification {
+ public:
+  XW_EXPORT static common::PlatformResult ToJson(int id,
+                                                 notification_h noti_handle,
+                                                 app_control_h app_handle,
+                                                 picojson::object* out_ptr);
+  XW_EXPORT static common::PlatformResult GetNotiHandleFromJson(const picojson::object& args,
+                                                                bool is_update,
+                                                                notification_h *noti_handle);
+  static common::PlatformResult PostUserNotification(const picojson::object& args,
+                                                     bool is_update,
+                                                     picojson::object* out_ptr);
+ private:
+  UserNotification();
+  virtual ~UserNotification();
+};
+
+}  // namespace notification
+}  // namespace extension
+
+#endif /* NOTIFICATION_USER_NOTIFICATION_H_ */