From b60eb6afb0bc17ab77d31257f64b28019b233157 Mon Sep 17 00:00:00 2001 From: hyunho Date: Fri, 26 Apr 2019 13:31:42 +0900 Subject: [PATCH] Add delete all, get count implementation Change-Id: I7aace495979b4b243dead73dfb2132b0ab5ec96d Signed-off-by: hyunho --- notification-ex/dbus_event_listener.cc | 18 ++++++++++++++++++ notification-ex/dbus_event_listener.h | 1 + notification-ex/dbus_sender.cc | 13 +++++++++++++ notification-ex/dbus_sender.h | 1 + notification-ex/event_info.cc | 4 ++++ notification-ex/event_listener_interface.h | 1 + notification-ex/event_observer_interface.h | 1 + notification-ex/event_sender_interface.h | 1 + notification-ex/ievent_info.h | 2 ++ notification-ex/manager.cc | 25 +++++++++++++++++++++---- notification-ex/manager.h | 2 ++ notification-ex/reporter.cc | 16 +++++++++++++--- notification-ex/reporter.h | 1 + 13 files changed, 79 insertions(+), 7 deletions(-) diff --git a/notification-ex/dbus_event_listener.cc b/notification-ex/dbus_event_listener.cc index 65962cb..318521f 100644 --- a/notification-ex/dbus_event_listener.cc +++ b/notification-ex/dbus_event_listener.cc @@ -114,6 +114,15 @@ void DBusEventListener::Impl::OnMethodCall( } reply_body = g_variant_new("(a(s))", builder); g_variant_builder_unref(builder); + } else if (g_strcmp0(method_name, "Count") == 0) { + char* appid = NULL; + char* serialized = NULL; + g_variant_get(parameters, "(&s&s)", &appid, &serialized); + + Bundle b(serialized); + EventInfo info(b); + int num = dl->parent_->NotifyNumberRequest(info); + reply_body = g_variant_new("(i)", num); } g_dbus_method_invocation_return_value(invocation, reply_body); } @@ -132,6 +141,11 @@ int DBusEventListener::Impl::RegisterGDBusInterface() { " " " " " " + " " + " " + " " + " " + " " " " " "; GError *error = NULL; @@ -218,4 +232,8 @@ list DBusEventListener::NotifyObserver(const IEventInfo& info) { return impl_->observer_->OnRequest(info); } +int DBusEventListener::NotifyNumberRequest(const IEventInfo& info) { + return impl_->observer_->OnRequestNumber(info); +} + } // namespace notification diff --git a/notification-ex/dbus_event_listener.h b/notification-ex/dbus_event_listener.h index 15b1fde..54900d4 100644 --- a/notification-ex/dbus_event_listener.h +++ b/notification-ex/dbus_event_listener.h @@ -31,6 +31,7 @@ class EXPORT_API DBusEventListener : public IEventListener { void NotifyObserver( const IEventInfo& info, std::list serialized) override; std::list NotifyObserver(const IEventInfo& info) override; + int NotifyNumberRequest(const IEventInfo& info) override; private: class Impl; diff --git a/notification-ex/dbus_sender.cc b/notification-ex/dbus_sender.cc index 0fc8dab..df91ac6 100644 --- a/notification-ex/dbus_sender.cc +++ b/notification-ex/dbus_sender.cc @@ -153,4 +153,17 @@ std::list DBusSender::Request(const IEventInfo& info) { return ret_list; } +int DBusSender::RequestNumber(const IEventInfo& info) { + string appid = util::GetAppId(); + string method_name = EventInfo::GetString(info.GetEventType()); + Bundle serialized = info.Serialize(); + + GDBusMessage* reply = impl_->MethodCall(appid, method_name, serialized); + GVariant *reply_body = g_dbus_message_get_body(reply); + + int num; + g_variant_get(reply_body, "(i)", &num); + return num; +} + } // namespace notification diff --git a/notification-ex/dbus_sender.h b/notification-ex/dbus_sender.h index c6bf298..046afb6 100644 --- a/notification-ex/dbus_sender.h +++ b/notification-ex/dbus_sender.h @@ -34,6 +34,7 @@ class EXPORT_API DBusSender : public IEventSender { void Notify(const IEventInfo& info, std::list serialized, std::string dest_appid = "") override; std::list Request(const IEventInfo& info) override; + int RequestNumber(const IEventInfo& info) override; private: class Impl; diff --git a/notification-ex/event_info.cc b/notification-ex/event_info.cc index 80fe34a..fda2de5 100644 --- a/notification-ex/event_info.cc +++ b/notification-ex/event_info.cc @@ -85,6 +85,10 @@ string EventInfo::GetString(int type) { return "Get"; case Error: return "Error"; + case Count: + return "Count"; + case DeleteAll: + return "DeleteAll"; default: return "Custom" + std::to_string(Custom); } diff --git a/notification-ex/event_listener_interface.h b/notification-ex/event_listener_interface.h index c59908b..824677c 100644 --- a/notification-ex/event_listener_interface.h +++ b/notification-ex/event_listener_interface.h @@ -35,6 +35,7 @@ class EXPORT_API IEventListener { virtual void UnRegisterObserver(IEventObserver* observer) = 0; virtual void NotifyObserver(const IEventInfo& info, std::list serialized) = 0; virtual std::list NotifyObserver(const IEventInfo& info) = 0; + virtual int NotifyNumberRequest(const IEventInfo& info) = 0; }; } // namespace notification diff --git a/notification-ex/event_observer_interface.h b/notification-ex/event_observer_interface.h index e3192a5..ce6872f 100644 --- a/notification-ex/event_observer_interface.h +++ b/notification-ex/event_observer_interface.h @@ -33,6 +33,7 @@ class EXPORT_API IEventObserver { virtual ~IEventObserver() = default; virtual void OnEvent(const IEventInfo& info, std::list serialized) = 0; virtual std::list OnRequest(const IEventInfo& info) = 0; + virtual int OnRequestNumber(const IEventInfo& info) = 0; }; } // namespace notification diff --git a/notification-ex/event_sender_interface.h b/notification-ex/event_sender_interface.h index 8b8bb1f..3acbe0c 100644 --- a/notification-ex/event_sender_interface.h +++ b/notification-ex/event_sender_interface.h @@ -33,6 +33,7 @@ class EXPORT_API IEventSender { virtual void Notify(const IEventInfo& info, std::list serialized, std::string dest_appid = "") = 0; virtual std::list Request(const IEventInfo &info) = 0; + virtual int RequestNumber(const IEventInfo &info) = 0; }; } // namespace notification diff --git a/notification-ex/ievent_info.h b/notification-ex/ievent_info.h index 690b974..c4e13e6 100644 --- a/notification-ex/ievent_info.h +++ b/notification-ex/ievent_info.h @@ -33,6 +33,8 @@ class EXPORT_API IEventInfo { Delete, Get, Error, + Count, + DeleteAll, Custom = 100 }; virtual ~IEventInfo() = default; diff --git a/notification-ex/manager.cc b/notification-ex/manager.cc index df4847e..190d369 100644 --- a/notification-ex/manager.cc +++ b/notification-ex/manager.cc @@ -88,13 +88,17 @@ int Manager::Delete(shared_ptr noti) { } int Manager::DeleteAll() { - //TODO - return -1; + Bundle serialized; + EventInfo info(EventInfo::DeleteAll, util::GetAppId(), ""); + list serialized_list {serialized}; + impl_->sender_->Notify(info, serialized_list, util::GetAppId()); + return info.GetRequestId(); } int Manager::GetCount() const { - //TODO - return -1; + EventInfo info(EventInfo::Count, util::GetAppId(), ""); + int num = impl_->sender_->RequestNumber(info); + return num; } int Manager::Hide(shared_ptr noti) { @@ -145,6 +149,10 @@ list Manager::OnRequest(const IEventInfo& info) { return serialized_list; } +int Manager::OnRequestNumber(const IEventInfo& info) { + return OnRequestNumberEvent(info); +} + void Manager::OnEvent(const IEventInfo& info, list serialized) { shared_ptr gen_item; int type = info.GetEventType(); @@ -191,6 +199,11 @@ void Manager::OnEvent(const IEventInfo& info, list serialized) { break; case EventInfo::Error: break; + case EventInfo::Count: + break; + case EventInfo::DeleteAll: + OnDelete(info, nullptr); + break; case EventInfo::Custom: break; } @@ -215,6 +228,10 @@ list> Manager::OnRequestEvent(const IEventInfo& i return list>({}); } +int Manager::OnRequestNumberEvent(const IEventInfo& info) { + return 0; +} + string Manager::GetPath() { return NOTIFICATION_EX_MANAGER_OBJECT_PATH; } diff --git a/notification-ex/manager.h b/notification-ex/manager.h index 578a0a6..9fd69a3 100644 --- a/notification-ex/manager.h +++ b/notification-ex/manager.h @@ -48,6 +48,7 @@ class EXPORT_API Manager : public IEventObserver { int SendEvent(const IEventInfo& info, std::shared_ptr noti); void OnEvent(const IEventInfo& info, std::list serialized) override; std::list OnRequest(const IEventInfo& info) override; + int OnRequestNumber(const IEventInfo& info) override; void SendError(const IEventInfo& info, NotificationError error); int GetCount() const; static std::string GetPath(); @@ -59,6 +60,7 @@ class EXPORT_API Manager : public IEventObserver { virtual void OnError(NotificationError error, int requestId); virtual std::list> OnRequestEvent( const IEventInfo& info); + virtual int OnRequestNumberEvent(const IEventInfo& info); private: class Impl; diff --git a/notification-ex/reporter.cc b/notification-ex/reporter.cc index ed1e64e..3aaacde 100644 --- a/notification-ex/reporter.cc +++ b/notification-ex/reporter.cc @@ -97,8 +97,11 @@ int Reporter::Delete(std::shared_ptr noti) { } int Reporter::DeleteAll() { - //TODO - return -1; + Bundle serialized; + EventInfo info(EventInfo::DeleteAll, util::GetAppId(), ""); + list serialized_list {serialized}; + impl_->sender_->Notify(info, serialized_list, util::GetAppId()); + return info.GetRequestId(); } std::unique_ptr Reporter::FindByRootID(std::string id) { @@ -125,12 +128,15 @@ int Reporter::SendEvent(const IEventInfo& info, void Reporter::OnEvent(const IEventInfo& info, list serialized) { NotificationError error = (static_cast(info)).GetError(); + list> item_list; if (info.GetEventType() == EventInfo::Error) { OnError(error, info.GetRequestId()); return; + } else if (info.GetEventType() == EventInfo::DeleteAll) { + OnEvent(info, item_list); + return; } - list> item_list; for (auto& i : serialized) { shared_ptr gen_item = ItemInflator::Create(i); item_list.emplace_back(gen_item); @@ -151,6 +157,10 @@ list Reporter::OnRequest(const IEventInfo& info) { return serialized_list; } +int Reporter::OnRequestNumber(const IEventInfo& info) { + return 0; +} + void Reporter::OnEvent( const IEventInfo& info, list> notiList) { } diff --git a/notification-ex/reporter.h b/notification-ex/reporter.h index c73db6f..cf5bde6 100644 --- a/notification-ex/reporter.h +++ b/notification-ex/reporter.h @@ -55,6 +55,7 @@ class EXPORT_API Reporter : public IEventObserver { virtual void OnError(NotificationError error, int requestId); void OnEvent(const IEventInfo& info, std::list serialized) override; std::list OnRequest(const IEventInfo& info) override; + int OnRequestNumber(const IEventInfo& info) override; static std::string GetPath(); private: -- 2.7.4