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.
23 #include "notification-ex/reporter.h"
24 #include "notification-ex/reporter_implementation.h"
25 #include "notification-ex/event_info.h"
26 #include "notification-ex/item_inflator.h"
27 #include "notification-ex/dbus_connection_manager.h"
28 #include "notification-ex/ex_util.h"
34 #define LOG_TAG "NOTIFICATION_EX"
36 #define MAX_PACKAGE_STR_SIZE 512
37 #define NOTIFICATION_EX_REPORTER_OBJECT_PATH "/org/tizen/notification_ex_reporter"
40 using namespace notification::item;
41 namespace notification {
43 Reporter::Reporter(IEventSender* sender, IEventListener* listener)
44 : impl_(new Impl(this, sender, listener)) {
46 Reporter::~Reporter() = default;
48 Reporter::Impl::~Impl() {
49 listener_->UnRegisterObserver(parent_);
51 Reporter::Impl::Impl(Reporter* parent,
52 IEventSender* sender, IEventListener* listener)
53 : sender_(sender), listener_(listener), parent_(parent) {
55 listener_->RegisterObserver(parent_);
58 void Reporter::Impl::SendNotify(shared_ptr<item::AbstractItem> noti,
59 EventInfo::EventType type) {
60 Bundle serialized = noti->Serialize();
61 EventInfo info(type, util::GetAppId(), noti->GetChannel());
62 list<Bundle> serialized_list {serialized};
63 sender_->Notify(info, serialized_list);
66 void Reporter::Post(std::shared_ptr<item::AbstractItem> noti) {
68 impl_->SendNotify(noti, EventInfo::Post);
71 void Reporter::Post(std::list<std::shared_ptr<AbstractItem>> notiList) {
72 EventInfo info(EventInfo::Post, util::GetAppId(), "");
73 list<Bundle> serialized_list;
74 for (auto& i : notiList) {
75 Bundle b = i->Serialize();
76 serialized_list.push_back(b);
78 impl_->sender_->Notify(info, serialized_list);
81 void Reporter::Update(std::shared_ptr<AbstractItem> noti) {
82 impl_->SendNotify(noti, EventInfo::Update);
85 void Reporter::Remove(std::shared_ptr<AbstractItem> noti) {
86 impl_->SendNotify(noti, EventInfo::Delete);
89 std::shared_ptr<AbstractItem> Reporter::FindByRootID(std::string id) {
91 EventInfo info(EventInfo::Get,
92 util::GetAppId(), "", id);
93 list<Bundle> result = impl_->sender_->Request(info);
94 if (result.size() == 0) {
95 LOGE("Fail to get noti");
96 return shared_ptr<item::AbstractItem>({});
98 Bundle b = result.front();
99 shared_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
103 void Reporter::SendEvent(const EventInfo& info, shared_ptr<item::AbstractItem> noti) {
104 Bundle serialized = noti->Serialize();
105 list<Bundle> serialized_list {serialized};
106 impl_->sender_->Notify(info, serialized_list);
109 void Reporter::OnEvent(const EventInfo& info, list<Bundle> serialized) {
110 list<shared_ptr<item::AbstractItem>> item_list;
111 for (auto& i : serialized) {
112 shared_ptr<AbstractItem> gen_item = ItemInflator::Create(i);
113 item_list.emplace_back(gen_item);
115 OnEvent(info, item_list);
118 list<shared_ptr<item::AbstractItem>> Reporter::OnRequestEvent(const EventInfo& info) {
119 return list<shared_ptr<item::AbstractItem>>({});
122 list<Bundle> Reporter::OnRequest(const EventInfo& info) {
123 list<shared_ptr<item::AbstractItem>> item_list = OnRequestEvent(info);
124 list<Bundle> serialized_list;
125 for (auto& i : item_list) {
126 serialized_list.push_back(i->Serialize());
128 return serialized_list;
131 void Reporter::OnEvent(
132 const EventInfo& info, list<shared_ptr<item::AbstractItem>> notiList) {
135 string Reporter::GetPath() {
136 return NOTIFICATION_EX_REPORTER_OBJECT_PATH;
139 } // nampace notification