Add find funcs for notification-ex reporter 71/226871/3
authormk5004.lee <mk5004.lee@samsung.com>
Fri, 6 Mar 2020 05:20:01 +0000 (14:20 +0900)
committermk5004.lee <mk5004.lee@samsung.com>
Fri, 6 Mar 2020 07:01:08 +0000 (16:01 +0900)
 - find_all
   find_by_channel

Change-Id: I7c82ee22d679f824704376f6f7d27c0306b5d30f
Signed-off-by: mk5004.lee <mk5004.lee@samsung.com>
notification-ex/api/notification_ex_internal.h
notification-ex/reporter.cc
notification-ex/reporter.h
notification-ex/stub.cc

index 2a48647..c20627c 100644 (file)
@@ -43,8 +43,13 @@ int noti_ex_item_icon_get_icon_path(noti_ex_item_h handle, char **icon_path);
 int noti_ex_item_button_set_image(noti_ex_item_h handle, char *path);
 int noti_ex_item_button_get_image(noti_ex_item_h handle, char **path);
 
+int noti_ex_reporter_find_by_channel(noti_ex_reporter_h handle,
+               const char *channel, noti_ex_item_h **noti_list, int *count);
+int noti_ex_reporter_find_all(noti_ex_reporter_h handle,
+               noti_ex_item_h **noti_list, int *count);
 int noti_ex_reporter_delete_by_channel(noti_ex_manager_h handle, char *channel,
                int *request_id);
+
 int noti_ex_manager_delete_by_channel(noti_ex_manager_h handle, char *channel,
                int *request_id);
 
index 11c0074..d423682 100644 (file)
@@ -143,6 +143,38 @@ std::unique_ptr<AbstractItem> Reporter::FindByRootID(std::string id) {
   return gen_item;
 }
 
+list<unique_ptr<AbstractItem>> Reporter::FindByChannel(string channel) {
+  Bundle serialized;
+  EventInfo info(EventInfo::Get, util::GetAppId(), channel, "");
+  list<Bundle> result = impl_->sender_->Request(info);
+  if (result.size() == 0) {
+    LOGE("Fail to get noti");
+    return list<unique_ptr<item::AbstractItem>>{};
+  }
+
+  list<unique_ptr<AbstractItem>> gen_item_list;
+  for (auto& i : result)
+    gen_item_list.push_back(ItemInflator::Create(i));
+
+  return gen_item_list;
+}
+
+list<unique_ptr<AbstractItem>> Reporter::FindAll() {
+  Bundle serialized;
+  EventInfo info(EventInfo::Get, util::GetAppId(), "", "");
+  list<Bundle> result = impl_->sender_->Request(info);
+  if (result.size() == 0) {
+    LOGE("Fail to get noti");
+    return list<unique_ptr<item::AbstractItem>>{};
+  }
+
+  list<unique_ptr<AbstractItem>> gen_item_list;
+  for (auto& i : result)
+    gen_item_list.push_back(ItemInflator::Create(i));
+
+  return gen_item_list;
+}
+
 int Reporter::SendEvent(const IEventInfo& info,
     shared_ptr<item::AbstractItem> noti) {
   Bundle serialized = noti->Serialize();
index d76292d..91bde45 100644 (file)
@@ -51,6 +51,8 @@ class EXPORT_API Reporter : public IEventObserver {
   int DeleteAll();
   int DeleteByChannel(std::string channel);
   std::unique_ptr<item::AbstractItem> FindByRootID(std::string id);
+  std::list<std::unique_ptr<item::AbstractItem>> FindByChannel(std::string channel);
+  std::list<std::unique_ptr<item::AbstractItem>> FindAll();
   virtual void OnEvent(const IEventInfo& info,
       std::list<std::shared_ptr<item::AbstractItem>> notiList);
   virtual std::list<std::shared_ptr<item::AbstractItem>> OnRequestEvent(
index 3a9b575..0698fa6 100644 (file)
@@ -3146,6 +3146,73 @@ extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
   return NOTI_EX_ERROR_NONE;
 }
 
+extern "C" EXPORT_API int noti_ex_reporter_find_by_channel(noti_ex_reporter_h handle,
+    const char *channel, noti_ex_item_h **noti_list, int *count) {
+  if (handle == nullptr || channel == nullptr || noti_list == nullptr
+      || count == nullptr) {
+    LOGE("Invalid parameter");
+    return NOTI_EX_ERROR_INVALID_PARAMETER;
+  }
+
+  try {
+    ReporterStub* stub = static_cast<ReporterStub*>(handle);
+    list<unique_ptr<AbstractItem>> list_ptr = stub->FindByChannel(channel);
+    if (list_ptr.empty()) {
+      LOGW("Not exist ID");
+      *noti_list = nullptr;
+      return NOTI_EX_ERROR_NONE;
+    }
+
+    int size = list_ptr.size();
+    int i = 0;
+
+    Handle* list_item[size];
+    for (auto& ptr : list_ptr)
+      list_item[i++] = new Handle(std::move(ptr));
+
+    *noti_list = reinterpret_cast<noti_ex_item_h*>(list_item);
+    *count = size;
+  } catch (Exception &ex) {
+    LOGE("%s %d", ex.what(), ex.GetErrorCode());
+    return NOTI_EX_ERROR_IO_ERROR;
+  }
+
+  return NOTI_EX_ERROR_NONE;
+}
+
+extern "C" EXPORT_API int noti_ex_reporter_find_all(noti_ex_reporter_h handle,
+    noti_ex_item_h **noti_list, int *count) {
+  if (handle == nullptr || noti_list == nullptr || count == nullptr) {
+    LOGE("Invalid parameter");
+    return NOTI_EX_ERROR_INVALID_PARAMETER;
+  }
+
+  try {
+    ReporterStub* stub = static_cast<ReporterStub*>(handle);
+    list<unique_ptr<AbstractItem>> list_ptr = stub->FindAll();
+    if (list_ptr.empty()) {
+      LOGW("Not exist ID");
+      *noti_list = nullptr;
+      return NOTI_EX_ERROR_NONE;
+    }
+
+    int size = list_ptr.size();
+    int i = 0;
+
+    Handle* list_item[size];
+    for (auto& ptr : list_ptr)
+      list_item[i++] = new Handle(std::move(ptr));
+
+    *noti_list = reinterpret_cast<noti_ex_item_h*>(list_item);
+    *count = size;
+  } catch (Exception &ex) {
+    LOGE("%s %d", ex.what(), ex.GetErrorCode());
+    return NOTI_EX_ERROR_IO_ERROR;
+  }
+
+  return NOTI_EX_ERROR_NONE;
+}
+
 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
     const char *id, const char *text, const char *hyperlink) {
   if (handle == nullptr || text == nullptr) {