Add manager implementation 53/201053/24
authorhyunho <hhstark.kang@samsung.com>
Thu, 7 Mar 2019 23:31:28 +0000 (08:31 +0900)
committerhyunho <hhstark.kang@samsung.com>
Tue, 19 Mar 2019 01:48:34 +0000 (10:48 +0900)
Change-Id: I9e9f26145752d8384f43634c25efac1324ddaa87
Signed-off-by: hyunho <hhstark.kang@samsung.com>
81 files changed:
notification-ex/CMakeLists.txt
notification-ex/abstract_action.cc
notification-ex/abstract_action.h
notification-ex/abstract_item.cc
notification-ex/abstract_item.h
notification-ex/abstract_item_implementation.h
notification-ex/app_control_action.cc
notification-ex/app_control_action.h
notification-ex/button_item.cc
notification-ex/button_item.h
notification-ex/chat_message_item.cc
notification-ex/chat_message_item.h
notification-ex/checkbox_item.cc
notification-ex/checkbox_item.h
notification-ex/common.h
notification-ex/dbus_connection_manager.cc [new file with mode: 0644]
notification-ex/dbus_connection_manager.h [new file with mode: 0644]
notification-ex/dbus_event_listener.cc [new file with mode: 0644]
notification-ex/dbus_event_listener.h [new file with mode: 0644]
notification-ex/dbus_event_listener_implementation.h [new file with mode: 0644]
notification-ex/dbus_listener.h [deleted file]
notification-ex/dbus_manager.h [deleted file]
notification-ex/dbus_sender.cc [new file with mode: 0644]
notification-ex/dbus_sender.h
notification-ex/dbus_sender_implementation.h [new file with mode: 0644]
notification-ex/entry_item.cc
notification-ex/entry_item.h
notification-ex/event_info.cc [new file with mode: 0644]
notification-ex/event_info.h
notification-ex/event_info_implementation.h [new file with mode: 0644]
notification-ex/event_listener_interface.h
notification-ex/event_observer_interface.h [new file with mode: 0644]
notification-ex/event_sender_interface.h
notification-ex/ex_bundle.h
notification-ex/ex_util.cc [new file with mode: 0644]
notification-ex/ex_util.h [new file with mode: 0644]
notification-ex/group_item.cc
notification-ex/group_item.h
notification-ex/icon_text_item.cc
notification-ex/icon_text_item.h
notification-ex/iitem_info_internal.h
notification-ex/image_item.cc
notification-ex/image_item.h
notification-ex/input_selector_item.cc
notification-ex/input_selector_item.h
notification-ex/item_info.cc
notification-ex/item_info_internal.h
notification-ex/manager.cc [new file with mode: 0644]
notification-ex/manager.h
notification-ex/manager_implementation.h [new file with mode: 0644]
notification-ex/mock_sender.h
notification-ex/notification-ex.pc.in
notification-ex/null_item.cc
notification-ex/null_item.h
notification-ex/observer_interface.h [deleted file]
notification-ex/progress_item.cc
notification-ex/progress_item.h
notification-ex/reporter.cc [new file with mode: 0644]
notification-ex/reporter.h [new file with mode: 0644]
notification-ex/reporter_implementation.h [new file with mode: 0644]
notification-ex/repoter.h [deleted file]
notification-ex/text_item.cc
notification-ex/text_item.h
notification-ex/time_item.cc
notification-ex/time_item.h
notification-ex/visibility_action.cc
notification-ex/visibility_action.h
packaging/notification.spec
unittest/CMakeLists.txt
unittest/src/test_button_item.cc
unittest/src/test_chat_message_item.cc
unittest/src/test_checkbox_item.cc
unittest/src/test_entry_item.cc
unittest/src/test_group_item.cc
unittest/src/test_icon_item.cc
unittest/src/test_icon_text_item.cc
unittest/src/test_image_item.cc
unittest/src/test_input_selector_item.cc
unittest/src/test_progress_item.cc
unittest/src/test_text_item.cc
unittest/src/test_time_item.cc

index cebea323822547030f72dac86988e33f3dd4c763..ea587cc435eec17b46cd9e5fc4da6b5dd188705b 100644 (file)
@@ -16,6 +16,8 @@ pkg_check_modules(notification-ex REQUIRED
        dlog
        capi-appfw-app-control
        capi-appfw-app-common
+       aul
+       uuid
 )
 
 FOREACH(flag ${notification-ex_CFLAGS})
index 7b9ec9e6a995dce66986e4a395fbf26494160e81..e37ee52efb43078ace5c3ec26cf7a18204cfdd14 100644 (file)
@@ -55,7 +55,7 @@ int AbstractAction::GetType(Bundle b) {
   return std::stoi(b.GetString(ABSTRACT_ACTION_TYPE_KEY));
 }
 
