#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 {
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();
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);
}
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::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) {
}
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,
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);
return serialized_list;
}
+int Reporter::OnRequestNumber(const IEventInfo& info) {
+ return 0;
+}
+
void Reporter::OnEvent(
const IEventInfo& info, list<shared_ptr<item::AbstractItem>> notiList) {
}
return NOTIFICATION_EX_REPORTER_OBJECT_PATH;
}
+void Reporter::OnRegister(const IEventInfo& info) {
+}
+
} // namespace notification