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();
58 LOGI("EventInfo impl created");
61 EventInfo::EventInfo(Bundle serialized)
62 : impl_(new Impl(this, EventInfo::Post, "", "", "")) {
63 string event_str = serialized.GetString(NOTIFICATION_EX_EVENT_TYPE_KEY);
64 impl_->type_ = std::stoi(event_str, nullptr, 10);
65 impl_->owner_ = serialized.GetString(NOTIFICATION_EX_EVENT_OWNER_KEY);
66 impl_->channel_ = serialized.GetString(NOTIFICATION_EX_EVENT_CHANNEL_KEY);
67 impl_->item_id_ = serialized.GetString(NOTIFICATION_EX_EVENT_ITEM_ID_KEY);
68 string uid_str = serialized.GetString(NOTIFICATION_EX_EVENT_UID_KEY);
69 impl_->uid_ = (uid_t)std::stoi(uid_str, nullptr, 10);
70 string request_id_str =
71 serialized.GetString(NOTIFICATION_EX_EVENT_REQUEST_ID_KEY);
72 impl_->request_id_ = std::stoi(request_id_str, nullptr, 10);
74 serialized.GetString(NOTIFICATION_EX_EVENT_ERROR_KEY);
75 impl_->error_ = (NotificationError)strtol(error_str.c_str(), NULL, 10);
78 string EventInfo::GetString(int type) {
99 return "Custom" + std::to_string(Custom);
103 Bundle EventInfo::Serialize() const {
105 serialized.Add(NOTIFICATION_EX_EVENT_TYPE_KEY, to_string(static_cast<int>(impl_->type_)));
106 serialized.Add(NOTIFICATION_EX_EVENT_OWNER_KEY, impl_->owner_);
107 serialized.Add(NOTIFICATION_EX_EVENT_CHANNEL_KEY, impl_->channel_);
108 serialized.Add(NOTIFICATION_EX_EVENT_ITEM_ID_KEY, impl_->item_id_);
109 serialized.Add(NOTIFICATION_EX_EVENT_UID_KEY, to_string(static_cast<int>(impl_->uid_)));
111 NOTIFICATION_EX_EVENT_REQUEST_ID_KEY, to_string(impl_->request_id_));
113 NOTIFICATION_EX_EVENT_ERROR_KEY, to_string(impl_->error_));
118 int EventInfo::GetEventType() const {
122 void EventInfo::SetEventType(int type) {
126 string EventInfo::GetOwner() const {
127 return impl_->owner_;
130 void EventInfo::SetValidatedOwner(std::string owner) {
131 impl_->validated_owner_ = owner;
134 string EventInfo::GetValidatedOwner() const {
135 return impl_->validated_owner_;
138 string EventInfo::GetChannel() const {
139 return impl_->channel_;
142 string EventInfo::GetItemId() const {
143 return impl_->item_id_;
146 uid_t EventInfo::GetUid() const {
150 void EventInfo::SetUid(uid_t uid) {
154 uid_t EventInfo::GetValidatedUid() const {
155 return impl_->validated_uid_;
158 void EventInfo::SetValidatedUid(uid_t uid) {
159 impl_->validated_uid_ = uid;
162 int EventInfo::GetRequestId() const {
163 return impl_->request_id_;
166 NotificationError EventInfo::GetError() const {
167 return impl_->error_;
170 void EventInfo::SetError(NotificationError error) {
171 impl_->error_ = error;
174 } // namespace notification