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.
22 #include "notification-ex/event_info_internal.h"
23 #include "notification-ex/event_info_implementation.h"
24 #include "notification-ex/ex_util.h"
30 #define LOG_TAG "NOTIFICATION_EX"
31 #define NOTIFICATION_EX_EVENT_TYPE_KEY "__NOTIFICATION_EX_EVENT_TYPE_KEY__"
32 #define NOTIFICATION_EX_EVENT_OWNER_KEY "__NOTIFICATION_EX_EVENT_OWNER_KEY__"
33 #define NOTIFICATION_EX_EVENT_CHANNEL_KEY "__NOTIFICATION_EX_EVENT_CHANNEL_KEY__"
34 #define NOTIFICATION_EX_EVENT_ITEM_ID_KEY "__NOTIFICATION_EX_EVENT_ITEM_ID_KEY__"
35 #define NOTIFICATION_EX_EVENT_UID_KEY "__NOTIFICATION_EX_EVENT_UID_KEY__"
36 #define NOTIFICATION_EX_EVENT_REQUEST_ID_KEY "__NOTIFICATION_EX_EVENT_REQUEST_ID_KEY__"
37 #define NOTIFICATION_EX_EVENT_ERROR_KEY "__NOTIFICATION_EX_EVENT_ERROR_KEY__"
40 using namespace tizen_base;
41 namespace notification {
43 EventInfo::EventInfo(int type, std::string owner, std::string channel,
45 : impl_(new Impl(this, type, owner, channel, item_id)) {
47 EventInfo::~EventInfo() = default;
48 EventInfo::Impl::~Impl() = default;
50 EventInfo::Impl::Impl(EventInfo* parent, int type, std::string owner,
51 std::string channel, std::string item_id)
52 : type_(type), owner_(owner), channel_(channel), item_id_(item_id),
55 request_id_ = util::GetRequestId();
57 LOGI("EventInfo impl created");
60 EventInfo::EventInfo(Bundle serialized)
61 : impl_(new Impl(this, EventInfo::Post, "", "", "")) {
62 string event_str = serialized.GetString(NOTIFICATION_EX_EVENT_TYPE_KEY);
63 impl_->type_ = std::stoi(event_str, nullptr, 10);
64 impl_->owner_ = serialized.GetString(NOTIFICATION_EX_EVENT_OWNER_KEY);
65 impl_->channel_ = serialized.GetString(NOTIFICATION_EX_EVENT_CHANNEL_KEY);
66 impl_->item_id_ = serialized.GetString(NOTIFICATION_EX_EVENT_ITEM_ID_KEY);
67 string uid_str = serialized.GetString(NOTIFICATION_EX_EVENT_UID_KEY);
68 impl_->uid_ = (uid_t)std::stoi(uid_str, nullptr, 10);
69 string request_id_str =
70 serialized.GetString(NOTIFICATION_EX_EVENT_REQUEST_ID_KEY);
71 impl_->request_id_ = std::stoi(request_id_str, nullptr, 10);
73 serialized.GetString(NOTIFICATION_EX_EVENT_ERROR_KEY);
74 impl_->error_ = (NotificationError)strtol(error_str.c_str(), NULL, 10);
77 string EventInfo::GetString(int type) {
98 return "Custom" + std::to_string(Custom);
102 Bundle EventInfo::Serialize() const {
104 serialized.Add(NOTIFICATION_EX_EVENT_TYPE_KEY, to_string(static_cast<int>(impl_->type_)));
105 serialized.Add(NOTIFICATION_EX_EVENT_OWNER_KEY, impl_->owner_);
106 serialized.Add(NOTIFICATION_EX_EVENT_CHANNEL_KEY, impl_->channel_);
107 serialized.Add(NOTIFICATION_EX_EVENT_ITEM_ID_KEY, impl_->item_id_);
108 serialized.Add(NOTIFICATION_EX_EVENT_UID_KEY, to_string(static_cast<int>(impl_->uid_)));
110 NOTIFICATION_EX_EVENT_REQUEST_ID_KEY, to_string(impl_->request_id_));
112 NOTIFICATION_EX_EVENT_ERROR_KEY, to_string(impl_->error_));
117 int EventInfo::GetEventType() const {
121 void EventInfo::SetEventType(int type) {
125 string EventInfo::GetOwner() const {
126 return impl_->owner_;
129 string EventInfo::GetChannel() const {
130 return impl_->channel_;
133 string EventInfo::GetItemId() const {
134 return impl_->item_id_;
137 uid_t EventInfo::GetUid() const {
141 void EventInfo::SetUid(uid_t uid) {
145 int EventInfo::GetRequestId() const {
146 return impl_->request_id_;
149 NotificationError EventInfo::GetError() const {
150 return impl_->error_;
153 void EventInfo::SetError(NotificationError error) {
154 impl_->error_ = error;
157 } // namespace notification