Merge branch 'tizen' into tizen_5.5
[platform/core/api/notification.git] / notification-ex / reporter.cc
index e7e2363..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
@@ -59,7 +61,7 @@ Reporter::Impl::Impl(Reporter* parent,
 int Reporter::Impl::SendNotify(shared_ptr<item::AbstractItem> noti,
     IEventInfo::EventType type) {
   Bundle serialized = noti->Serialize();
-  EventInfo info(type, util::GetAppId(), noti->GetChannel());
+  EventInfo info(type, util::GetAppId(), noti->GetChannel(), noti->GetId());
   list<Bundle> serialized_list {serialized};
   sender_->Notify(info, serialized_list);
   return info.GetRequestId();
@@ -75,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);
 }
 
@@ -82,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);
 }
 
@@ -98,8 +115,19 @@ int Reporter::Delete(std::shared_ptr<AbstractItem> noti) {
 }
 
 int Reporter::DeleteAll() {
-  //TODO
-  return -1;
+  Bundle serialized;
+  EventInfo info(EventInfo::DeleteAll, util::GetAppId(), "");
+  list<Bundle> serialized_list {serialized};
+  impl_->sender_->Notify(info, serialized_list, util::GetAppId());
+  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) {
@@ -112,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,
@@ -123,15 +183,29 @@ 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();
+  list<shared_ptr<item::AbstractItem>> item_list;
   if (info.GetEventType() == EventInfo::Error) {
     OnError(error, info.GetRequestId());
     return;
+  } else if (info.GetEventType() == EventInfo::DeleteAll) {
+    OnEvent(info, item_list);
+    return;
   }
 
-  list<shared_ptr<item::AbstractItem>> item_list;
   for (auto& i : serialized) {
     shared_ptr<AbstractItem> gen_item = ItemInflator::Create(i);
     item_list.emplace_back(gen_item);
@@ -152,6 +226,10 @@ list<Bundle> Reporter::OnRequest(const IEventInfo& info) {
   return serialized_list;
 }
 
+int Reporter::OnRequestNumber(const IEventInfo& info) {
+  return 0;
+}
+
 void Reporter::OnEvent(
     const IEventInfo& info, list<shared_ptr<item::AbstractItem>> notiList) {
 }
@@ -163,4 +241,7 @@ string Reporter::GetPath() {
   return NOTIFICATION_EX_REPORTER_OBJECT_PATH;
 }
 
+void Reporter::OnRegister(const IEventInfo& info) {
+}
+
 }  // namespace notification