-Bundle AbstractAction::Serialize() {
+Bundle AbstractAction::Serialize() const {
   Bundle b;
 
   b.Add(ABSTRACT_ACTION_TYPE_KEY, std::to_string(GetType()));
index cb1063ddadfb7375693fbe7864435ff7b5374c83..0e001b850ceab4cd0e0255e108454a99d6a4314e 100644 (file)
@@ -46,7 +46,7 @@ class EXPORT_API AbstractAction {
 
   virtual int GetType() const = 0;
   static int GetType(Bundle b);
-  virtual Bundle Serialize() = 0;
+  virtual Bundle Serialize() const = 0;
   virtual void Deserialize(Bundle b) = 0;
   virtual bool IsLocal() const = 0;
   virtual void Execute(std::shared_ptr<AbstractItem> item) = 0;
index 0bdcdccaa2305b2022f493e04dc8fa58ae6a0be7..8e0edae87487beb84d24c0443b4c261a98b9c088 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include <dlog.h>
+#include <uuid/uuid.h>
 
 #include <memory>
 #include <algorithm>
@@ -23,6 +24,7 @@
 #include "notification-ex/abstract_item.h"
 #include "notification-ex/abstract_item_implementation.h"
 #include "notification-ex/item_info_internal.h"
+#include "notification-ex/ex_util.h"
 
 #ifdef LOG_TAG
 #undef LOG_TAG
 
 #define ABSTRACT_ITEM_TYPE_KEY "__ABSTRACT_ITEM_TYPE_KEY__"
 #define ABSTRACT_ITEM_ID_KEY "__ABSTRACT_ITEM_ID_KEY__"
+#define ABSTRACT_ITEM_SENDER_APPID_KEY "__ABSTRACT_ITEM_SENDER_APPID_KEY__"
 
 using namespace std;
 namespace notification {
 namespace item {
 
-AbstractItem::AbstractItem(std::shared_ptr<AbstractAction> action)
-    : impl_(new Impl(this, action)) {
+string AbstractItem::Impl::GenerateItemId() {
+  char uuid[37];
+  uuid_t u;
+  uuid_generate(u);
+  uuid_unparse(u, uuid);
+  string id = util::GetAppId();
+  return string(uuid) + ":" + id;
+}
+
+AbstractItem::AbstractItem(
+    std::shared_ptr<AbstractAction> action)
+  : impl_(new Impl(this, action)) {
 }
 
 AbstractItem::AbstractItem(std::string id,
     std::shared_ptr<AbstractAction> action)
-    : impl_(new Impl(this, id, action)) {
+  : impl_(new Impl(this, id, action)) {
 }
 
 AbstractItem::Impl::Impl(AbstractItem* parent, string id,
     std::shared_ptr<AbstractAction> action)
-    : id_(id), action_(action), parent_(parent),
+  : id_(id), action_(action), parent_(parent),
     info_(std::make_shared<ItemInfo>(this)) {
-  LOGI("Item created");
+
+  if (id_.empty())
+    id_ = GenerateItemId();
+  sender_appid_ = util::GetAppId();
+  LOGI("GroupItem created (%s)", id_.c_str());
 }
 
 AbstractItem::Impl::Impl(AbstractItem* parent,
     std::shared_ptr<AbstractAction> action)
-    : action_(action), parent_(parent),
+  : action_(action), parent_(parent),
     info_(std::make_shared<ItemInfo>(this)) {
-  LOGI("Item created");
+  LOGI("GroupItem created");
+
+  id_ = GenerateItemId();
+  sender_appid_ = util::GetAppId();
+  LOGI("GroupItem created (%s)", id_.c_str());
 }
 
 AbstractItem::~AbstractItem() = default;
 
-Bundle AbstractItem::Serialize() {
+Bundle AbstractItem::Serialize() const {
   Bundle b;
   b.Add(ABSTRACT_ITEM_TYPE_KEY, to_string(GetType()));
   b.Add(ABSTRACT_ITEM_ID_KEY, impl_->id_);
+  b.Add(ABSTRACT_ITEM_SENDER_APPID_KEY, GetSenderAppId().c_str());
   return b;
 }
 
@@ -76,6 +98,7 @@ void AbstractItem::Deserialize(Bundle b) {
 
   string id_str = b.GetString(ABSTRACT_ITEM_ID_KEY);
   impl_->id_ = id_str;
+  impl_->sender_appid_ = b.GetString(ABSTRACT_ITEM_SENDER_APPID_KEY);
 }
 
 string AbstractItem::GetId() const {
@@ -125,7 +148,13 @@ void AbstractItem::RemoveReceiver(std::string receiver_group) {
   impl_->receiver_group_list_.remove(receiver_group);
 }
 
+list<string> AbstractItem::GetReceiverList() {
+  return impl_->receiver_group_list_;
+}
+
 bool AbstractItem::CanReceive(std::string id) const {
+  if (impl_->receiver_group_list_.size() == 0)
+    return true;
   list<string>::iterator iter =
     std::find(impl_->receiver_group_list_.begin(),
       impl_->receiver_group_list_.end(), id);
@@ -155,15 +184,42 @@ void AbstractItem::SetChannel(string channel) {
 void AbstractItem::SetSoundPath(std::string path) {
   impl_->sound_path_ = path;
 }
+
 void AbstractItem::SetVibrationPath(std::string path) {
   impl_->vibration_path_ = path;
 }
+
 std::string AbstractItem::GetSoundPath() const {
   return impl_->sound_path_;
 }
+
 std::string AbstractItem::GetVibrationPath() const {
   return impl_->vibration_path_;
 }
 
+std::string AbstractItem::GetSenderAppId() const {
+  return impl_->sender_appid_;
+}
+
+void AbstractItem::SetSenderAppId(std::string sender_appid) {
+  impl_->sender_appid_ = sender_appid;
+}
+
+time_t AbstractItem::GetTime() {
+  return impl_->time_;
+}
+
+int AbstractItem::GetUid() {
+  return impl_->uid_;
+}
+
+void AbstractItem::SetUid(int uid) {
+  impl_->uid_ = uid;
+}
+
+int AbstractItem::GetRequestId() {
+  return impl_->request_id_;
+}
+
 }  // namespace item
 }  // namespace notification
index e5b5e7f6ce3339af35cfe880fcc1ee2b146bec09..043f6a11f290178715c5da34b75d9f620f1e075e 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <memory>
 #include <string>
+#include <list>
 
 #include "notification-ex/abstract_action.h"
 #include "notification-ex/ex_bundle.h"
@@ -191,12 +192,12 @@ class EXPORT_API AbstractItem {
   };
 
  public:
-  AbstractItem(std::shared_ptr<AbstractAction> action =
-      std::shared_ptr<AbstractAction>({}));
-  AbstractItem(std::string id, std::shared_ptr<AbstractAction> action =
-      std::shared_ptr<AbstractAction>({}));
+  AbstractItem(
+      std::shared_ptr<AbstractAction> action = std::shared_ptr<AbstractAction>({}));
+  AbstractItem(std::string id,
+      std::shared_ptr<AbstractAction> action = std::shared_ptr<AbstractAction>({}));
   virtual ~AbstractItem() = 0;
-  virtual Bundle Serialize() = 0;
+  virtual Bundle Serialize() const = 0;
   virtual void Deserialize(Bundle b) = 0;
   virtual AbstractItem& FindByID(std::string id) = 0;
   virtual int GetType() const = 0;
@@ -211,6 +212,7 @@ class EXPORT_API AbstractItem {
   void SetEnable(bool enable);
   void AddReceiver(std::string receiver_group);
   void RemoveReceiver(std::string receiver_group);
+  std::list<std::string> GetReceiverList();
   bool CanReceive(std::string id) const;
   void SetPolicy(Policy policy);
   Policy GetPolicy() const;
@@ -223,6 +225,14 @@ class EXPORT_API AbstractItem {
   std::string GetSoundPath() const;
   std::string GetVibrationPath() const;
   std::shared_ptr<IItemInfo> GetInfo() const;
+  std::string GetSenderAppId() const;
+  void SetSenderAppId(std::string sender_appid);
+  std::string GetTag();
+  void SetTag();
+  time_t GetTime();
+  int GetUid();
+  void SetUid(int uid);
+  int GetRequestId();
 
  private:
   class Impl;
index 4f4b94208fd8eeefca67b4c3b7ec54a991fc87f8..eaada761ad70aa70d11070a42ca1f3408c477141 100644 (file)
@@ -33,14 +33,14 @@ class AbstractItem::Impl {
 
  private:
   Impl(AbstractItem* parent);
-  Impl(AbstractItem* parent, std::shared_ptr<AbstractAction> action =
-      std::shared_ptr<AbstractAction>({}));
+  Impl(AbstractItem* parent,
+      std::shared_ptr<AbstractAction> action = std::shared_ptr<AbstractAction>({}));
   Impl(AbstractItem* parent, std::string id,
-      std::shared_ptr<AbstractAction> action =
-          std::shared_ptr<AbstractAction>({}));
+      std::shared_ptr<AbstractAction> action = std::shared_ptr<AbstractAction>({}));
 
  private:
   friend class AbstractItem;
+  std::string GenerateItemId();
   std::string channel_;
   std::string id_;
   std::shared_ptr<LEDInfo> led_ = nullptr;
@@ -57,7 +57,13 @@ class AbstractItem::Impl {
   AbstractItem* parent_;
   std::string sound_path_;
   std::string vibration_path_;
+  std::string sender_appid_;
   std::shared_ptr<IItemInfo> info_;
+  std::list<std::string> hide_viewer_list_;
+  std::string tag_;
+  time_t time_ = 0;
+  int uid_ = 0;
+  int request_id_ = 0;
 };
 
 }  // namespace item
index df2ec90e2e023ce2fb56703ac4c6fdf66b88360f..5108c11280a2ca77ea9ed5e9fcc0abb9d289831d 100644 (file)
@@ -60,7 +60,7 @@ int AppControlAction::GetType() const {
   return AbstractAction::AppControl;
 }
 
-Bundle AppControlAction::Serialize() {
+Bundle AppControlAction::Serialize() const {
   Bundle b;
   bundle* control_b = NULL;
   bundle_raw* control_raw;
index 0839eb068bc3faeb1c08372fcf78e9464688e3fb..6d53e9254c7d16c8ac8640d51dd47e47e23c53c5 100644 (file)
@@ -31,7 +31,7 @@ class EXPORT_API AppControlAction : public AbstractAction {
   virtual ~AppControlAction();
 
   int GetType() const override;
-  Bundle Serialize() override;
+  Bundle Serialize() const override;
   void Deserialize(Bundle b) override;
   bool IsLocal() const override;
   void Execute(std::shared_ptr<AbstractItem> item) override;
index 284b806e3613442dca4f58f68782a13354437a66..3042d35b5fc2e42d8dc7cc885f8cb86d923f749b 100644 (file)
@@ -54,7 +54,7 @@ int ButtonItem::GetType() const {
   return AbstractItem::Button;
 }
 
-Bundle ButtonItem::Serialize() {
+Bundle ButtonItem::Serialize() const {
   Bundle b;
   b = AbstractItem::Serialize();
   b.Add(BUTTON_TITLE_KEY, impl_->title_);
index 6f459d21dec1c63f9a17f018110bacecb3fd6e1d..6cfd30d7e69ad67825052261be169d5d937ccdff 100644 (file)
@@ -34,7 +34,7 @@ class EXPORT_API ButtonItem : public AbstractItem {
       std::shared_ptr<AbstractAction> action = std::shared_ptr<AbstractAction>({}));
   virtual ~ButtonItem();
 
-  Bundle Serialize() override;
+  Bundle Serialize() const override;
   void Deserialize(Bundle b) override;
   AbstractItem& FindByID(std::string id) override;
   int GetType() const override;
index 1970a8721c4946ae4d255054865f58134251b6a1..2a94bb1e06b5f24b4487bb3f178951fe7c6b60aa 100644 (file)
@@ -53,7 +53,7 @@ int ChatMessageItem::GetType() const {
   return AbstractItem::ChatMessage;
 }
 
-Bundle ChatMessageItem::Serialize() {
+Bundle ChatMessageItem::Serialize() const {
   Bundle b;
   b = AbstractItem::Serialize();
 
index 1321b0bf1bfcc39e28b3f6ddef7ca455461b8fbe..4ccf3138881078f9713e93b42dee66c4d2477702 100644 (file)
@@ -45,7 +45,7 @@ class EXPORT_API ChatMessageItem : public AbstractItem {
   virtual ~ChatMessageItem();
   int GetType() const override;
 
-  Bundle Serialize() override;
+  Bundle Serialize() const override;
   void Deserialize(Bundle b) override;
   AbstractItem& FindByID(std::string id) override;
   TextItem& GetNameItem() const;
index 97cba9658cf5d2b452663f00ad373207cec5662d..7fb48733deefbe201d3bc6d4f6c1f9c54606e2a2 100644 (file)
@@ -46,7 +46,7 @@ int CheckBoxItem::GetType() const {
   return AbstractItem::CheckBox;
 }
 
-Bundle CheckBoxItem::Serialize() {
+Bundle CheckBoxItem::Serialize() const {
   Bundle b;
 
   b = AbstractItem::Serialize();
index 27c9fbd249f2ec91272c2bbab8fe76fbe75db811..6eab2ead05ba9a9eb27cec952e09550cd0bc3b97 100644 (file)
@@ -32,7 +32,7 @@ class EXPORT_API CheckBoxItem : public AbstractItem {
     std::shared_ptr<AbstractAction> action = std::shared_ptr<AbstractAction>({}));
   virtual ~CheckBoxItem();
 
-  Bundle Serialize() override;
+  Bundle Serialize() const override;
   void Deserialize(Bundle b) override;
   AbstractItem& FindByID(std::string id) override;
   int GetType() const override;
index 8a0a67da14c07e73d8e7b3317ee072bbefbe9358..68e01e9ae7bac8287ace7730a4e8ace714b9b006 100644 (file)
@@ -19,7 +19,7 @@
 
 namespace notification {
 
-typedef enum _notification_error {
+enum NotificationError {
  NOTIFICATION_ERROR_NONE = TIZEN_ERROR_NONE, /**< Success */
  NOTIFICATION_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
  NOTIFICATION_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
@@ -32,7 +32,7 @@ typedef enum _notification_error {
  NOTIFICATION_ERROR_NOT_EXIST_ID = TIZEN_ERROR_NOTIFICATION | 0x04, /**< Not exist private ID */
  NOTIFICATION_ERROR_SERVICE_NOT_READY = TIZEN_ERROR_NOTIFICATION | 0x05, /**< No response from notification service */
  NOTIFICATION_ERROR_MAX_EXCEEDED = TIZEN_ERROR_NOTIFICATION | 0x06, /**< Max notification count exceeded (@b Since: 3.0) */
-} notification_error_e;
+};
 
 }  // namespace notification
 
diff --git a/notification-ex/dbus_connection_manager.cc b/notification-ex/dbus_connection_manager.cc
new file mode 100644 (file)
index 0000000..5c2abe8
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dlog.h>
+#include <glib.h>
+
+#include "notification-ex/exception.h"
+#include "notification-ex/dbus_connection_manager.h"
+#include "notification-ex/ex_util.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "NOTIFICATION_EX"
+
+#define NOTIFICATION_EX_BUS_NAME_PREFIX "org.tizen.notification_ex._"
+#define NOTIFICATION_EX_INTERFACE "org.tizen.notification_ex"
+#define DATA_PROVIDER_MASTER_ID "data-provider-master"
+
+using namespace std;
+namespace notification {
+
+DBusConnectionManager::DBusConnectionManager() = default;
+DBusConnectionManager::~DBusConnectionManager() = default;
+DBusConnectionManager& DBusConnectionManager::GetInst() {
+  static DBusConnectionManager w_inst;
+  int ret;
+  if (w_inst.connection_ == nullptr) {
+    ret = w_inst.Init();
+    if (ret != NOTIFICATION_ERROR_NONE)
+      THROW(ret);
+  }
+  return w_inst;
+}
+
+bool DBusConnectionManager::IsDataProviderMaster() const {
+  return is_DPM_;
+}
+
+bool DBusConnectionManager::IsDataProviderMaster(string appid) const {
+  if (appid == DATA_PROVIDER_MASTER_ID)
+    return true;
+  return false;
+}
+
+string DBusConnectionManager::GetDataProviderMasterName() const {
+  return GetBusName(DATA_PROVIDER_MASTER_ID);
+}
+
+string DBusConnectionManager::GetInterfaceName() const {
+  return NOTIFICATION_EX_INTERFACE;
+}
+
+GDBusConnection* DBusConnectionManager::GetConnection() {
+  return connection_;
+}
+
+std::string DBusConnectionManager::GetBusName(string appid) const {
+  if (appid.empty())
+    return "";
+
+  if (IsDataProviderMaster(appid))
+    return string(NOTIFICATION_EX_BUS_NAME_PREFIX) + DATA_PROVIDER_MASTER_ID;
+
+  char* encoded_str = g_compute_checksum_for_string(G_CHECKSUM_MD5,
+                appid.c_str(), -1);
+  if (encoded_str == NULL)
+    return "";
+
+  return string(NOTIFICATION_EX_BUS_NAME_PREFIX) + encoded_str;
+}
+
+int DBusConnectionManager::Init() {
+  GError* error = nullptr;
+  connection_ = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+  if (connection_ == NULL) {
+    if (error != NULL) {
+      LOGE("Failed to get dbus [%s]", error->message);
+      g_error_free(error);
+    }
+    return NOTIFICATION_ERROR_IO_ERROR;
+  }
+
+  string appid = util::GetAppId();
+  if (appid.empty())
+    return NOTIFICATION_ERROR_IO_ERROR;
+
+  if (IsDataProviderMaster(appid))
+    is_DPM_ = true;
+
+  string encoded_name = GetBusName(appid);
+  LOGI("own name %s", encoded_name.c_str());
+  int owner_id = g_bus_own_name_on_connection(connection_, encoded_name.c_str(),
+                                          G_BUS_NAME_OWNER_FLAGS_NONE,
+                                          NULL, NULL, NULL, NULL);
+  if (!owner_id) {
+    g_object_unref(connection_);
+    LOGE("g_bus_own_name_on_connection, error");
+    return NOTIFICATION_ERROR_IO_ERROR;
+  }
+  return NOTIFICATION_ERROR_NONE;
+}
+
+}  // nampace notification
\ No newline at end of file
diff --git a/notification-ex/dbus_connection_manager.h b/notification-ex/dbus_connection_manager.h
new file mode 100644 (file)
index 0000000..9b37f09
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef NOTIFICATION_EX_DBUS_MANAGER_H_
+#define NOTIFICATION_EX_DBUS_MANAGER_H_
+
+#include <gio/gio.h>
+
+#include <string>
+
+#include "notification-ex/ex_bundle.h"
+
+namespace notification {
+
+class EXPORT_API DBusConnectionManager {
+ public:
+  static DBusConnectionManager& GetInst();
+  GDBusConnection* GetConnection();
+  bool IsDataProviderMaster(std::string appid) const;
+  std::string GetDataProviderMasterName() const;
+  std::string GetInterfaceName() const;
+  std::string GetBusName(std::string appid) const;
+
+ private:
+  bool IsDataProviderMaster() const;
+  DBusConnectionManager();
+  ~DBusConnectionManager();
+  int Init();
+  GDBusConnection* connection_ = nullptr;
+  bool is_DPM_ = false;
+};
+
+}  // namespace notification
+
+#endif  // NOTIFICATION_EX_DBUS_MANAGER_H_
diff --git a/notification-ex/dbus_event_listener.cc b/notification-ex/dbus_event_listener.cc
new file mode 100644 (file)
index 0000000..455ce93
--- /dev/null
@@ -0,0 +1,218 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dlog.h>
+#include <glib.h>
+#include <unistd.h>
+
+#include "notification-ex/dbus_connection_manager.h"
+#include "notification-ex/dbus_event_listener.h"
+#include "notification-ex/dbus_event_listener_implementation.h"
+#include "notification-ex/exception.h"
+#include "notification-ex/ex_util.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "NOTIFICATION_EX"
+
+#define MAX_PACKAGE_STR_SIZE 512
+
+using namespace std;
+namespace notification {
+
+DBusEventListener::DBusEventListener(string path)
+  : impl_(new Impl(this, path)) {
+  LOGW("Created (%s)", path.c_str());
+}
+
+DBusEventListener::~DBusEventListener() {
+  LOGW("Destroyed");
+}
+
+DBusEventListener::Impl::~Impl() = default;
+
+DBusEventListener::Impl::Impl(DBusEventListener* parent, string path)
+  : subscribe_id_(0), registration_id_(0), path_(path), parent_(parent) {
+  LOGI("ButtonItem impl created");
+}
+
+void DBusEventListener::Impl::SignalCb(GDBusConnection* connection,
+                      const gchar* sender_name,
+                      const gchar* object_path,
+                      const gchar* interface_name,
+                      const gchar* signal_name,
+                      GVariant* parameters,
+                      void* user_data) {
+  DBusEventListener* dl = static_cast<DBusEventListener*>(user_data);
+  char* appid = nullptr;
+  GVariantIter *iter = nullptr;
+  char* event_info_raw = nullptr;
+  g_variant_get(parameters, "(ssa(s))", &appid, &event_info_raw, &iter);
+
+  LOGI("signal callback!! (%s)", appid);
+  string sender_appid = string(appid);
+  string cur_appid = util::GetAppId();
+  if (sender_appid == cur_appid)
+    return;
+  if ((!DBusConnectionManager::GetInst().IsDataProviderMaster(cur_appid)
+    && !DBusConnectionManager::GetInst().IsDataProviderMaster(sender_appid))
+    || (cur_appid == sender_appid))
+    return;
+
+  LOGE("%s : %s", cur_appid.c_str(), sender_appid.c_str());
+
+  char* raw = nullptr;
+  list<Bundle> ret_list;
+  while (g_variant_iter_loop(iter, "(s)", &raw) && raw != nullptr) {
+    Bundle ret(raw);
+    ret_list.emplace_back(ret);
+  }
+
+  Bundle b(event_info_raw);
+  EventInfo info(b);
+  dl->NotifyObserver(info, ret_list);
+}
+
+void DBusEventListener::Impl::OnMethodCall(
+    GDBusConnection *conn, const gchar *sender, const gchar *object_path,
+    const gchar *iface_name, const gchar *method_name,
+    GVariant *parameters, GDBusMethodInvocation *invocation,
+    gpointer user_data) {
+  LOGI("method_name[%s] sender[%s]", method_name, sender);
+  DBusEventListener* dl = static_cast<DBusEventListener*>(user_data);
+  GVariant *reply_body = NULL;
+  if (g_strcmp0(method_name, "Get") == 0) {
+    char* appid = NULL;
+    char* serialized = NULL;
+    g_variant_get(parameters, "(&s&s)", &appid, &serialized);
+
+    Bundle b(serialized);
+    EventInfo info(b);
+    list<Bundle> result = dl->NotifyObserver(info);
+    GVariantBuilder* builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
+    for (auto& i : result) {
+      g_variant_builder_add(builder, "(s)",
+          reinterpret_cast<char*>(i.ToRaw().first.get()));
+    }
+    reply_body = g_variant_new("(a(s))", builder);
+    g_variant_builder_unref(builder);
+  }
+  g_dbus_method_invocation_return_value(invocation, reply_body);
+}
+
+int DBusEventListener::Impl::RegisterGDBusInterface() {
+  static const GDBusInterfaceVTable interface_vtable = {
+    OnMethodCall,
+    nullptr,
+    nullptr
+  };
+  static gchar introspection_xml[] =
+    "  <node>"
+    "  <interface name='org.tizen.notification_ex'>"
+    "        <method name='Get'>"
+    "          <arg type='s' name='appid' direction='in'/>"
+    "          <arg type='s' name='serialized' direction='in'/>"
+    "          <arg type='a(s)' name='noti_arr' direction='out'/>"
+    "        </method>"
+    "  </interface>"
+    "  </node>";
+  GError *error = NULL;
+  GDBusNodeInfo *introspection_data =
+      g_dbus_node_info_new_for_xml(introspection_xml, &error);
+  if (!introspection_data) {
+    LOGE("g_dbus_node_info_new_for_xml is failed.");
+    if (error != NULL) {
+      LOGE("g_dbus_node_info_new_for_xml err [%s]", error->message);
+      g_error_free(error);
+    }
+    return NOTIFICATION_ERROR_IO_ERROR;
+  }
+
+  registration_id_ = g_dbus_connection_register_object(
+      DBusConnectionManager::GetInst().GetConnection(),
+      path_.c_str(), introspection_data->interfaces[0],
+      &interface_vtable, this, NULL, NULL);
+  g_dbus_node_info_unref(introspection_data);
+  if (registration_id_ == 0) {
+    LOGE("register object fail");
+    return NOTIFICATION_ERROR_IO_ERROR;
+  }
+
+  LOGI("RegisterGDBusInterface success");
+  return NOTIFICATION_ERROR_NONE;
+}
+
+void DBusEventListener::Impl::UnRegisterGDBusInterface() {
+  g_dbus_connection_unregister_object(
+        DBusConnectionManager::GetInst().GetConnection(),
+        registration_id_);
+}
+
+bool DBusEventListener::Impl::SubscribeSignal() {
+  subscribe_id_ = g_dbus_connection_signal_subscribe(
+                    DBusConnectionManager::GetInst().GetConnection(),
+                    NULL,
+                    DBusConnectionManager::GetInst().GetInterfaceName().c_str(),
+                    NULL,
+                    path_.c_str(),
+                    NULL,
+                    G_DBUS_SIGNAL_FLAGS_NONE,
+                    SignalCb,
+                    this,
+                    NULL);
+  return subscribe_id_ > 0;
+}
+
+void DBusEventListener::Impl::UnSubscribeSignal() {
+  g_dbus_connection_signal_unsubscribe(
+      DBusConnectionManager::GetInst().GetConnection(), subscribe_id_);
+  subscribe_id_ = 0;
+}
+
+void DBusEventListener::RegisterObserver(IEventObserver* observer) {
+  if (impl_->subscribe_id_ == 0) {
+    impl_->SubscribeSignal();
+  } else {
+    impl_->UnSubscribeSignal();
+    impl_->SubscribeSignal();
+  }
+
+  if (impl_->registration_id_ == 0) {
+    impl_->RegisterGDBusInterface();
+  } else {
+    impl_->UnRegisterGDBusInterface();
+    impl_->RegisterGDBusInterface();
+  }
+  impl_->observer_ = observer;
+}
+
+void DBusEventListener::UnRegisterObserver(IEventObserver* observer) {
+  impl_->UnSubscribeSignal();
+  impl_->observer_ = NULL;
+}
+
+void DBusEventListener::NotifyObserver(
+    const EventInfo& info, list<Bundle> serialized) {
+  impl_->observer_->OnEvent(info, serialized);
+}
+
+list<Bundle> DBusEventListener::NotifyObserver(const EventInfo& info) {
+  return impl_->observer_->OnRequest(info);
+}
+
+}  // nampace notification
\ No newline at end of file
diff --git a/notification-ex/dbus_event_listener.h b/notification-ex/dbus_event_listener.h
new file mode 100644 (file)
index 0000000..bea87d7
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef NOTIFICATION_EX_DBUS_LISTENER_H_
+#define NOTIFICATION_EX_DBUS_LISTENER_H_
+
+#include <gio/gio.h>
+
+#include "notification-ex/event_listener_interface.h"
+
+namespace notification {
+
+class EXPORT_API DBusEventListener : public IEventListener {
+ public:
+  DBusEventListener(std::string path);
+  ~DBusEventListener();
+
+  void RegisterObserver(IEventObserver* observer) override;
+  void UnRegisterObserver(IEventObserver* observer) override;
+  void NotifyObserver(
+      const EventInfo& info, std::list<Bundle> serialized) override;
+  std::list<Bundle> NotifyObserver(const EventInfo& info) override;
+
+ private:
+  class Impl;
+  std::unique_ptr<Impl> impl_;
+};
+
+}  // namespace notification
+
+#endif  // NOTIFICATION_EX_DBUS_LISTENER_H_
diff --git a/notification-ex/dbus_event_listener_implementation.h b/notification-ex/dbus_event_listener_implementation.h
new file mode 100644 (file)
index 0000000..feff2a3
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef NOTIFICATION_EX_DBUS_EVENT_LISTENER_IMPLEMENTATION_H_
+#define NOTIFICATION_EX_DBUS_EVENT_LISTENER_IMPLEMENTATION_H_
+
+#include <string>
+#include <memory>
+#include <list>
+
+#include "notification-ex/dbus_event_listener.h"
+
+namespace notification {
+
+class DBusEventListener::Impl {
+ public:
+  virtual ~Impl();
+
+ private:
+  friend class DBusEventListener;
+  Impl(DBusEventListener* parent, std::string path);
+
+ private:
+  void UnRegisterGDBusInterface();
+  int RegisterGDBusInterface();
+  static void OnMethodCall(
+    GDBusConnection *conn, const gchar *sender, const gchar *object_path,
+    const gchar *iface_name, const gchar *method_name,
+    GVariant *parameters, GDBusMethodInvocation *invocation,
+    gpointer user_data);
+
+  static GDBusInterfaceVTable InterfaceVtable;
+  static void SignalCb(GDBusConnection* connection,
+                      const gchar* sender_name,
+                      const gchar* object_path,
+                      const gchar* interface_name,
+                      const gchar* signal_name,
+                      GVariant* parameters,
+                      void* user_data);
+  bool SubscribeSignal();
+  void UnSubscribeSignal();
+  IEventObserver* observer_ = nullptr;
+  int subscribe_id_;
+  int registration_id_;
+  std::string path_;
+  DBusEventListener* parent_;
+};
+
+}  // nampace notification
+#endif  // NOTIFICATION_EX_DBUS_EVENT_LISTENER_IMPLEMENTATION_H_
diff --git a/notification-ex/dbus_listener.h b/notification-ex/dbus_listener.h
deleted file mode 100644 (file)
index e0ad60a..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef NOTIFICATION_EX_DBUS_LISTENER_H_
-#define NOTIFICATION_EX_DBUS_LISTENER_H_
-
-#include "notification-ex/observer_interface.h"
-
-namespace notification {
-
-class EXPORT_API DBusEventsListener : public IEventListener {
- public:
-  DBusEventsListener();
-  ~DBusEventsListener();
-
-  void RegisterObserver(IEventObserver observer) override;
-  void UnRegisterObserver(IEventObserver observer) override;
-  void NotifyAll() override;
-};
-
-}  // namespace notification
-
-#endif  // NOTIFICATION_EX_DBUS_LISTENER_H_
diff --git a/notification-ex/dbus_manager.h b/notification-ex/dbus_manager.h
deleted file mode 100644 (file)
index 8c1943d..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef NOTIFICATION_EX_DBUS_MANAGER_H_
-#define NOTIFICATION_EX_DBUS_MANAGER_H_
-
-#include <string>
-
-namespace notification {
-
-class DBusConnectionManager {
- public:
-  static DBusConnectionManager& GetInst();
-  GDbusConnection& GetConnection();
-
- private:
-  DBusConnectionManager();
-  ~DBusConnectionManager();
-  GDbusConnection connection_;
-};
-
-}  // namespace notification
-
-#endif  // NOTIFICATION_EX_DBUS_MANAGER_H_
diff --git a/notification-ex/dbus_sender.cc b/notification-ex/dbus_sender.cc
new file mode 100644 (file)
index 0000000..c3e9991
--- /dev/null
@@ -0,0 +1,156 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dlog.h>
+#include <glib.h>
+#include <unistd.h>
+
+#include <list>
+
+#include "notification-ex/dbus_connection_manager.h"
+#include "notification-ex/dbus_sender.h"
+#include "notification-ex/dbus_sender_implementation.h"
+#include "notification-ex/event_info.h"
+#include "notification-ex/ex_util.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "NOTIFICATION_EX"
+
+#define MAX_PACKAGE_STR_SIZE 512
+
+using namespace std;
+namespace notification {
+
+DBusSender::DBusSender(string path)
+  : impl_(new Impl(this, path)) {
+  LOGW("Created (%s)", path.c_str());
+}
+
+DBusSender::Impl::~Impl() = default;
+
+DBusSender::Impl::Impl(DBusSender* parent, string path)
+  : path_(path), parent_(parent) {
+  LOGI("ButtonItem impl created");
+}
+
+DBusSender::~DBusSender() {
+  LOGW("Destroyed");
+}
+
+bool DBusSender::Impl::EmitSignal(string bus_name,
+    string signal_name, GVariant* data) {
+  GError* err = NULL;
+  gboolean result = TRUE;
+
+  result = g_dbus_connection_emit_signal(
+              DBusConnectionManager::GetInst().GetConnection(),
+              bus_name.empty() ? NULL : bus_name.c_str(),
+              path_.c_str(),
+              DBusConnectionManager::GetInst().GetInterfaceName().c_str(),
+              signal_name.c_str(), data, &err);
+  if (result == FALSE) {
+    LOGE("g_dbus_connection_emit_signal() is failed");
+    if (err != NULL) {
+      LOGE("g_dbus_connection_emit_signal() err : %s",
+        err->message);
+      g_error_free(err);
+    }
+  } else {
+    LOGI("Successfully emit signal to %s, %s, %s",
+      bus_name.c_str(), path_.c_str(), signal_name.c_str());
+  }
+  return result;
+}
+
+void DBusSender::Notify(const EventInfo& 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) {
+    g_variant_builder_add(builder, "(s)",
+        reinterpret_cast<char*>(i.ToRaw().first.get()));
+  }
+
+  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);
+  }
+  g_variant_builder_unref(builder);
+}
+
+GDBusMessage* DBusSender::Impl::MethodCall(string appid,
+    string method_name, Bundle serialized) {
+  GError* err = nullptr;
+  GDBusMessage* msg = g_dbus_message_new_method_call(
+      DBusConnectionManager::GetInst().GetDataProviderMasterName().c_str(),
+      path_.c_str(),
+      DBusConnectionManager::GetInst().GetInterfaceName().c_str(),
+      method_name.c_str());
+  if (!msg) {
+    LOGE("Can't allocate new method call");
+    return nullptr;
+  }
+
+  g_dbus_message_set_body(msg,
+      g_variant_new("(ss)",
+        appid.c_str(),
+        reinterpret_cast<char*>(serialized.ToRaw().first.get())
+      )
+  );
+
+  LOGI("send message !! (%s) (%s) (%s)",
+      path_.c_str(), method_name.c_str(), appid.c_str());
+  GDBusMessage* reply = g_dbus_connection_send_message_with_reply_sync(
+      DBusConnectionManager::GetInst().GetConnection(), msg,
+      G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &err);
+
+  return reply;
+}
+
+std::list<Bundle> DBusSender::Request(const EventInfo& 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);
+
+  GVariantIter *iter = nullptr;
+  list<Bundle> ret_list;
+  g_variant_get(reply_body, "(a(s))", &iter);
+  char* raw = nullptr;
+  while (g_variant_iter_loop(iter, "(s)", &raw) && raw != nullptr) {
+    Bundle ret(raw);
+    ret_list.emplace_back(ret);
+  }
+
+  return ret_list;
+}
+
+}  // nampace notification
\ No newline at end of file
index b8063be041adb210a1c5dab233ae0ca3457505c1..a347bcf488a3f68343e052ac08ccc16465be4e91 100644 (file)
 #ifndef NOTIFICATION_EX_DBUS_SENDER_H_
 #define NOTIFICATION_EX_DBUS_SENDER_H_
 
+#include <gio/gio.h>
+
 #include "notification-ex/ex_bundle.h"
+#include "notification-ex/event_sender_interface.h"
+#include "notification-ex/event_info.h"
 
 #ifndef EXPORT_API
 #define EXPORT_API __attribute__((visibility("default")))
 
 namespace notification {
 
-class EXPORT_API DBusSender : public IEventsSender {
+class EXPORT_API DBusSender : public IEventSender {
  public:
-  DBusSender();
+  DBusSender(std::string path);
   virtual ~DBusSender();
 
-  void Notify(Bundle serialized) override;
+  void Notify(const EventInfo& info, std::list<Bundle> serialized,
+      std::string dest_appid = "") override;
+  std::list<Bundle> Request(const EventInfo& info) override;
+
+ private:
+  class Impl;
+  std::unique_ptr<Impl> impl_;
 };
 
 }  // namespace notification
diff --git a/notification-ex/dbus_sender_implementation.h b/notification-ex/dbus_sender_implementation.h
new file mode 100644 (file)
index 0000000..e0b61c9
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef NOTIFICATION_EX_DBUS_SENDER_IMPLEMENTATION_H_
+#define NOTIFICATION_EX_DBUS_SENDER_IMPLEMENTATION_H_
+
+#include <string>
+#include <memory>
+#include <list>
+
+#include "notification-ex/dbus_sender.h"
+
+namespace notification {
+
+class DBusSender::Impl {
+ public:
+  virtual ~Impl();
+
+ private:
+  friend class DBusSender;
+  Impl(DBusSender* parent, std::string path);
+
+ private:
+  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_;
+  DBusSender* parent_;
+};
+
+}  // nampace notification
+#endif  // NOTIFICATION_EX_DBUS_SENDER_IMPLEMENTATION_H_
\ No newline at end of file
index 29bf5fc7f802a08209b96bf2b5eacbc91d3f368b..dd62de0167b8be195fb0e69d7d53eee681a7dfff 100644 (file)
@@ -53,7 +53,7 @@ int EntryItem::GetType() const {
   return AbstractItem::Entry;
 }
 
-Bundle EntryItem::Serialize() {
+Bundle EntryItem::Serialize() const {
   Bundle b;
   b = AbstractItem::Serialize();
 
index d3dcf660f5590f9289441b0cca818f5e4aa403f5..38a32fb498839633bf8399002235cb304c580798 100644 (file)
@@ -36,7 +36,7 @@ class EXPORT_API EntryItem : public AbstractItem {
       std::shared_ptr<AbstractAction> action = std::shared_ptr<AbstractAction>({}));
   virtual ~EntryItem();
 
-  Bundle Serialize() override;
+  Bundle Serialize() const override;
   void Deserialize(Bundle b) override;
   AbstractItem& FindByID(std::string id) override;
   int GetType() const override;
diff --git a/notification-ex/event_info.cc b/notification-ex/event_info.cc
new file mode 100644 (file)
index 0000000..a0d9f4b
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dlog.h>
+
+#include <memory>
+
+#include "notification-ex/event_info.h"
+#include "notification-ex/event_info_implementation.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "NOTIFICATION_EX"
+#define NOTIFICATION_EX_EVENT_TYPE_KEY "__NOTIFICATION_EX_EVENT_TYPE_KEY__"
+#define NOTIFICATION_EX_EVENT_OWNER_KEY "__NOTIFICATION_EX_EVENT_OWNER_KEY__"
+#define NOTIFICATION_EX_EVENT_CHANNEL_KEY "__NOTIFICATION_EX_EVENT_CHANNEL_KEY__"
+#define NOTIFICATION_EX_EVENT_ITEM_ID_KEY "__NOTIFICATION_EX_EVENT_ITEM_ID_KEY__"
+#define NOTIFICATION_EX_EVENT_TAG_KEY "__NOTIFICATION_EX_EVENT_TAG_KEY__"
+
+using namespace std;
+namespace notification {
+
+EventInfo::EventInfo(EventInfo::EventType type, std::string owner,
+    std::string channel, std::string item_id, std::string tag)
+  : impl_(new Impl(this, type, owner, channel, item_id, tag)) {
+}
+EventInfo::~EventInfo() = default;
+EventInfo::Impl::~Impl() = default;
+
+EventInfo::Impl::Impl(EventInfo* parent, EventInfo::EventType type, std::string owner,
+    std::string channel, std::string item_id, std::string tag)
+  : type_(type), owner_(owner), channel_(channel), item_id_(item_id),
+    tag_(tag), parent_(parent) {
+  LOGI("EventInfo impl created");
+}
+
+EventInfo::EventInfo(Bundle serialized) {
+  string event_str = serialized.GetString(NOTIFICATION_EX_EVENT_TYPE_KEY);
+  impl_->type_ = static_cast<EventInfo::EventType>(strtol(event_str.c_str(), NULL, 10));
+  impl_->owner_ = serialized.GetString(NOTIFICATION_EX_EVENT_OWNER_KEY);
+  impl_->channel_ = serialized.GetString(NOTIFICATION_EX_EVENT_CHANNEL_KEY);
+  impl_->item_id_ = serialized.GetString(NOTIFICATION_EX_EVENT_ITEM_ID_KEY);
+  impl_->tag_ = serialized.GetString(NOTIFICATION_EX_EVENT_TAG_KEY);
+}
+
+string EventInfo::GetString(EventInfo::EventType type) {
+  switch(type) {
+  case Post:
+    return "Post";
+    break;
+  case Update:
+    return "Update";
+    break;
+  case Delete:
+    return "Delete";
+    break;
+  case Get:
+    return "Get";
+    break;
+  }
+  return "";
+}
+
+Bundle EventInfo::Serialize() const {
+  Bundle serialized;
+  serialized.Add(NOTIFICATION_EX_EVENT_TYPE_KEY, to_string((int)impl_->type_));
+  serialized.Add(NOTIFICATION_EX_EVENT_OWNER_KEY, impl_->owner_);
+  serialized.Add(NOTIFICATION_EX_EVENT_CHANNEL_KEY, impl_->channel_);
+  serialized.Add(NOTIFICATION_EX_EVENT_ITEM_ID_KEY, impl_->item_id_);
+  serialized.Add(NOTIFICATION_EX_EVENT_TAG_KEY, impl_->tag_);
+
+  return serialized;
+}
+
+EventInfo::EventType EventInfo::GetEventType() const {
+  return impl_->type_;
+}
+
+string EventInfo::GetOwner() const {
+  return impl_->owner_;
+}
+
+string EventInfo::GetChannel() const {
+  return impl_->channel_;
+}
+
+string EventInfo::GetItemId() const {
+  return impl_->item_id_;
+}
+
+string EventInfo::GetTag() const {
+  return impl_->tag_;
+}
+
+}  // namespace notification
index 55b31b878dfc17ae909bf01d55bd313563174fcd..5b998b3e0e9244968a00897d6ed180b1082f9737 100644 (file)
@@ -18,6 +18,9 @@
 #define NOTIFICATION_EX_EVENT_INFO_H_
 
 #include <string>
+#include <list>
+
+#include "notification-ex/ex_bundle.h"
 
 #ifndef EXPORT_API
 #define EXPORT_API __attribute__((visibility("default")))
@@ -27,17 +30,30 @@ namespace notification {
 
 class EXPORT_API EventInfo {
  public:
-  EventInfo();
+  enum EventType {
+    Post,
+    Update,
+    Delete,
+    Get,
+  };
+  EventInfo(EventType type, std::string owner,
+      std::string channel = "",
+      std::string item_id = "",
+      std::string tag = "");
+  EventInfo(Bundle serialized);
   ~EventInfo();
 
-  int GetEventType() const;
+  static std::string GetString(EventType type);
+  EventType GetEventType() const;
   std::string GetOwner() const;
-  int GetChannel();
+  std::string GetChannel() const;
+  std::string GetItemId() const;
+  std::string GetTag() const;
+  Bundle Serialize() const;
 
  private:
-  int type_;
-  std::string owner_;
-  int channel_;
+  class Impl;
+  std::unique_ptr<Impl> impl_;
 };
 
 }  // namespace notification
diff --git a/notification-ex/event_info_implementation.h b/notification-ex/event_info_implementation.h
new file mode 100644 (file)
index 0000000..9ec2fb6
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef NOTIFICATION_EX_EVENT_INFO_IMPLEMENTATION_H_
+#define NOTIFICATION_EX_EVENT_INFO_IMPLEMENTATION_H_
+
+#include <string>
+#include <memory>
+#include <list>
+
+#include "notification-ex/dbus_sender.h"
+
+namespace notification {
+
+class EventInfo::Impl {
+ public:
+  virtual ~Impl();
+
+ private:
+  friend class EventInfo;
+  Impl(EventInfo* parent, EventInfo::EventType type, std::string owner,
+    std::string channel, std::string item_id, std::string tag);
+
+ private:
+  EventType type_;
+  std::string owner_;
+  std::string channel_;
+  std::string item_id_;
+  std::string tag_;
+  EventInfo* parent_;
+};
+
+}  // nampace notification
+#endif  // NOTIFICATION_EX_EVENT_INFO_IMPLEMENTATION_H_
\ No newline at end of file
index 3990271a841c0190367141cbb10754ed20dc3b7e..7d95807c1468bb33432cf3dbe40a02d5a393642f 100644 (file)
@@ -17,7 +17,8 @@
 #ifndef NOTIFICATION_EX_EVENT_LISTENER_INTERFACE_H_
 #define NOTIFICATION_EX_EVENT_LISTENER_INTERFACE_H_
 
-#include "notification-ex/observer_interface.h"
+#include "notification-ex/event_observer_interface.h"
+#include "notification-ex/event_info.h"
 
 #ifndef EXPORT_API
 #define EXPORT_API __attribute__((visibility("default")))
 
 namespace notification {
 
-class EXPORT_API IEventsListener {
+class EXPORT_API IEventListener {
  public:
-  virtual ~IEventsListener() = 0;
-
-  virtual void RegisterObserver(IEventObserver observer) = 0;
-  virtual void UnRegisterObserver(IEventObserver observer) = 0;
-  virtual void NotifyAll() = 0;
+  virtual ~IEventListener() = default;
+  virtual void RegisterObserver(IEventObserver* observer) = 0;
+  virtual void UnRegisterObserver(IEventObserver* observer) = 0;
+  virtual void NotifyObserver(const EventInfo& info, std::list<Bundle> serialized) = 0;
+  virtual std::list<Bundle> NotifyObserver(const EventInfo& info) = 0;
 };
 
 }  // namespace notification
diff --git a/notification-ex/event_observer_interface.h b/notification-ex/event_observer_interface.h
new file mode 100644 (file)
index 0000000..a94abe8
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef NOTIFICATION_EX_OBSERVER_INTERFACE_H_
+#define NOTIFICATION_EX_OBSERVER_INTERFACE_H_
+
+#include "notification-ex/ex_bundle.h"
+#include "notification-ex/event_info.h"
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+namespace notification {
+
+class EXPORT_API IEventObserver {
+ public:
+  virtual ~IEventObserver() = default;
+  virtual void OnEvent(const EventInfo& info, std::list<Bundle> serialized) = 0;
+  virtual std::list<Bundle> OnRequest(const EventInfo& info) = 0;
+};
+
+}  // namespace notification
+
+#endif
index 3c42a4e8a03a79cc9af42c8234c7d4109dce6244..fcefaec21556bf56327f6e6508904bcd59da3962 100644 (file)
@@ -17,7 +17,8 @@
 #ifndef NOTIFICATION_EX_EVENT_SENDER_INTERFACE_H_
 #define NOTIFICATION_EX_EVENT_SENDER_INTERFACE_H_
 
-#include "notification-ex/bundle.h"
+#include "notification-ex/ex_bundle.h"
+#include "notification-ex/event_info.h"
 
 #ifndef EXPORT_API
 #define EXPORT_API __attribute__((visibility("default")))
 
 namespace notification {
 
-class EXPORT_API IEventsSender {
+class EXPORT_API IEventSender {
  public:
-  virtual ~IEventsSender() = 0;
-
-  virtual void Notify(Bundle serialized) = 0;
+  virtual void Notify(const EventInfo& info, std::list<Bundle> serialized,
+      std::string dest_appid = "") = 0;
+  virtual std::list<Bundle> Request(const EventInfo &info) = 0;
 };
 
 }  // namespace notification
index 1640f00a4f05b552929e588c90c2188e33b1c4da..4eaf47fb852cc805f0ccebf779155c2438d92036 100644 (file)
@@ -37,7 +37,6 @@
 #endif
 
 namespace notification {
-namespace item {
 class EXPORT_API Bundle final {
  public:
   using BundleRaw =
@@ -142,6 +141,20 @@ class EXPORT_API Bundle final {
     return bundle_add_byte(handle_, key.c_str(), val.data(), val.size());
   }
 
+  int Merge(Bundle& b) {
+    std::vector<KeyInfo> keys = b.GetKeys();
+    for (auto& k : keys) {
+      int ret;
+      if (k.IsArray())
+        ret = Add(k.GetName(), b.GetStringArray(k.GetName()));
+      else
+        ret = Add(k.GetName(), b.GetString(k.GetName()));
+      if (ret != 0)
+        return ret;
+    }
+    return 0;
+  }
+
   int Remove(const std::string& key) {
     return bundle_del(handle_, key.c_str());
   }
@@ -212,7 +225,6 @@ class EXPORT_API Bundle final {
   bool copy_ = true;
 };
 
-}  // namespace item
 }  // namespace notification
 
 #endif  // NOTIFICATION_EX_BUNDLE_H_
diff --git a/notification-ex/ex_util.cc b/notification-ex/ex_util.cc
new file mode 100644 (file)
index 0000000..dca6606
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dlog.h>
+#include <aul.h>
+#include <aul.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <string>
+
+#include "notification-ex/ex_util.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "NOTIFICATION_EX"
+#define MAX_PACKAGE_STR_SIZE 512
+
+using namespace std;
+namespace notification {
+namespace util {
+  GQuark GetQuarkFromString(string str) {
+    return g_quark_from_string(str.c_str());
+  }
+
+  std::string GetQuarkToString(GQuark quark) {
+    return g_quark_to_string(quark);
+  }
+
+  string GetAppId() {
+    static string appid = "";
+    char appid_buf[MAX_PACKAGE_STR_SIZE] = {0, };
+
+    if (!appid.empty()) {
+      LOGI("appid(%s)", appid.c_str());
+      return appid;
+    }
+
+    int pid = getpid();
+    int ret = aul_app_get_appid_bypid(pid, appid_buf, sizeof(appid_buf));
+    if (ret == AUL_R_OK) {
+      appid = string(appid_buf);
+    } else {
+      int fd, i;
+      int last_slash_index = 0;
+      char proc_buf[MAX_PACKAGE_STR_SIZE] = { 0, };
+
+      snprintf(proc_buf, sizeof(proc_buf), "/proc/%d/cmdline", pid);
+
+      fd = open(proc_buf, O_RDONLY);
+      if (fd < 0) {
+        LOGE("Fail to get appid (%d)", errno);
+        return "";
+      }
+
+      ret = read(fd, appid_buf, sizeof(appid_buf) - 1);
+      if (ret <= 0) {
+        LOGE("Fail to get appid (%d)", errno);
+        close(fd);
+        return "";
+      }
+      close(fd);
+
+      for (i = 0 ; i < ret ; i++) {
+        if (appid_buf[i] == '/')
+          last_slash_index = i;
+      }
+
+      if (last_slash_index == (ret - 1)) {
+        LOGE("Fail to get appid (%s)", appid_buf);
+        return "";
+      }
+
+      if (last_slash_index == 0)
+        appid = string(appid_buf);
+      else
+        appid = string(&appid_buf[last_slash_index + 1]);
+    }
+
+    LOGI("appid(%s)", appid.c_str());
+    return appid;
+  }
+}  // namespace util
+}  // namespace watchface_complication
diff --git a/notification-ex/ex_util.h b/notification-ex/ex_util.h
new file mode 100644 (file)
index 0000000..c4250d4
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef NOTIFICATION_EX_EX_UTIL_H_
+#define NOTIFICATION_EX_EX_UTIL_H_
+
+#include <gmodule.h>
+
+#include <string>
+
+namespace notification {
+namespace util {
+  std::string GetAppId();
+  std::string GetAppId();
+  GQuark GetQuarkFromString(std::string str);
+  std::string GetQuarkToString(GQuark quark);
+}  // namespace util
+}  // namespace notification
+
+#endif  // NOTIFICATION_EX_EX_UTIL_H_
index d6a53daabfda915e6db14dca216cfacc7443c561..6e65f0a72a51cb88685242dc4701639325a6f63c 100644 (file)
@@ -61,7 +61,7 @@ int GroupItem::GetType() const {
   return AbstractItem::Group;
 }
 
-Bundle GroupItem::Serialize() {
+Bundle GroupItem::Serialize() const {
   Bundle b;
   b = AbstractItem::Serialize();
   b.Add(GROUP_DIRECTION_KEY, impl_->is_vertical_ ?
index 51d1b6519f2027767bd16ac84cda89491b153655..2989c745d188df96440f2c1c9310cf283f60e8de 100644 (file)
@@ -34,7 +34,7 @@ class EXPORT_API GroupItem : public AbstractItem {
   virtual ~GroupItem();
 
  public:
-  virtual Bundle Serialize() override;
+  virtual Bundle Serialize() const override;
   virtual void Deserialize(Bundle b) override;
   virtual AbstractItem& FindByID(std::string id) override;
   int GetType() const override;
index 1006bfae0a44c889b4f3086cdfdf5c0106e368c8..a237ae94b2857c47f51af1b038bf1699f6e7a7c6 100644 (file)
@@ -48,7 +48,7 @@ int IconTextItem::GetType() const {
   return AbstractItem::IconText;
 }
 
-Bundle IconTextItem::Serialize() {
+Bundle IconTextItem::Serialize() const {
   Bundle b;
   b = AbstractItem::Serialize();
 
index 4fdc44fce96e52b5349ae6de89a6f9cb7a1f4fd8..2653076a59c4d63b6cf35cc70c5462d292781336 100644 (file)
@@ -36,7 +36,7 @@ class EXPORT_API IconTextItem : public AbstractItem {
 
   virtual ~IconTextItem();
 
-  Bundle Serialize() override;
+  Bundle Serialize() const override;
   void Deserialize(Bundle b) override;
   AbstractItem& FindByID(std::string id) override;
   int GetType() const override;
index 56f667be686302c14a8c5febbeac8e3d6d7d38bc..46c7f10d4d7843ed25d9c017124e5ba966a7669d 100644 (file)
@@ -27,6 +27,9 @@ class IItemInfoInternal : public IItemInfo{
   virtual ~IItemInfoInternal() = default;
   virtual int GetHideTime() const = 0;
   virtual int GetDeleteTime() const = 0;
+  virtual void AddHideViewer(std::string appid) = 0;
+  virtual void RemoveHideViewer(std::string appid) = 0;
+  virtual std::list<std::string> GetHideViewerList() const = 0;
 };
 
 }  // namespace item
index c9e8701ec067eb2d05ff3d76002427c3b18e8a5e..bce699dfdafacb777cde061358091e56124711d7 100644 (file)
@@ -50,7 +50,7 @@ int ImageItem::GetType() const {
   return AbstractItem::Image;
 }
 
-Bundle ImageItem::Serialize() {
+Bundle ImageItem::Serialize() const {
   Bundle b;
   b = AbstractItem::Serialize();
   b.Add(IMAGE_PATH_KEY, impl_->imagePath_);
index c2bad8015f830adf6f513f9cd91581f93b2b9bc2..ea536504ae343e36ccd0a0a316e9e31a46efb977 100644 (file)
@@ -35,7 +35,7 @@ class EXPORT_API ImageItem : public AbstractItem {
   virtual ~ImageItem();
   int GetType() const override;
 
-  Bundle Serialize() override;
+  Bundle Serialize() const override;
   void Deserialize(Bundle b) override;
   AbstractItem& FindByID(std::string id) override;
   std::string GetImagePath() const;
index 5115552ecff7e02ffde43f85fc2176ce8407a1f3..37867e23d8d7f9423d79b51a6c0f060e5a6ac2c6 100644 (file)
@@ -55,7 +55,7 @@ int InputSelectorItem::GetType() const {
   return AbstractItem::InputSelector;
 }
 
-Bundle InputSelectorItem::Serialize() {
+Bundle InputSelectorItem::Serialize() const {
   Bundle b;
   b = AbstractItem::Serialize();
   vector<string> contents_vector {
index 6b1220a86802c9fc2f96729e764060dc1b6a0d2c..f9a873a6e579d8af2fcc89e5f895e32efd68a297 100644 (file)
@@ -34,7 +34,7 @@ class EXPORT_API InputSelectorItem : public AbstractItem {
   virtual ~InputSelectorItem();
 
  public:
-  virtual Bundle Serialize() override;
+  virtual Bundle Serialize() const override;
   virtual void Deserialize(Bundle b) override;
   virtual AbstractItem& FindByID(std::string id) override;
   int GetType() const override;
index 2b456ce02fcd20b46cbe4de25f9c6fd6892a828d..6bf60ff98cf152ff017d00cdc80b4bfa6541ae56 100644 (file)
@@ -17,6 +17,7 @@
 #include <dlog.h>
 
 #include <memory>
+#include <algorithm>
 
 #include "notification-ex/item_info_internal.h"
 
@@ -48,5 +49,23 @@ int AbstractItem::Impl::ItemInfo::GetDeleteTime() const {
   return impl_->delete_time_;
 }
 
+void AbstractItem::Impl::ItemInfo::AddHideViewer(std::string appid) {
+  if (find(impl_->hide_viewer_list_.begin(),
+      impl_->hide_viewer_list_.end(), appid) !=
+      impl_->hide_viewer_list_.end()) {
+    return;
+  }
+  impl_->hide_viewer_list_.push_back(appid);
+}
+
+void AbstractItem::Impl::ItemInfo::RemoveHideViewer(std::string appid) {
+  impl_->hide_viewer_list_.remove(appid);
+}
+
+std::list<std::string> AbstractItem::Impl::ItemInfo::GetHideViewerList() const {
+  return impl_->hide_viewer_list_;
+}
+
+
 }  // namespace item
 }  // namespace notification
index 5c9d1b1d54974e2b59a753e064cead46e6b558cf..918513a93ddef330d22d15e291b9cf92bffdb8d6 100644 (file)
@@ -31,6 +31,9 @@ class AbstractItem::Impl::ItemInfo : public IItemInfoInternal {
   void SetVersion(int ver) override;
   int GetHideTime() const override;
   int GetDeleteTime() const override;
+  void AddHideViewer(std::string appid) override;
+  void RemoveHideViewer(std::string appid) override;
+  std::list<std::string> GetHideViewerList() const override;
 
  private:
   AbstractItem::Impl* impl_;
diff --git a/notification-ex/manager.cc b/notification-ex/manager.cc
new file mode 100644 (file)
index 0000000..d46b1e1
--- /dev/null
@@ -0,0 +1,177 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dlog.h>
+#include <glib.h>
+#include <unistd.h>
+
+#include <list>
+
+#include "notification-ex/item_inflator.h"
+#include "notification-ex/manager.h"
+#include "notification-ex/manager_implementation.h"
+#include "notification-ex/event_info.h"
+#include "notification-ex/dbus_connection_manager.h"
+#include "notification-ex/ex_util.h"
+#include "notification-ex/item_info_internal.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "NOTIFICATION_EX"
+
+#define MAX_PACKAGE_STR_SIZE 512
+#define NOTIFICATION_EX_MANAGER_OBJECT_PATH "/org/tizen/notification_ex_manager"
+
+using namespace std;
+using namespace notification::item;
+namespace notification {
+
+Manager::Manager(IEventSender* sender, IEventListener* listener, string receiver_group)
+  : impl_(new Impl(this, sender, listener, receiver_group)) {
+}
+Manager::~Manager() = default;
+
+Manager::Impl::~Impl() {
+  listener_->UnRegisterObserver(parent_);
+}
+Manager::Impl::Impl(Manager* parent,
+    IEventSender* sender, IEventListener* listener, string receiver_group)
+  : sender_(sender), listener_(listener), receiver_group_(receiver_group),
+    parent_(parent) {
+  LOGI("impl created");
+  listener_->RegisterObserver(parent_);
+}
+
+void Manager::Impl::SendNotify(shared_ptr<item::AbstractItem> noti,
+    EventInfo::EventType type) {
+  Bundle serialized = noti->Serialize();
+  EventInfo info(type, util::GetAppId(), noti->GetChannel());
+  list<Bundle> serialized_list {serialized};
+
+  /* Reply to Sender */
+  sender_->Notify(info, serialized_list, noti->GetSenderAppId());
+}
+
+void Manager::Update(shared_ptr<item::AbstractItem> noti) {
+  impl_->SendNotify(noti, EventInfo::Update);
+}
+
+void Manager::Remove(shared_ptr<item::AbstractItem> noti) {
+  impl_->SendNotify(noti, EventInfo::Delete);
+}
+
+void Manager::Hide(shared_ptr<item::AbstractItem> noti) {
+  ((IItemInfoInternal*)noti->GetInfo().get())->AddHideViewer(util::GetAppId());
+  impl_->SendNotify(noti, EventInfo::Update);
+}
+
+shared_ptr<item::AbstractItem> Manager::FindByRootID(string id) {
+  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>({});
+  }
+  Bundle b = result.front();
+  shared_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
+  return gen_item;
+}
+
+list<shared_ptr<item::AbstractItem>> Manager::Get() {
+  EventInfo info(EventInfo::Get, util::GetAppId(), "");
+  list<Bundle> result = impl_->sender_->Request(info);
+  list<shared_ptr<item::AbstractItem>> gen_list;
+  for (auto& i : result) {
+    shared_ptr<AbstractItem> gen_item = ItemInflator::Create(i);
+    gen_list.emplace_back(gen_item);
+  }
+  return gen_list;
+}
+
+void Manager::SendEvent(const EventInfo& info, shared_ptr<item::AbstractItem> noti) {
+  Bundle serialized = noti->Serialize();
+  Bundle serialized_info = info.Serialize();
+  list<Bundle> serialized_list {serialized};
+  impl_->sender_->Notify(info, serialized_list, noti->GetSenderAppId());
+}
+
+list<Bundle> Manager::OnRequest(const EventInfo& info) {
+  list<shared_ptr<item::AbstractItem>> item_list = OnRequestEvent(info);
+  list<Bundle> serialized_list;
+  for (auto& i : item_list) {
+    serialized_list.push_back(i->Serialize());
+  }
+  return serialized_list;
+}
+
+void Manager::OnEvent(const EventInfo& info, list<Bundle> serialized) {
+  shared_ptr<AbstractItem> gen_item;
+  const EventInfo::EventType type = info.GetEventType();
+  switch(type) {
+  case EventInfo::Post:
+  {
+    list<shared_ptr<item::AbstractItem>> added;
+    for (auto& i : serialized) {
+      gen_item = ItemInflator::Create(i);
+      if (gen_item->CanReceive(impl_->receiver_group_))
+        added.emplace_back(gen_item);
+    }
+    if (added.size() > 0)
+      OnAdd(info, added);
+    break;
+  }
+  case EventInfo::Update:
+  {
+    for (auto& i : serialized) {
+      gen_item = ItemInflator::Create(i);
+      if (gen_item->CanReceive(impl_->receiver_group_))
+        OnUpdate(info, gen_item);
+    }
+    break;
+  }
+  case EventInfo::Delete:
+    for (auto& i : serialized) {
+      gen_item = ItemInflator::Create(i);
+      if (gen_item->CanReceive(impl_->receiver_group_))
+        OnDelete(info, gen_item);
+    }
+    break;
+  case EventInfo::Get:
+    break;
+  }
+}
+
+void Manager::OnAdd(const EventInfo& info, list<shared_ptr<item::AbstractItem>> addedItem) {
+}
+
+void Manager::OnUpdate(const EventInfo& info, shared_ptr<item::AbstractItem> updatedItem) {
+}
+
+void Manager::OnDelete(const EventInfo& info, shared_ptr<item::AbstractItem> deletedItem) {
+}
+
+list<shared_ptr<item::AbstractItem>> Manager::OnRequestEvent(const EventInfo& info) {
+  return list<shared_ptr<item::AbstractItem>>({});
+}
+
+string Manager::GetPath() {
+  return NOTIFICATION_EX_MANAGER_OBJECT_PATH;
+}
+
+}  // nampace notification
\ No newline at end of file
index 8942ba1be945f8ccf960acf0046e6e495f2bc2a1..56b2b34829ef331cac30738fd98bbfefeccb92e8 100644 (file)
@@ -21,6 +21,9 @@
 #include <list>
 
 #include "notification-ex/abstract_item.h"
+#include "notification-ex/event_observer_interface.h"
+#include "notification-ex/event_sender_interface.h"
+#include "notification-ex/event_listener_interface.h"
 
 #ifndef EXPORT_API
 #define EXPORT_API __attribute__((visibility("default")))
@@ -30,24 +33,30 @@ namespace notification {
 
 class EXPORT_API Manager : public IEventObserver {
  public:
-  Manager(IEventsSender* sender, IEventsListener* listener);
+  Manager(IEventSender* sender, IEventListener* listener, std::string receiver_group = "");
   virtual ~Manager();
 
+  std::list<std::shared_ptr<item::AbstractItem>> Get();
   void Update(std::shared_ptr<item::AbstractItem> noti);
   void Remove(std::shared_ptr<item::AbstractItem> noti);
   void Hide(std::shared_ptr<item::AbstractItem> noti);
   std::shared_ptr<item::AbstractItem> FindByRootID(std::string id);
-  void SendEvent(EventInfo info, std::shared_ptr<item::AbstractItem> noti);
-  void OnEvent(EventInfo info, std::shared_ptr<AbstractItem> notiList) override;
+  void SendEvent(const EventInfo& info, std::shared_ptr<item::AbstractItem> noti);
+  void OnEvent(const EventInfo& info, std::list<Bundle> serialized) override;
+  std::list<Bundle> OnRequest(const EventInfo& info) override;
+  static std::string GetPath();
 
  protected:
-  virtual void OnAdd(std::list<std::shared_ptr<item::AbstractItem>> addedItem);
-  virtual void OnUpdate(shared_ptr<item::AbstractItem> updatedItem);
-  virtual void OnDelete(shared_ptr<item::AbstractItem> deletedItem);
+  virtual void OnAdd(const EventInfo& info, std::list<std::shared_ptr<item::AbstractItem>> addedItem);
+  virtual void OnUpdate(const EventInfo& info, std::shared_ptr<item::AbstractItem> updatedItem);
+  virtual void OnDelete(const EventInfo& info, std::shared_ptr<item::AbstractItem> deletedItem);
+  virtual std::list<std::shared_ptr<item::AbstractItem>> OnRequestEvent(
+      const EventInfo& info);
 
  private:
-  IEventsSender* sender_;
-  IEventsListener* receiver_;
+  class Impl;
+  std::unique_ptr<Impl> impl_;
+
 };
 
 }  // namespace notification
diff --git a/notification-ex/manager_implementation.h b/notification-ex/manager_implementation.h
new file mode 100644 (file)
index 0000000..9b7c79e
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef NOTIFICATION_EX_MANAGER_IMPLEMENTATION_H_
+#define NOTIFICATION_EX_MANAGER_IMPLEMENTATION_H_
+
+#include <string>
+#include <memory>
+#include <list>
+
+#include "notification-ex/manager.h"
+
+namespace notification {
+
+class Manager::Impl {
+ public:
+  virtual ~Impl();
+
+ private:
+  Impl(Manager* parent,
+    IEventSender* sender, IEventListener* listener, std::string receiver_group);
+
+ private:
+  friend class Manager;
+  void SendNotify(std::shared_ptr<item::AbstractItem> noti,
+      EventInfo::EventType type);
+  IEventSender* sender_;
+  IEventListener* listener_;
+  std::string receiver_group_;
+  Manager* parent_;
+};
+
+}  // namespace notification
+
+#endif  // NOTIFICATION_EX_MANAGER_IMPLEMENTATION_H_
index 769c735deb4c6ce980aa3b59fc7671a16a395af7..509a5258ef5b7b0474735745cd357e8696026413 100644 (file)
@@ -25,7 +25,7 @@
 
 namespace notification {
 
-class EXPORT_API MockSender : public IEventsSender {
+class EXPORT_API MockSender : public IEventSender {
  public:
   MockSender();
   virtual ~MockSender();
index a4fdc5e7091879bf1f588b62c87360e1b99f2c87..e51c660a90b63cafd55a9d2e44192b1a39ab15e5 100644 (file)
@@ -6,6 +6,6 @@ includedir=@INCLUDEDIR@
 Name: notification-ex
 Description: Support development of the notification
 Version: @VERSION@
-Libs: -L${libdir}
+Libs: -L${libdir} -lnotification-ex
 Cflags: -I${includedir}
-cppflags: -I${includedir}
\ No newline at end of file
+cppflags: -I${includedir}
index 819677eb73996c260b3aee71dd65a66bc6c60136..5d688d23e26f3a1306bc3372ca47d78e555d4e74 100644 (file)
@@ -44,7 +44,7 @@ int NullItem::GetType() const {
   return AbstractItem::NullObject;
 }
 
-Bundle NullItem::Serialize() {
+Bundle NullItem::Serialize() const {
   Bundle b;
   b = AbstractItem::Serialize();
   return b;
index cf2716426250e6068666dfd8b483db5fac752ea7..6864c1aa62511413289ad43d9bc13b235e90e512 100644 (file)
@@ -33,7 +33,7 @@ class EXPORT_API NullItem : public AbstractItem {
       std::shared_ptr<AbstractAction> action = std::shared_ptr<AbstractAction>({}));
   virtual ~NullItem();
   int GetType() const override;
-  Bundle Serialize() override;
+  Bundle Serialize() const override;
   void Deserialize(Bundle b) override;
   AbstractItem& FindByID(std::string id) override;
 };
diff --git a/notification-ex/observer_interface.h b/notification-ex/observer_interface.h
deleted file mode 100644 (file)
index 7ea61f6..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef NOTIFICATION_EX_OBSERVER_INTERFACE_H_
-#define NOTIFICATION_EX_OBSERVER_INTERFACE_H_
-
-#include "notification-ex/ex_bundle.h"
-#include "notification-ex/event_info.h"
-
-#ifndef EXPORT_API
-#define EXPORT_API __attribute__((visibility("default")))
-#endif
-
-namespace notification {
-
-class EXPORT_API IEventObserver {
- public:
-  virtual ~IEventObserver() = 0;
-
-  virtual void OnEvent(EventInfo info, std::shared_ptr<AbstractItem> noti) = 0;
-};
-
-}  // namespace notification
-
-#endif
index fecefbc3c86cfa5ff714cd3dcfad850534874545..36dd5dfec8ded492a507fa329e75f512f7bd3f03 100644 (file)
@@ -62,7 +62,7 @@ int ProgressItem::GetType() const {
   return AbstractItem::Progress;
 }
 
-Bundle ProgressItem::Serialize() {
+Bundle ProgressItem::Serialize() const {
   Bundle b;
   b = AbstractItem::Serialize();
   b.Add(PROGRESS_MIN_KEY, to_string(impl_->min_));
index d3d4b9e2b849b02a49296b3f95de95ea9b10d5ee..04fa3a7db0bb323f78596674b21bf910425e2825 100644 (file)
@@ -35,7 +35,7 @@ class EXPORT_API ProgressItem : public AbstractItem {
   virtual ~ProgressItem();
 
  public:
-  virtual Bundle Serialize() override;
+  virtual Bundle Serialize() const override;
   virtual void Deserialize(Bundle b) override;
   virtual AbstractItem& FindByID(std::string id) override;
   int GetType() const override;
diff --git a/notification-ex/reporter.cc b/notification-ex/reporter.cc
new file mode 100644 (file)
index 0000000..893b615
--- /dev/null
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dlog.h>
+#include <glib.h>
+#include <unistd.h>
+
+#include <list>
+
+#include "notification-ex/reporter.h"
+#include "notification-ex/reporter_implementation.h"
+#include "notification-ex/event_info.h"
+#include "notification-ex/item_inflator.h"
+#include "notification-ex/dbus_connection_manager.h"
+#include "notification-ex/ex_util.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "NOTIFICATION_EX"
+
+#define MAX_PACKAGE_STR_SIZE 512
+#define NOTIFICATION_EX_REPORTER_OBJECT_PATH "/org/tizen/notification_ex_reporter"
+
+using namespace std;
+using namespace notification::item;
+namespace notification {
+
+Reporter::Reporter(IEventSender* sender, IEventListener* listener)
+  : impl_(new Impl(this, sender, listener)) {
+}
+Reporter::~Reporter() = default;
+
+Reporter::Impl::~Impl() {
+  listener_->UnRegisterObserver(parent_);
+}
+Reporter::Impl::Impl(Reporter* parent,
+    IEventSender* sender, IEventListener* listener)
+  : sender_(sender), listener_(listener), parent_(parent) {
+  LOGI("impl created");
+  listener_->RegisterObserver(parent_);
+}
+
+void Reporter::Impl::SendNotify(shared_ptr<item::AbstractItem> noti,
+    EventInfo::EventType type) {
+  Bundle serialized = noti->Serialize();
+  EventInfo info(type, util::GetAppId(), noti->GetChannel());
+  list<Bundle> serialized_list {serialized};
+  sender_->Notify(info, serialized_list);
+}
+
+void Reporter::Post(std::shared_ptr<item::AbstractItem> noti) {
+  LOGI("Post noti");
+  impl_->SendNotify(noti, EventInfo::Post);
+}
+
+void Reporter::Post(std::list<std::shared_ptr<AbstractItem>> notiList) {
+  EventInfo info(EventInfo::Post, util::GetAppId(), "");
+  list<Bundle> serialized_list;
+  for (auto& i : notiList) {
+    Bundle b = i->Serialize();
+    serialized_list.push_back(b);
+  }
+  impl_->sender_->Notify(info, serialized_list);
+}
+
+void Reporter::Update(std::shared_ptr<AbstractItem> noti) {
+  impl_->SendNotify(noti, EventInfo::Update);
+}
+
+void Reporter::Remove(std::shared_ptr<AbstractItem> noti) {
+  impl_->SendNotify(noti, EventInfo::Delete);
+}
+
+std::shared_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>({});
+  }
+  Bundle b = result.front();
+  shared_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
+  return gen_item;
+}
+
+void Reporter::SendEvent(const EventInfo& info, shared_ptr<item::AbstractItem> noti) {
+  Bundle serialized = noti->Serialize();
+  list<Bundle> serialized_list {serialized};
+  impl_->sender_->Notify(info, serialized_list);
+}
+
+void Reporter::OnEvent(const EventInfo& info, list<Bundle> serialized) {
+  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);
+  }
+  OnEvent(info, item_list);
+}
+
+list<shared_ptr<item::AbstractItem>> Reporter::OnRequestEvent(const EventInfo& info) {
+  return list<shared_ptr<item::AbstractItem>>({});
+}
+
+list<Bundle> Reporter::OnRequest(const EventInfo& info) {
+  list<shared_ptr<item::AbstractItem>> item_list = OnRequestEvent(info);
+  list<Bundle> serialized_list;
+  for (auto& i : item_list) {
+    serialized_list.push_back(i->Serialize());
+  }
+  return serialized_list;
+}
+
+void Reporter::OnEvent(
+    const EventInfo& info, list<shared_ptr<item::AbstractItem>> notiList) {
+}
+
+string Reporter::GetPath() {
+  return NOTIFICATION_EX_REPORTER_OBJECT_PATH;
+}
+
+}  // nampace notification
\ No newline at end of file
diff --git a/notification-ex/reporter.h b/notification-ex/reporter.h
new file mode 100644 (file)
index 0000000..61aa457
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef NOTIFICATION_EX_REPOTER_H_
+#define NOTIFICATION_EX_REPOTER_H_
+
+#include <string>
+#include <list>
+
+#include "notification-ex/event_info.h"
+#include "notification-ex/event_observer_interface.h"
+#include "notification-ex/event_sender_interface.h"
+#include "notification-ex/event_listener_interface.h"
+#include "notification-ex/abstract_item.h"
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+namespace notification {
+
+class EXPORT_API Reporter : public IEventObserver {
+ public:
+  Reporter(IEventSender* sender, IEventListener* listener);
+  virtual ~Reporter();
+
+  void SendEvent(const EventInfo& info, std::shared_ptr<item::AbstractItem> noti);
+  void Post(std::shared_ptr<item::AbstractItem> noti);
+  void Post(std::list<std::shared_ptr<item::AbstractItem>> notiList);
+  void Update(std::shared_ptr<item::AbstractItem> noti);
+  void Remove(std::shared_ptr<item::AbstractItem> noti);
+  std::shared_ptr<item::AbstractItem> FindByRootID(std::string id);
+  virtual void OnEvent(const EventInfo& info,
+      std::list<std::shared_ptr<item::AbstractItem>> notiList);
+  virtual std::list<std::shared_ptr<item::AbstractItem>> OnRequestEvent(
+      const EventInfo& info);
+  void OnEvent(const EventInfo& info, std::list<Bundle> serialized) override;
+  std::list<Bundle> OnRequest(const EventInfo& info) override;
+  static std::string GetPath();
+
+ private:
+  class Impl;
+  std::unique_ptr<Impl> impl_;
+};
+
+}  // namespace notification
+
+#endif  // NOTIFICATION_EX_REPOTER_H_
diff --git a/notification-ex/reporter_implementation.h b/notification-ex/reporter_implementation.h
new file mode 100644 (file)
index 0000000..378e507
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef NOTIFICATION_EX_REPORTER_IMPLEMENTATION_H_
+#define NOTIFICATION_EX_REPORTER_IMPLEMENTATION_H_
+
+#include <string>
+#include <memory>
+#include <list>
+
+#include "notification-ex/reporter.h"
+
+namespace notification {
+
+class Reporter::Impl {
+ public:
+  virtual ~Impl();
+
+ private:
+  Impl(Reporter* parent,
+    IEventSender* sender, IEventListener* listener);
+
+ private:
+  friend class Reporter;
+  void SendNotify(std::shared_ptr<item::AbstractItem> noti,
+      EventInfo::EventType type);
+  IEventSender* sender_;
+  IEventListener* listener_;
+  Reporter* parent_;
+};
+
+}  // namespace notification
+
+#endif  // NOTIFICATION_EX_REPORTER_IMPLEMENTATION_H_
diff --git a/notification-ex/repoter.h b/notification-ex/repoter.h
deleted file mode 100644 (file)
index 90cbf6f..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef NOTIFICATION_EX_REPOTER_H_
-#define NOTIFICATION_EX_REPOTER_H_
-
-#include <string>
-#include <list>
-
-#include "notification-ex/abstract_item.h"
-#include "notification-ex/event_info.h"
-
-#ifndef EXPORT_API
-#define EXPORT_API __attribute__((visibility("default")))
-#endif
-
-namespace notification {
-
-class EXPORT_API Repoter : public IEventObserver {
- public:
-  Repoter(IEventsSender* sender, IEventsListener* listener);
-  virtual ~Repoter();
-
-  void Post(std::shared_ptr<item::AbstractItem> noti);
-  void Post(std::list<std::shared_ptr<AbstractItem>> notiList);
-  void Update(std::shared_ptr<AbstractItem> noti);
-  void Remove(std::shared_ptr<AbstractItem> noti);
-  std::shared_ptr<AbstractItem> FindByRootID(std::string id);
-  void OnEvent(EventInfo info, std::shared_ptr<AbstractItem> notiList) override;
-
- private:
-  IEventsSender* sender_;
-  IEventsListener* receiver_;
-};
-
-}  // namespace notification
-
-#endif  // NOTIFICATION_EX_REPOTER_H_
index f9543ac622715ac02ba4238e235d2d2f2ff66e9f..f5d5ed28190ee4e5181eb4cf00b73064b3490f1b 100644 (file)
@@ -49,7 +49,7 @@ int TextItem::GetType() const {
   return AbstractItem::Text;
 }
 
-Bundle TextItem::Serialize() {
+Bundle TextItem::Serialize() const {
   Bundle b;
   b = AbstractItem::Serialize();
 
index b7487facdf7548dcb8762b84d37d95d5670e4e86..9f9a987e71eaf5c3a619af09ae73e3ab7aaba11a 100644 (file)
@@ -36,7 +36,7 @@ class EXPORT_API TextItem : public AbstractItem {
       std::shared_ptr<AbstractAction> action = std::shared_ptr<AbstractAction>({}));
   virtual ~TextItem();
   int GetType() const override;
-  Bundle Serialize() override;
+  Bundle Serialize() const override;
   void Deserialize(Bundle b) override;
   AbstractItem& FindByID(std::string id) override;
   void SetContents(std::string contents);
index fc7fbf9c588ce1c978b37994b4fff92d6ccef27d..0816373bd6228f9754e4ca0774240d2ca09dd154 100644 (file)
@@ -57,7 +57,7 @@ int TimeItem::GetType() const {
   return AbstractItem::Time;
 }
 
-Bundle TimeItem::Serialize() {
+Bundle TimeItem::Serialize() const {
   Bundle b;
   struct tm* timeinfo;
   char buf[80] = {0,};
index 388a9b4f59f54ccd46375cbe1516fd595fb7a019..29a8d56096629656bceeb943f6035951b9493cc9 100644 (file)
@@ -39,7 +39,7 @@ class EXPORT_API TimeItem : public AbstractItem {
 
   virtual ~TimeItem();
   int GetType() const override;
-  Bundle Serialize() override;
+  Bundle Serialize() const override;
   void Deserialize(Bundle b) override;
   AbstractItem& FindByID(std::string id) override;
   time_t GetTime() const;
index 3ff4dfe6711ad34f8b634b1154ea5f6e4b88ec51..1ec90b578aa61b1883121b8e8d33627cfa42a858 100644 (file)
@@ -49,7 +49,7 @@ int VisibilityAction::GetType() const {
   return AbstractAction::Visibility;
 }
 
-Bundle VisibilityAction::Serialize() {
+Bundle VisibilityAction::Serialize() const {
   char buf_key[128];
   char buf_data[128];
   Bundle b;
index c4e7b7a8ac7ac0a43b48c96bda909d331b3f68bb..ebc543a1ef4a37149ad2cb327c75963cc7b2eacd 100644 (file)
@@ -29,7 +29,7 @@ class EXPORT_API VisibilityAction  : public AbstractAction {
   virtual ~VisibilityAction();
 
   int GetType() const override;
-  Bundle Serialize() override;
+  Bundle Serialize() const override;
   void Deserialize(Bundle b) override;
   bool IsLocal() const override;
   void Execute(std::shared_ptr<AbstractItem> item) override;
index 52c67d464057186e11b534a628041ef79dd7e66c..6aef59aacc88c3388c7e0e16f0b065ced0eaf7c9 100644 (file)
@@ -22,6 +22,7 @@ BuildRequires: pkgconfig(iniparser)
 BuildRequires: pkgconfig(security-manager)
 BuildRequires: pkgconfig(libsmack)
 BuildRequires: pkgconfig(gmock)
+BuildRequires: pkgconfig(uuid)
 
 BuildRequires: cmake
 Requires(post): /sbin/ldconfig
index d56e3bd00d548e94d865f8d41a754803a0551286..5af53a69eb640a0624c2c242b798d3d498858bef 100644 (file)
@@ -6,6 +6,8 @@ pkg_check_modules(notification-ex_unittests REQUIRED
     dlog
     gmock
     capi-appfw-app-control
+    glib-2.0
+    aul
 )
 
 FOREACH(flag ${notification-ex_unittests_CFLAGS})
index 3320832029af90ea3ca899ad664f77621041914d..7e28128bc5a833d39ce75b329526e432f39e1a29 100644 (file)
@@ -7,6 +7,7 @@
 #include "notification-ex/button_item.h"
 #include "notification-ex/item_inflator.h"
 
+using namespace notification;
 using namespace notification::item;
 using namespace std;
 
index 20a86cfb328b78a1180dab081f47d2d20841fecf..086e517c4af3f4b7a2b47419dbe965d8532c4b3d 100644 (file)
@@ -20,6 +20,7 @@
 #include "notification-ex/chat_message_item.h"
 #include "notification-ex/item_inflator.h"
 
+using namespace notification;
 using namespace notification::item;
 
 class ChatMessageItemTest : public ::testing::Test {
index 8aa0e6b3f32f8bfb1db0f0741e17bfccd4b9a26b..cca8c4d550b6e7d632bcaca2d81d598ad1e41876 100644 (file)
@@ -20,6 +20,7 @@
 #include "notification-ex/checkbox_item.h"
 #include "notification-ex/item_inflator.h"
 
+using namespace notification;
 using namespace notification::item;
 
 class CheckBoxItemTest : public ::testing::Test {
index da933d337bff9ca982a93a63cad94ef2f00a292e..8bc9d4ede16f322977ecafef204814518915e6b6 100644 (file)
@@ -20,6 +20,7 @@
 #include "notification-ex/entry_item.h"
 #include "notification-ex/item_inflator.h"
 
+using namespace notification;
 using namespace notification::item;
 
 namespace {
index 6288c8df711953b5837c14504f566b8321ac5d35..fb4b63bd9237ee52c126741ff217c5f55f37ea59 100644 (file)
@@ -9,6 +9,7 @@
 #include "notification-ex/item_inflator.h"
 #include "unittest/mock/app_common.h"
 
+using namespace notification;
 using namespace notification::item;
 using namespace std;
 
index cd2fdbfa82ac3ac5c0cbab4906ba05f55b3e6360..23704672c8ef76b34ebc8cf2929ef449691cff06 100644 (file)
@@ -20,6 +20,7 @@
 #include "notification-ex/icon_item.h"
 #include "notification-ex/item_inflator.h"
 
+using namespace notification;
 using namespace notification::item;
 
 class IconItemTest : public ::testing::Test {
index 423d0522535c81ab41ce7a6c065b5eb8378dc1d6..20451e2ffffe0ce1fe72bb5954e9bab4c8770db4 100644 (file)
@@ -20,6 +20,7 @@
 #include "notification-ex/icon_text_item.h"
 #include "notification-ex/item_inflator.h"
 
+using namespace notification;
 using namespace notification::item;
 
 class IconTextItemTest : public ::testing::Test {
index 5aa45e2de79faf1756a1d422626a722d350ce79a..a12e58c42f0f394c81fd04dc2cd6888e459ad3b6 100644 (file)
@@ -20,6 +20,7 @@
 #include "notification-ex/image_item.h"
 #include "notification-ex/item_inflator.h"
 
+using namespace notification;
 using namespace notification::item;
 
 class ImageItemTest : public ::testing::Test {
index d2db27d9a32736463e32a97a927502c7351b4c3a..7a02da8c4760a44125579ae93e6f87e2ef371c7e 100644 (file)
@@ -7,6 +7,7 @@
 #include "notification-ex/input_selector_item.h"
 #include "notification-ex/item_inflator.h"
 
+using namespace notification;
 using namespace notification::item;
 using namespace std;
 
index d62aab3832faf1753ea0c6f3d80458d8ec69bfc7..a592e448308c672c4ea3d11e8e0469d03ceb305b 100644 (file)
@@ -7,6 +7,7 @@
 #include "notification-ex/progress_item.h"
 #include "notification-ex/item_inflator.h"
 
+using namespace notification;
 using namespace notification::item;
 using namespace std;
 
index 49ea0fc423141bb9234012b21679753aed76664f..5224dfa56f09ab3135c3ace6f8b4ef0ce8fdd0d1 100644 (file)
@@ -20,6 +20,7 @@
 #include "notification-ex/text_item.h"
 #include "notification-ex/item_inflator.h"
 
+using namespace notification;
 using namespace notification::item;
 
 namespace {
index f595277a71d00676f917090f569e8bdafdb241da..fd7762df51b0ddaa74b297ec7509680aae549252 100644 (file)
@@ -20,6 +20,7 @@
 #include "notification-ex/time_item.h"
 #include "notification-ex/item_inflator.h"
 
+using namespace notification;
 using namespace notification::item;
 
 class TimeItemTest : public ::testing::Test {