[Notification] getAll
authorRyszard Matuszyk <r.matuszyk@samsung.com>
Tue, 17 Mar 2015 12:11:44 +0000 (13:11 +0100)
committerRafal Galka <r.galka@samsung.com>
Thu, 19 Mar 2015 07:43:11 +0000 (16:43 +0900)
[Verification] Build required

Change-Id: I2512e66dca6082a791710afef020b6c686cc578f
Signed-off-by: Ryszard Matuszyk <r.matuszyk@samsung.com>
src/notification/notification_manager.cc

index ce50be1c1495f30fc5bdcb85a22946c7aa4159e9..de95488ad2b79fcc0f4c78c77a4b03d7b3262ffc 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "common/converter.h"
 #include "common/logger.h"
+#include "common/scope_exit.h"
 
 #include "notification/status_notification.h"
 
@@ -80,6 +81,52 @@ PlatformResult NotificationManager::Get(const picojson::object& args,
 }
 
 PlatformResult NotificationManager::GetAll(picojson::array& out) {
+  notification_h noti = nullptr;
+  notification_list_h noti_list = nullptr;
+  notification_list_h noti_list_iter = nullptr;
+
+  int ret =
+      notification_get_grouping_list(NOTIFICATION_TYPE_NONE, -1, &noti_list);
+  if (ret != NOTIFICATION_ERROR_NONE) {
+    LoggerD("Get notification list error: %d", ret);
+    return PlatformResult(ErrorCode::UNKNOWN_ERR,
+                          "Get notification list error");
+  }
+
+  SCOPE_EXIT {
+      notification_free_list(noti_list);
+  };
+
+  noti_list_iter = notification_list_get_head(noti_list);
+
+  while (noti_list_iter != nullptr) {
+    noti = notification_list_get_data(noti_list_iter);
+    if (noti != nullptr) {
+      int noti_priv = -1;
+      ret = notification_get_id(noti, NULL, &noti_priv);
+      if (ret != NOTIFICATION_ERROR_NONE) {
+        LoggerE("Cannot get notification id, error: %d", ret);
+        return PlatformResult(ErrorCode::UNKNOWN_ERR,
+                              "Cannot get notification id error");
+      }
+
+      app_control_h app_control;
+      PlatformResult status =
+          StatusNotification::GetAppControl(noti, &app_control);
+      if (status.IsError()) return status;
+
+      picojson::object noti_item = picojson::object();
+
+      status =
+          StatusNotification::ToJson(noti_priv, noti, app_control, &noti_item);
+      if (status.IsError()) return status;
+
+      out.push_back(picojson::value(noti_item));
+    }
+
+    noti_list_iter = notification_list_get_next(noti_list_iter);
+  }
+
   return PlatformResult(ErrorCode::NO_ERROR);
 }