Merge branch 'tizen' into tizen_5.5
[platform/core/api/notification.git] / notification-ex / reporter.cc
index 4a655c0..d423682 100644 (file)
@@ -26,6 +26,8 @@
 #include "notification-ex/item_inflator.h"
 #include "notification-ex/dbus_connection_manager.h"
 #include "notification-ex/ex_util.h"
+#include "notification-ex/item_info_internal.h"
+#include "notification-ex/shared_file.h"
 
 #ifdef LOG_TAG
 #undef LOG_TAG
@@ -36,6 +38,7 @@
 #define NOTIFICATION_EX_REPORTER_OBJECT_PATH "/org/tizen/notification_ex_reporter"
 
 using namespace std;
+using namespace tizen_base;
 using namespace notification::item;
 namespace notification {
 
@@ -74,6 +77,11 @@ void Reporter::SendError(const IEventInfo& info, NotificationError error) {
 
 int Reporter::Post(std::shared_ptr<item::AbstractItem> noti) {
   LOGI("Post noti");
+  static_pointer_cast<IItemInfoInternal>(noti->GetInfo())->SetTime(time(NULL));
+  SharedFile* shared_file = new SharedFile();
+  shared_file->CopyPrivateFile(noti);
+  delete shared_file;
+
   return impl_->SendNotify(noti, EventInfo::Post);
 }
 
@@ -81,14 +89,24 @@ int Reporter::Post(std::list<std::shared_ptr<AbstractItem>> notiList) {
   EventInfo info(EventInfo::Post, util::GetAppId(), "");
   list<Bundle> serialized_list;
   for (auto& i : notiList) {
+    static_pointer_cast<IItemInfoInternal>(i->GetInfo())->SetTime(time(NULL));
     Bundle b = i->Serialize();
     serialized_list.push_back(b);
+
+    SharedFile* shared_file = new SharedFile();
+    shared_file->CopyPrivateFile(i);
+    delete shared_file;
   }
   impl_->sender_->Notify(info, serialized_list);
   return info.GetRequestId();
 }
 
 int Reporter::Update(std::shared_ptr<AbstractItem> noti) {
+  static_pointer_cast<IItemInfoInternal>(noti->GetInfo())->SetTime(time(NULL));
+  SharedFile* shared_file = new SharedFile();
+  shared_file->CopyPrivateFile(noti);
+  delete shared_file;
+
   return impl_->SendNotify(noti, EventInfo::Update);
 }
 
@@ -104,6 +122,14 @@ int Reporter::DeleteAll() {
   return info.GetRequestId();
 }
 
+int Reporter::DeleteByChannel(string channel) {
+  Bundle serialized;
+  EventInfo info(EventInfo::DeleteAll, util::GetAppId(), channel);
+  list<Bundle> serialized_list {serialized};
+  impl_->sender_->Notify(info, serialized_list, util::GetAppId());
+  return info.GetRequestId();
+}
+
 std::unique_ptr<AbstractItem> Reporter::FindByRootID(std::string id) {
   Bundle serialized;
   EventInfo info(EventInfo::Get, util::GetAppId(), "", id);
@@ -114,7 +140,39 @@ std::unique_ptr<AbstractItem> Reporter::FindByRootID(std::string id) {
   }
   Bundle b = result.front();
   unique_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
-  return move(gen_item);
+  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,
@@ -125,6 +183,17 @@ int Reporter::SendEvent(const IEventInfo& info,
   return info.GetRequestId();
 }
 
+int Reporter::SendEvent(const IEventInfo& info,
+    std::list<std::shared_ptr<item::AbstractItem>> notiList) {
+  list<Bundle> serialized_list;
+  for (auto& i : notiList) {
+    Bundle b = i->Serialize();
+    serialized_list.push_back(b);
+  }
+  impl_->sender_->Notify(info, serialized_list);
+  return info.GetRequestId();
+}
+
 void Reporter::OnEvent(const IEventInfo& info, list<Bundle> serialized) {
   NotificationError error =
       (static_cast<const IEventInfoInternal&>(info)).GetError();
@@ -172,4 +241,7 @@ string Reporter::GetPath() {
   return NOTIFICATION_EX_REPORTER_OBJECT_PATH;
 }
 
+void Reporter::OnRegister(const IEventInfo& info) {
+}
+
 }  // namespace notification