Add error handling feature 08/201908/4
authorhyunho <hhstark.kang@samsung.com>
Thu, 21 Mar 2019 01:22:38 +0000 (10:22 +0900)
committerhyunho <hhstark.kang@samsung.com>
Fri, 22 Mar 2019 02:50:05 +0000 (11:50 +0900)
Change-Id: Icfb7df4ddcc021487a6ef12ac3e4bdd1bb7094e2
Signed-off-by: hyunho <hhstark.kang@samsung.com>
13 files changed:
notification-ex/common.h
notification-ex/dbus_sender.cc
notification-ex/dbus_sender.h
notification-ex/dbus_sender_implementation.h
notification-ex/event_info.cc
notification-ex/event_info_implementation.h
notification-ex/event_info_internal.h
notification-ex/ievent_info.h
notification-ex/ievent_info_internal.h
notification-ex/manager.cc
notification-ex/manager.h
notification-ex/reporter.cc
notification-ex/reporter.h

index 68e01e9ae7bac8287ace7730a4e8ace714b9b006..44228233eb21fa87462d50cc1e1f446d4b84b581 100644 (file)
@@ -17,6 +17,8 @@
 #ifndef NOTIFICATION_EX_COMMON_H_
 #define NOTIFICATION_EX_COMMON_H_
 
