From: hyunho Date: Thu, 21 Mar 2019 01:22:38 +0000 (+0900) Subject: Add error handling feature X-Git-Tag: submit/tizen/20190326.074206~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6331648ecf9301a43ed1037e398e66139c0572bf;p=platform%2Fcore%2Fapi%2Fnotification.git Add error handling feature Change-Id: Icfb7df4ddcc021487a6ef12ac3e4bdd1bb7094e2 Signed-off-by: hyunho --- diff --git a/notification-ex/common.h b/notification-ex/common.h index 68e01e9a..44228233 100644 --- a/notification-ex/common.h +++ b/notification-ex/common.h @@ -17,6 +17,8 @@ #ifndef NOTIFICATION_EX_COMMON_H_ #define NOTIFICATION_EX_COMMON_H_ +#include + namespace notification { enum NotificationError { diff --git a/notification-ex/dbus_sender.cc b/notification-ex/dbus_sender.cc index 33d99da9..21952359 100644 --- a/notification-ex/dbus_sender.cc +++ b/notification-ex/dbus_sender.cc @@ -76,11 +76,17 @@ bool DBusSender::Impl::EmitSignal(string bus_name, string signal_name, return result; } +string DBusSender::Impl::GetBusName(string appid, string dest_appid) const { + if (!DBusConnectionManager::GetInst().IsDataProviderMaster(appid)) + return DBusConnectionManager::GetInst().GetDataProviderMasterName(); + + return DBusConnectionManager::GetInst().GetBusName(dest_appid); +} + void DBusSender::Notify(const IEventInfo& info, list serialized, string dest_appid) { string signal_name = EventInfo::GetString(info.GetEventType()); string appid = util::GetAppId(); - string bus_name = ""; GVariantBuilder* builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)")); for (auto& i : serialized) { @@ -91,14 +97,9 @@ void DBusSender::Notify(const IEventInfo& info, list serialized, GVariant* data = g_variant_new("(ssa(s))", appid.c_str(), reinterpret_cast(info.Serialize().ToRaw().first.get()), builder); - if (!DBusConnectionManager::GetInst().IsDataProviderMaster(appid)) { - bus_name = DBusConnectionManager::GetInst().GetDataProviderMasterName(); - impl_->EmitSignal(bus_name, signal_name, data); - } else { - bus_name = DBusConnectionManager::GetInst().GetBusName(dest_appid); - LOGE("bus name %s, %s", dest_appid.c_str(), bus_name.c_str()); - impl_->EmitSignal(bus_name, signal_name, data); - } + string bus_name = impl_->GetBusName(appid, dest_appid); + LOGI("bus name %s, %s", dest_appid.c_str(), bus_name.c_str()); + impl_->EmitSignal(bus_name, signal_name, data); g_variant_builder_unref(builder); } diff --git a/notification-ex/dbus_sender.h b/notification-ex/dbus_sender.h index 7e86e8e7..c6bf2985 100644 --- a/notification-ex/dbus_sender.h +++ b/notification-ex/dbus_sender.h @@ -31,7 +31,6 @@ class EXPORT_API DBusSender : public IEventSender { public: DBusSender(std::string path); virtual ~DBusSender(); - void Notify(const IEventInfo& info, std::list serialized, std::string dest_appid = "") override; std::list Request(const IEventInfo& info) override; diff --git a/notification-ex/dbus_sender_implementation.h b/notification-ex/dbus_sender_implementation.h index b82299b0..1ce5e5f7 100644 --- a/notification-ex/dbus_sender_implementation.h +++ b/notification-ex/dbus_sender_implementation.h @@ -34,6 +34,8 @@ class DBusSender::Impl { Impl(DBusSender* parent, std::string path); private: + std::string GetBusName( + std::string appid, std::string dest_appid) const; bool EmitSignal(std::string bus_name, std::string signal_name, GVariant* data); GDBusMessage* MethodCall(std::string appid, std::string method_name, Bundle serialized); std::string path_; diff --git a/notification-ex/event_info.cc b/notification-ex/event_info.cc index 2853e6d7..f88ea82a 100644 --- a/notification-ex/event_info.cc +++ b/notification-ex/event_info.cc @@ -35,6 +35,7 @@ #define NOTIFICATION_EX_EVENT_TAG_KEY "__NOTIFICATION_EX_EVENT_TAG_KEY__" #define NOTIFICATION_EX_EVENT_UID_KEY "__NOTIFICATION_EX_EVENT_UID_KEY__" #define NOTIFICATION_EX_EVENT_REQUEST_ID_KEY "__NOTIFICATION_EX_EVENT_REQUEST_ID_KEY__" +#define NOTIFICATION_EX_EVENT_ERROR_KEY "__NOTIFICATION_EX_EVENT_ERROR_KEY__" using namespace std; namespace notification { @@ -53,6 +54,7 @@ EventInfo::Impl::Impl(EventInfo* parent, item_id_(item_id), tag_(tag), parent_(parent) { uid_ = getuid(); request_id_ = util::GetRequestId(); + error_ = NOTIFICATION_ERROR_NONE; LOGI("EventInfo impl created"); } @@ -69,6 +71,9 @@ EventInfo::EventInfo(Bundle serialized) string request_id_str = serialized.GetString(NOTIFICATION_EX_EVENT_REQUEST_ID_KEY); impl_->request_id_ = (int)strtol(request_id_str.c_str(), NULL, 10); + string error_str = + serialized.GetString(NOTIFICATION_EX_EVENT_ERROR_KEY); + impl_->error_ = (NotificationError)strtol(error_str.c_str(), NULL, 10); } string EventInfo::GetString(IEventInfo::EventType type) { @@ -85,6 +90,9 @@ string EventInfo::GetString(IEventInfo::EventType type) { case Get: return "Get"; break; + case Error: + return "Error"; + break; } return ""; } @@ -99,6 +107,8 @@ Bundle EventInfo::Serialize() const { serialized.Add(NOTIFICATION_EX_EVENT_UID_KEY, to_string((int)impl_->uid_)); serialized.Add( NOTIFICATION_EX_EVENT_REQUEST_ID_KEY, to_string(impl_->request_id_)); + serialized.Add( + NOTIFICATION_EX_EVENT_ERROR_KEY, to_string(impl_->error_)); return serialized; } @@ -107,6 +117,10 @@ IEventInfo::EventType EventInfo::GetEventType() const { return impl_->type_; } +void EventInfo::SetEventType(EventInfo::EventType type) { + impl_->type_ = type; +} + string EventInfo::GetOwner() const { return impl_->owner_; } @@ -135,4 +149,12 @@ int EventInfo::GetRequestId() const { return impl_->request_id_; } +NotificationError EventInfo::GetError() const { + return impl_->error_; +} + +void EventInfo::SetError(NotificationError error) { + impl_->error_ = error; +} + } // namespace notification diff --git a/notification-ex/event_info_implementation.h b/notification-ex/event_info_implementation.h index 5bd175f0..4e0d11e2 100644 --- a/notification-ex/event_info_implementation.h +++ b/notification-ex/event_info_implementation.h @@ -25,6 +25,7 @@ #include "notification-ex/dbus_sender.h" #include "notification-ex/ievent_info.h" +#include "notification-ex/common.h" namespace notification { @@ -46,6 +47,7 @@ class EventInfo::Impl { std::string tag_; uid_t uid_; int request_id_; + NotificationError error_; EventInfo* parent_; }; diff --git a/notification-ex/event_info_internal.h b/notification-ex/event_info_internal.h index 31b268e9..90bf0c29 100644 --- a/notification-ex/event_info_internal.h +++ b/notification-ex/event_info_internal.h @@ -20,6 +20,7 @@ #include #include +#include "notification-ex/common.h" #include "notification-ex/ex_bundle.h" #include "notification-ex/ievent_info_internal.h" @@ -39,7 +40,10 @@ class EventInfo : public IEventInfoInternal { virtual ~EventInfo(); uid_t GetUid() const override; void SetUid(uid_t uid) override; + NotificationError GetError() const override; + void SetError(NotificationError error) override; EventType GetEventType() const override; + void SetEventType(EventType type) override; std::string GetOwner() const override; std::string GetChannel() const override; std::string GetItemId() const override; diff --git a/notification-ex/ievent_info.h b/notification-ex/ievent_info.h index faf5cd0b..89f16c7e 100644 --- a/notification-ex/ievent_info.h +++ b/notification-ex/ievent_info.h @@ -32,6 +32,7 @@ class EXPORT_API IEventInfo { Update, Delete, Get, + Error, }; virtual ~IEventInfo() = default; virtual EventType GetEventType() const = 0; diff --git a/notification-ex/ievent_info_internal.h b/notification-ex/ievent_info_internal.h index 15ca6ece..15c669c1 100644 --- a/notification-ex/ievent_info_internal.h +++ b/notification-ex/ievent_info_internal.h @@ -17,6 +17,7 @@ #ifndef NOTIFICATION_EX_IEVENT_INFO_INTERNAL_H_ #define NOTIFICATION_EX_IEVENT_INFO_INTERNAL_H_ +#include "notification-ex/common.h" #include "notification-ex/ievent_info.h" namespace notification { @@ -26,6 +27,9 @@ class IEventInfoInternal : public IEventInfo { virtual ~IEventInfoInternal() = default; virtual uid_t GetUid() const = 0; virtual void SetUid(uid_t uid) = 0; + virtual NotificationError GetError() const = 0; + virtual void SetError(NotificationError error) = 0; + virtual void SetEventType(EventType type) = 0; }; } // namespace notification diff --git a/notification-ex/manager.cc b/notification-ex/manager.cc index 32fa9715..a3be6870 100644 --- a/notification-ex/manager.cc +++ b/notification-ex/manager.cc @@ -71,6 +71,14 @@ int Manager::Impl::SendNotify(shared_ptr noti, return info.GetRequestId(); } +void Manager::SendError(const IEventInfo& info, NotificationError error) { + list serialized_list {}; + IEventInfo& i = const_cast(info); + static_cast(i).SetError(error); + static_cast(i).SetEventType(EventInfo::Error); + impl_->sender_->Notify(info, serialized_list, info.GetOwner()); +} + int Manager::Update(shared_ptr noti) { return impl_->SendNotify(noti, EventInfo::Update); } @@ -128,6 +136,14 @@ list Manager::OnRequest(const IEventInfo& info) { void Manager::OnEvent(const IEventInfo& info, list serialized) { shared_ptr gen_item; const IEventInfo::EventType type = info.GetEventType(); + NotificationError error = + (static_cast(info)).GetError(); + if (error != NOTIFICATION_ERROR_NONE) { + LOGE("Handling error event (%d)", error); + OnError(error, info.GetRequestId()); + return; + } + switch(type) { case EventInfo::Post: { list> added; @@ -158,6 +174,8 @@ void Manager::OnEvent(const IEventInfo& info, list serialized) { } case EventInfo::Get: break; + case EventInfo::Error: + break; } } @@ -173,6 +191,9 @@ void Manager::OnDelete(const IEventInfo& info, shared_ptr deletedItem) { } +void Manager::OnError(NotificationError error, int requestId) { +} + list> Manager::OnRequestEvent(const IEventInfo& info) { return list>({}); } diff --git a/notification-ex/manager.h b/notification-ex/manager.h index d3692cad..78ef7977 100644 --- a/notification-ex/manager.h +++ b/notification-ex/manager.h @@ -47,12 +47,14 @@ 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; + void SendError(const IEventInfo& info, NotificationError error); static std::string GetPath(); protected: virtual void OnAdd(const IEventInfo& info, std::list> addedItem); virtual void OnUpdate(const IEventInfo& info, std::shared_ptr updatedItem); virtual void OnDelete(const IEventInfo& info, std::shared_ptr deletedItem); + virtual void OnError(NotificationError error, int requestId); virtual std::list> OnRequestEvent( const IEventInfo& info); diff --git a/notification-ex/reporter.cc b/notification-ex/reporter.cc index ef5d3970..d4daf352 100644 --- a/notification-ex/reporter.cc +++ b/notification-ex/reporter.cc @@ -64,6 +64,14 @@ int Reporter::Impl::SendNotify(shared_ptr noti, return info.GetRequestId(); } +void Reporter::SendError(const IEventInfo& info, NotificationError error) { + list serialized_list {}; + IEventInfo& i = const_cast(info); + static_cast(i).SetError(error); + static_cast(i).SetEventType(EventInfo::Error); + impl_->sender_->Notify(info, serialized_list, info.GetOwner()); +} + int Reporter::Post(std::shared_ptr noti) { LOGI("Post noti"); return impl_->SendNotify(noti, EventInfo::Post); @@ -110,6 +118,13 @@ int Reporter::SendEvent(const IEventInfo& info, } void Reporter::OnEvent(const IEventInfo& info, list serialized) { + NotificationError error = + (static_cast(info)).GetError(); + if (info.GetEventType() == EventInfo::Error) { + OnError(error, info.GetRequestId()); + return; + } + list> item_list; for (auto& i : serialized) { shared_ptr gen_item = ItemInflator::Create(i); @@ -135,6 +150,9 @@ void Reporter::OnEvent( const IEventInfo& info, list> notiList) { } +void Reporter::OnError(NotificationError error, int requestId) { +} + string Reporter::GetPath() { return NOTIFICATION_EX_REPORTER_OBJECT_PATH; } diff --git a/notification-ex/reporter.h b/notification-ex/reporter.h index a087d17a..5980643c 100644 --- a/notification-ex/reporter.h +++ b/notification-ex/reporter.h @@ -21,6 +21,7 @@ #include #include +#include "notification-ex/common.h" #include "notification-ex/ievent_info.h" #include "notification-ex/event_observer_interface.h" #include "notification-ex/event_sender_interface.h" @@ -40,6 +41,7 @@ class EXPORT_API Reporter : public IEventObserver { virtual ~Reporter(); int SendEvent(const IEventInfo& info, std::shared_ptr noti); + void SendError(const IEventInfo& info, NotificationError error); int Post(std::shared_ptr noti); int Post(std::list> notiList); int Update(std::shared_ptr noti); @@ -49,6 +51,7 @@ class EXPORT_API Reporter : public IEventObserver { std::list> notiList); virtual std::list> OnRequestEvent( const IEventInfo& info); + virtual void OnError(NotificationError error, int requestId); void OnEvent(const IEventInfo& info, std::list serialized) override; std::list OnRequest(const IEventInfo& info) override; static std::string GetPath();