2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
27 #include <notification-ex/manager.h>
28 #include <notification-ex/reporter.h>
29 #include <notification-ex/dbus_sender.h>
30 #include <notification-ex/dbus_event_listener.h>
31 #include <notification-ex/dbus_connection_manager.h>
32 #include <notification-ex/button_item.h>
33 #include <notification-ex/ex_util.h>
36 #include "notification_ex_service.h"
38 using namespace notification;
43 DPMFacade(unique_ptr<Reporter> reporter, unique_ptr<Manager> manager)
44 : reporter_(move(reporter)), manager_(move(manager)) {
47 void DelegateReporterEvent(const EventInfo& info, shared_ptr<item::AbstractItem> item) {
48 reporter_->SendEvent(info, item);
51 void DelegateManagerEvent(const EventInfo& info, shared_ptr<item::AbstractItem> noti) {
52 manager_->SendEvent(info, noti);
55 unique_ptr<Reporter> reporter_;
56 unique_ptr<Manager> manager_;
59 static DPMFacade* facade_;
61 class DPMReporter : public Reporter {
63 void OnEvent(const EventInfo& info,
64 list<shared_ptr<item::AbstractItem>> noti_list) override {
65 LOGI("Event received (%d) !!", (int)info.GetEventType());
66 for (auto& i : noti_list) {
67 facade_->DelegateManagerEvent(info, i);
70 facade_->DelegateReporterEvent(info, i);
74 list<shared_ptr<item::AbstractItem>> OnRequestEvent(const EventInfo& info) override {
75 DBG("Get report !!! %s", info.GetItemId().c_str());
76 list<shared_ptr<item::AbstractItem>> ret {
77 make_shared<item::ButtonItem>(info.GetItemId().c_str(), "title")
83 DPMReporter(std::unique_ptr<IEventSender> sender,
84 std::unique_ptr<IEventListener> listener)
85 : Reporter(move(sender), move(listener)) {
89 class DPMManager : public Manager {
91 void OnAdd(const EventInfo& info,
92 list<shared_ptr<item::AbstractItem>> addedItem) override {
94 //TODO: store it to DB
95 for (auto& i : addedItem)
96 facade_->DelegateReporterEvent(info, i);
99 void OnUpdate(const EventInfo& info,
100 shared_ptr<item::AbstractItem> updatedItem) override {
102 facade_->DelegateReporterEvent(info, updatedItem);
105 void OnDelete(const EventInfo& info,
106 shared_ptr<item::AbstractItem> deletedItem) override {
108 facade_->DelegateReporterEvent(info, deletedItem);
111 list<shared_ptr<item::AbstractItem>> OnRequestEvent(const EventInfo& info) override {
112 DBG("Get !!! %s", info.GetItemId().c_str());
113 //TODO: Get it from DB
114 list<shared_ptr<item::AbstractItem>> ret {
115 make_shared<item::ButtonItem>(info.GetItemId().c_str(), "title")
121 DPMManager(std::unique_ptr<IEventSender> sender,
122 std::unique_ptr<IEventListener> listener)
123 : Manager(move(sender), move(listener)) {
127 HAPI int notification_ex_service_init() {
128 facade_ = new DPMFacade(
129 unique_ptr<Reporter>(
131 unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
132 unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath()))
137 unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
138 unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath()))
146 HAPI int notification_ex_service_fini() {
151 HAPI GDBusConnection* notification_ex_service_get_gdbus_connection() {
152 return DBusConnectionManager::GetInst().GetConnection();