+#include <tizen.h>
+
 namespace notification {
 
 enum NotificationError {
index 33d99da9c99bd9c2e90e882ef9ca5434fb73d934..21952359e24e6b6681966d0e6c4c7a3523163267 100644 (file)
@@ -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<Bundle> 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<Bundle> serialized,
   GVariant* data = g_variant_new("(ssa(s))",
         appid.c_str(),
         reinterpret_cast<char*>(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);
 }
 
index 7e86e8e73062511d81fedf2ad7c6f765463f5f15..c6bf29856b6954ffc201e25078b76978cdf3042f 100644 (file)
@@ -31,7 +31,6 @@ class EXPORT_API DBusSender : public IEventSender {
  public:
   DBusSender(std::string path);
   virtual ~DBusSender();
-
   void Notify(const IEventInfo& info, std::list<Bundle> serialized,
       std::string dest_appid = "") override;
   std::list<Bundle> Request(const IEventInfo& info) override;
index b82299b05919b73ae00861a25ff35552fb4e183f..1ce5e5f7087a544e61bb1a2d07da88eb1722e7ce 100644 (file)
@@ -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_;
index 2853e6d75be07ef511e29ab205fa37ca120d0501..f88ea82a24ef0b55ca08b215f5948db0bdd42739 100644 (file)
@@ -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
index 5bd175f0d52751c96dc7043ca2884594146f257e..4e0d11e2bf2dae5700f5cfb4d02435f24ac2d86f 100644 (file)
@@ -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_;
 };
 
index 31b268e9258a5a11ce698781cf93cb5fb633e36b..90bf0c2924caed6ad850828a94d7edb5a9771588 100644 (file)
@@ -20,6 +20,7 @@
 #include <string>
 #include <list>
 
+#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;
index faf5cd0b19d5e85571da1c5c2af59e5e4f8ef6b6..89f16c7e5a236a187066b10910d0ddf13045b18d 100644 (file)
@@ -32,6 +32,7 @@ class EXPORT_API IEventInfo {
     Update,
     Delete,
     Get,
+    Error,
   };
   virtual ~IEventInfo() = default;
   virtual EventType GetEventType() const = 0;
index 15ca6ece4debd409da86e12eab34e21c2bfd18fa..15c669c1ba55868a32d6b998f613214992f8e9a2 100644 (file)
@@ -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
index 32fa9715ef7827e9be724cd1ded85e14bfa677cf..a3be6870aa50fdac0a90c94b83aa1a13e41f5830 100644 (file)
@@ -71,6 +71,14 @@ int Manager::Impl::SendNotify(shared_ptr<item::AbstractItem> noti,
   return info.GetRequestId();
 }
 
+void Manager::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 Manager::Update(shared_ptr<item::AbstractItem> noti) {
   return impl_->SendNotify(noti, EventInfo::Update);
 }
@@ -128,6 +136,14 @@ list<Bundle> Manager::OnRequest(const IEventInfo& info) {
 void Manager::OnEvent(const IEventInfo& info, list<Bundle> serialized) {
   shared_ptr<AbstractItem> gen_item;
   const IEventInfo::EventType type = info.GetEventType();
+  NotificationError error =
+      (static_cast<const IEventInfoInternal&>(info)).GetError();
+  if (error != NOTIFICATION_ERROR_NONE) {
+    LOGE("Handling error event (%d)", error);
+    OnError(error, info.GetRequestId());
+    return;
+  }
+
   switch(type) {
     case EventInfo::Post: {
       list<shared_ptr<item::AbstractItem>> added;
@@ -158,6 +174,8 @@ void Manager::OnEvent(const IEventInfo& info, list<Bundle> serialized) {
     }
     case EventInfo::Get:
       break;
+    case EventInfo::Error:
+      break;
   }
 }
 
@@ -173,6 +191,9 @@ void Manager::OnDelete(const IEventInfo& info,
       shared_ptr<item::AbstractItem> deletedItem) {
 }
 
+void Manager::OnError(NotificationError error, int requestId) {
+}
+
 list<shared_ptr<item::AbstractItem>> Manager::OnRequestEvent(const IEventInfo& info) {
   return list<shared_ptr<item::AbstractItem>>({});
 }
index d3692cad3c7fa7b88e183464174e0c6bfcf10f92..78ef7977b5f9732db824527f108141237868461f 100644 (file)
@@ -47,12 +47,14 @@ class EXPORT_API Manager : public IEventObserver {
   int SendEvent(const IEventInfo& info, std::shared_ptr<item::AbstractItem> noti);
   void OnEvent(const IEventInfo& info, std::list<Bundle> serialized) override;
   std::list<Bundle> 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<std::shared_ptr<item::AbstractItem>> addedItem);
   virtual void OnUpdate(const IEventInfo& info, std::shared_ptr<item::AbstractItem> updatedItem);
   virtual void OnDelete(const IEventInfo& info, std::shared_ptr<item::AbstractItem> deletedItem);
+  virtual void OnError(NotificationError error, int requestId);
   virtual std::list<std::shared_ptr<item::AbstractItem>> OnRequestEvent(
       const IEventInfo& info);
 
index ef5d397003d23155e8da5aa868974b65c2fe64cb..d4daf352d5bb1eaa2cbd44bcf1f3df807adca2d0 100644 (file)
@@ -64,6 +64,14 @@ int Reporter::Impl::SendNotify(shared_ptr<item::AbstractItem> noti,
   return info.GetRequestId();
 }
 
+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");
   return impl_->SendNotify(noti, EventInfo::Post);
@@ -110,6 +118,13 @@ int Reporter::SendEvent(const IEventInfo& info,
 }
 
 void Reporter::OnEvent(const IEventInfo& info, list<Bundle> serialized) {
+  NotificationError error =
+      (static_cast<const IEventInfoInternal&>(info)).GetError();
+  if (info.GetEventType() == EventInfo::Error) {
+    OnError(error, info.GetRequestId());
+    return;
+  }
+
   list<shared_ptr<item::AbstractItem>> item_list;
   for (auto& i : serialized) {
     shared_ptr<AbstractItem> gen_item = ItemInflator::Create(i);
@@ -135,6 +150,9 @@ 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;
 }
index a087d17a1f3c453aeaa71c272bdc70f3a3dad13d..5980643cbe3783f53b983b3f619ae697fcd754b8 100644 (file)
@@ -21,6 +21,7 @@
 #include <list>
 #include <memory>
 
+#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<item::AbstractItem> noti);
+  void SendError(const IEventInfo& info, NotificationError error);
   int Post(std::shared_ptr<item::AbstractItem> noti);
   int Post(std::list<std::shared_ptr<item::AbstractItem>> notiList);
   int Update(std::shared_ptr<item::AbstractItem> noti);
@@ -49,6 +51,7 @@ class EXPORT_API Reporter : public IEventObserver {
       std::list<std::shared_ptr<item::AbstractItem>> notiList);
   virtual std::list<std::shared_ptr<item::AbstractItem>> OnRequestEvent(
       const IEventInfo& info);
+  virtual void OnError(NotificationError error, int requestId);
   void OnEvent(const IEventInfo& info, std::list<Bundle> serialized) override;
   std::list<Bundle> OnRequest(const IEventInfo& info) override;
   static std::string GetPath();