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>
77 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 [moved from notification-ex/dbus_manager.h with 67% similarity]
notification-ex/dbus_event_listener.cc [new file with mode: 0644]
notification-ex/dbus_event_listener.h [moved from notification-ex/dbus_listener.h with 60% similarity]
notification-ex/dbus_event_listener_implementation.h [new file with mode: 0644]
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 [moved from notification-ex/observer_interface.h with 84% similarity]
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/progress_item.cc
notification-ex/progress_item.h
notification-ex/reporter.cc [new file with mode: 0644]
notification-ex/reporter.h [moved from notification-ex/repoter.h with 50% similarity]
notification-ex/reporter_implementation.h [new file with mode: 0644]
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 cebea32..ea587cc 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 7b9ec9e..e37ee52 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 cb1063d..0e001b8 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 0bdcdcc..8e0edae 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 e5b5e7f..043f6a1 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 4f4b942..eaada76 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 df2ec90..5108c11 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 0839eb0..6d53e92 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 284b806..3042d35 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 6f459d2..6cfd30d 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 1970a87..2a94bb1 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 1321b0b..4ccf313 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 97cba96..7fb4873 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 27c9fbd..6eab2ea 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 8a0a67d..68e01e9 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
similarity index 67%
rename from notification-ex/dbus_manager.h
rename to notification-ex/dbus_connection_manager.h
index 8c1943d..9b37f09 100644 (file)
 #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 DBusConnectionManager {
+class EXPORT_API DBusConnectionManager {
  public:
   static DBusConnectionManager& GetInst();
-  GDbusConnection& GetConnection();
+  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();
-  GDbusConnection connection_;
+  int Init();
+  GDBusConnection* connection_ = nullptr;
+  bool is_DPM_ = false;
 };
 
 }  // namespace notification
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
similarity index 60%
rename from notification-ex/dbus_listener.h
rename to notification-ex/dbus_event_listener.h
index e0ad60a..bea87d7 100644 (file)
 #ifndef NOTIFICATION_EX_DBUS_LISTENER_H_
 #define NOTIFICATION_EX_DBUS_LISTENER_H_
 
-#include "notification-ex/observer_interface.h"
+#include <gio/gio.h>
+
+#include "notification-ex/event_listener_interface.h"
 
 namespace notification {
 
-class EXPORT_API DBusEventsListener : public IEventListener {
+class EXPORT_API DBusEventListener : public IEventListener {
  public:
-  DBusEventsListener();
-  ~DBusEventsListener();
+  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;
 
-  void RegisterObserver(IEventObserver observer) override;
-  void UnRegisterObserver(IEventObserver observer) override;
-  void NotifyAll() override;
+ private:
+  class Impl;
+  std::unique_ptr<Impl> impl_;
 };
 
 }  // namespace notification
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_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 b8063be..a347bcf 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 29bf5fc..dd62de0 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 d3dcf66..38a32fb 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 55b31b8..5b998b3 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 3990271..7d95807 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
similarity index 84%
rename from notification-ex/observer_interface.h
rename to notification-ex/event_observer_interface.h
index 7ea61f6..a94abe8 100644 (file)
@@ -28,9 +28,9 @@ namespace notification {
 
 class EXPORT_API IEventObserver {
  public:
-  virtual ~IEventObserver() = 0;
-
-  virtual void OnEvent(EventInfo info, std::shared_ptr<AbstractItem> noti) = 0;
+  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
index 3c42a4e..fcefaec 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 1640f00..4eaf47f 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 d6a53da..6e65f0a 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 51d1b65..2989c74 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 1006bfa..a237ae9 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 4fdc44f..2653076 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 56f667b..46c7f10 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 c9e8701..bce699d 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 c2bad80..ea53650 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 5115552..37867e2 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 6b1220a..f9a873a 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 2b456ce..6bf60ff 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 5c9d1b1..918513a 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 8942ba1..56b2b34 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 769c735..509a525 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 a4fdc5e..e51c660 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 819677e..5d688d2 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 cf27164..6864c1a 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;
 };
index fecefbc..36dd5df 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 d3d4b9e..04fa3a7 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
similarity index 50%
rename from notification-ex/repoter.h
rename to notification-ex/reporter.h
index 90cbf6f..61aa457 100644 (file)
 #include <string>
 #include <list>
 
-#include "notification-ex/abstract_item.h"
 #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")))
 
 namespace notification {
 
-class EXPORT_API Repoter : public IEventObserver {
+class EXPORT_API Reporter : public IEventObserver {
  public:
-  Repoter(IEventsSender* sender, IEventsListener* listener);
-  virtual ~Repoter();
+  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<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;
+  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:
-  IEventsSender* sender_;
-  IEventsListener* receiver_;
+  class Impl;
+  std::unique_ptr<Impl> impl_;
 };
 
 }  // namespace notification
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_
index f9543ac..f5d5ed2 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 b7487fa..9f9a987 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 fc7fbf9..0816373 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 388a9b4..29a8d56 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 3ff4dfe..1ec90b5 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 c4e7b7a..ebc543a 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 52c67d4..6aef59a 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 d56e3bd..5af53a6 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 3320832..7e28128 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 20a86cf..086e517 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 8aa0e6b..cca8c4d 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 da933d3..8bc9d4e 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 6288c8d..fb4b63b 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 cd2fdbf..2370467 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 423d052..20451e2 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 5aa45e2..a12e58c 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 d2db27d..7a02da8 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 d62aab3..a592e44 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 49ea0fc..5224dfa 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 f595277..fd7762d 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 {