+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <glib.h>
+#include <math.h>
+#include <gio/gio.h>
+
+#include <aul.h>
+#include <dlog.h>
+
+#include <notification-ex/manager.h>
+#include <notification-ex/reporter.h>
+#include <notification-ex/dbus_sender.h>
+#include <notification-ex/dbus_event_listener.h>
+#include <notification-ex/dbus_connection_manager.h>
+#include <notification-ex/button_item.h>
+#include <notification-ex/ex_util.h>
+
+#include "debug.h"
+#include "notification_ex_service.h"
+
+using namespace notification;
+using namespace std;
+
+class DPMFacade {
+ public:
+ DPMFacade(unique_ptr<Reporter> reporter, unique_ptr<Manager> manager)
+ : reporter_(move(reporter)), manager_(move(manager)) {
+ }
+
+ void DelegateReporterEvent(const EventInfo& info, shared_ptr<item::AbstractItem> item) {
+ reporter_->SendEvent(info, item);
+ }
+
+ void DelegateManagerEvent(const EventInfo& info, shared_ptr<item::AbstractItem> noti) {
+ manager_->SendEvent(info, noti);
+ }
+
+ unique_ptr<Reporter> reporter_;
+ unique_ptr<Manager> manager_;
+};
+
+static DPMFacade* facade_;
+
+class DPMReporter : public Reporter {
+ protected:
+ void OnEvent(const EventInfo& info,
+ list<shared_ptr<item::AbstractItem>> noti_list) override {
+ LOGI("Event received (%d) !!", (int)info.GetEventType());
+ for (auto& i : noti_list) {
+ facade_->DelegateManagerEvent(info, i);
+
+ /* noti to viewers */
+ facade_->DelegateReporterEvent(info, i);
+ }
+ }
+
+ list<shared_ptr<item::AbstractItem>> OnRequestEvent(const EventInfo& info) override {
+ DBG("Get report !!! %s", info.GetItemId().c_str());
+ list<shared_ptr<item::AbstractItem>> ret {
+ make_shared<item::ButtonItem>(info.GetItemId().c_str(), "title")
+ };
+ return ret;
+ }
+
+ public:
+ DPMReporter(std::unique_ptr<IEventSender> sender,
+ std::unique_ptr<IEventListener> listener)
+ : Reporter(move(sender), move(listener)) {
+ }
+};
+
+class DPMManager : public Manager {
+ protected:
+ void OnAdd(const EventInfo& info,
+ list<shared_ptr<item::AbstractItem>> addedItem) override {
+ DBG("Add !!!");
+ //TODO: store it to DB
+ for (auto& i : addedItem)
+ facade_->DelegateReporterEvent(info, i);
+ }
+
+ void OnUpdate(const EventInfo& info,
+ shared_ptr<item::AbstractItem> updatedItem) override {
+ DBG("Update !!!");
+ facade_->DelegateReporterEvent(info, updatedItem);
+ }
+
+ void OnDelete(const EventInfo& info,
+ shared_ptr<item::AbstractItem> deletedItem) override {
+ DBG("Delete !!!");
+ facade_->DelegateReporterEvent(info, deletedItem);
+ }
+
+ list<shared_ptr<item::AbstractItem>> OnRequestEvent(const EventInfo& info) override {
+ DBG("Get !!! %s", info.GetItemId().c_str());
+ //TODO: Get it from DB
+ list<shared_ptr<item::AbstractItem>> ret {
+ make_shared<item::ButtonItem>(info.GetItemId().c_str(), "title")
+ };
+ return ret;
+ }
+
+ public:
+ DPMManager(std::unique_ptr<IEventSender> sender,
+ std::unique_ptr<IEventListener> listener)
+ : Manager(move(sender), move(listener)) {
+ }
+};
+
+HAPI int notification_ex_service_init() {
+ facade_ = new DPMFacade(
+ unique_ptr<Reporter>(
+ new DPMReporter(
+ unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
+ unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath()))
+ )
+ ),
+ unique_ptr<Manager>(
+ new DPMManager(
+ unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
+ unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath()))
+ )
+ )
+ );
+
+ return 0;
+}
+
+HAPI int notification_ex_service_fini() {
+ delete facade_;
+ return 0;
+}
+
+HAPI GDBusConnection* notification_ex_service_get_gdbus_connection() {
+ return DBusConnectionManager::GetInst().GetConnection();
+}
\ No newline at end of file