#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
#define NOTIFICATION_EX_REPORTER_OBJECT_PATH "/org/tizen/notification_ex_reporter"
using namespace std;
+using namespace tizen_base;
using namespace notification::item;
namespace notification {
listener_->RegisterObserver(parent_);
}
-void Reporter::Impl::SendNotify(shared_ptr<item::AbstractItem> noti,
+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();
}
-void Reporter::Post(std::shared_ptr<item::AbstractItem> noti) {
+void Reporter::SendError(const IEventInfo& info, NotificationError error) {
+ list<Bundle> serialized_list {};
+ IEventInfo& i = const_cast<IEventInfo&>(info);
+ static_cast<IEventInfoInternal&>(i).SetError(error);
+ static_cast<IEventInfoInternal&>(i).SetEventType(EventInfo::Error);
+ impl_->sender_->Notify(info, serialized_list, info.GetOwner());
+}
+
+int Reporter::Post(std::shared_ptr<item::AbstractItem> noti) {
LOGI("Post noti");
- impl_->SendNotify(noti, EventInfo::Post);
+ 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);
}
-void Reporter::Post(std::list<std::shared_ptr<AbstractItem>> notiList) {
+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);
+}
+
+int Reporter::Delete(std::shared_ptr<AbstractItem> noti) {
+ return impl_->SendNotify(noti, EventInfo::Delete);
}
-void Reporter::Update(std::shared_ptr<AbstractItem> noti) {
- impl_->SendNotify(noti, EventInfo::Update);
+int Reporter::DeleteAll() {
+ Bundle serialized;
+ EventInfo info(EventInfo::DeleteAll, util::GetAppId(), "");
+ list<Bundle> serialized_list {serialized};
+ impl_->sender_->Notify(info, serialized_list, util::GetAppId());
+ return info.GetRequestId();
}
-void Reporter::Remove(std::shared_ptr<AbstractItem> noti) {
- impl_->SendNotify(noti, EventInfo::Delete);
+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::shared_ptr<AbstractItem> Reporter::FindByRootID(std::string id) {
+std::unique_ptr<AbstractItem> Reporter::FindByRootID(std::string id) {
Bundle serialized;
EventInfo info(EventInfo::Get, util::GetAppId(), "", id);
list<Bundle> result = impl_->sender_->Request(info);
if (result.size() == 0) {
LOGE("Fail to get noti");
- return shared_ptr<item::AbstractItem>({});
+ return unique_ptr<item::AbstractItem>{};
}
Bundle b = result.front();
- shared_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
+ unique_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
return gen_item;
}
-void Reporter::SendEvent(const IEventInfo& info,
+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();
list<Bundle> serialized_list {serialized};
impl_->sender_->Notify(info, serialized_list);
+ 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;
+ }
+
for (auto& i : serialized) {
shared_ptr<AbstractItem> gen_item = ItemInflator::Create(i);
item_list.emplace_back(gen_item);
return serialized_list;
}
+int Reporter::OnRequestNumber(const IEventInfo& info) {
+ return 0;
+}
+
void Reporter::OnEvent(
const IEventInfo& info, list<shared_ptr<item::AbstractItem>> notiList) {
}
+void Reporter::OnError(NotificationError error, int requestId) {
+}
+
string Reporter::GetPath() {
return NOTIFICATION_EX_REPORTER_OBJECT_PATH;
}
-} // nampace notification
+void Reporter::OnRegister(const IEventInfo& info) {
+}
+
+} // namespace notification