Merge branch 'tizen' into tizen_5.5
[platform/core/api/notification.git] / notification-ex / abstract_action.cc
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <dlog.h>
18
19 #include "notification-ex/abstract_action.h"
20 #include "notification-ex/abstract_action_implementation.h"
21
22 #ifdef LOG_TAG
23 #undef LOG_TAG
24 #endif
25
26 #define LOG_TAG "NOTIFICATION_EX"
27 #define ABSTRACT_ACTION_TYPE_KEY "__ABSTRACT_ACTION_TYPE_KEY__"
28 #define ABSTRACT_ACTION_IS_LOCAL_KEY "__ABSTRACT_ACTION_IS_LOCAL_KEY__"
29 #define ABSTRACT_ACTION_EXTRA_KEY "__ABSTRACT_ACTION_EXTRA_KEY__"
30
31 using namespace tizen_base;
32
33 namespace notification {
34 namespace item {
35 AbstractAction::AbstractAction(bool isLocal)
36     : impl_(new Impl(this, isLocal)) {
37 }
38
39 AbstractAction::AbstractAction(bool isLocal, std::string extra)
40     : impl_(new Impl(this, isLocal, extra)) {
41 }
42
43 AbstractAction::Impl::Impl(AbstractAction* parent, bool isLocal)
44     : parent_(parent) , isLocal_(isLocal) {
45   LOGI("Action created");
46 }
47
48 AbstractAction::Impl::Impl(AbstractAction* parent, bool isLocal,
49     std::string extra) : parent_(parent) , isLocal_(isLocal), extra_(extra) {
50   LOGI("Action created");
51 }
52
53 AbstractAction::~AbstractAction() = default;
54 AbstractAction::Impl::~Impl() = default;
55
56 int AbstractAction::GetType(Bundle b) {
57   return std::stoi(b.GetString(ABSTRACT_ACTION_TYPE_KEY));
58 }
59
60 Bundle AbstractAction::Serialize() const {
61   Bundle b;
62
63   b.Add(ABSTRACT_ACTION_TYPE_KEY, std::to_string(GetType()));
64   b.Add(ABSTRACT_ACTION_IS_LOCAL_KEY, std::to_string(impl_->isLocal_));
65   if (!impl_->extra_.empty())
66     b.Add(ABSTRACT_ACTION_EXTRA_KEY, impl_->extra_);
67   return b;
68 }
69
70 void AbstractAction::Deserialize(Bundle b) {
71   impl_->isLocal_ = std::stoi(b.GetString(ABSTRACT_ACTION_IS_LOCAL_KEY));
72   impl_->extra_ = b.GetString(ABSTRACT_ACTION_EXTRA_KEY);
73 }
74
75 bool AbstractAction::IsLocal() const {
76   return impl_->isLocal_;
77 }
78
79 void AbstractAction::Execute(std::shared_ptr<AbstractItem> item) {
80 }
81
82 std::string AbstractAction::GetExtra() const {
83   return impl_->extra_;
84 }
85
86 }  // namespace item
87 }  // namespace notification