Create FactoryManager to register the other factory
[platform/core/api/notification.git] / notification-ex / entry_item.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 <memory>
20
21 #include "notification-ex/entry_item.h"
22 #include "notification-ex/entry_item_implementation.h"
23 #include "notification-ex/factory_manager.h"
24
25 #ifdef LOG_TAG
26 #undef LOG_TAG
27 #endif
28
29 #define LOG_TAG "NOTIFICATION_EX"
30 #define ENTRY_TEXT_KEY "__ENTRY_TEXT_KEY__"
31 #define ENTRY_LIMIT_KEY "__ENTRY_LIMIT_KEY__"
32
33 namespace notification {
34 namespace item {
35
36 EntryItem::EntryItem(std::string id, std::shared_ptr<AbstractAction> action)
37   : AbstractItem(id, AbstractItem::Type::Entry), impl_(new Impl()) {
38 }
39
40 EntryItem::EntryItem(std::shared_ptr<AbstractAction> action)
41   : AbstractItem(AbstractItem::Type::Entry), impl_(new Impl()) {
42 }
43
44 EntryItem::Impl::Impl() {
45   LOGI("EntryItem created");
46 }
47
48 EntryItem::~EntryItem() = default;
49 EntryItem::Impl::~Impl() = default;
50
51 Bundle EntryItem::Serialize() {
52   Bundle b;
53   b = AbstractItem::Serialize();
54
55   if (!impl_->text_.empty())
56     b.Add(ENTRY_TEXT_KEY, impl_->text_);
57
58   b.Add(ENTRY_LIMIT_KEY, std::to_string(impl_->limit_));
59
60   return b;
61 }
62
63 void EntryItem::Deserialize(Bundle b) {
64   AbstractItem::Deserialize(b);
65   impl_->text_ = b.GetString(ENTRY_TEXT_KEY);
66   impl_->limit_ = std::stoi(b.GetString(ENTRY_LIMIT_KEY));
67 }
68
69 AbstractItem& EntryItem::FindByID(std::string id) {
70   if (GetId() == id)
71     return *this;
72   return FactoryManager::GetInst().GetNullItem();
73 }
74
75 std::string EntryItem::GetText() const {
76   return impl_->text_;
77 }
78
79 void EntryItem::SetText(std::string text) {
80   impl_->text_ = text;
81 }
82
83 int EntryItem::GetTextLimit() const {
84   return impl_->limit_;
85 }
86
87 }  // namespace item
88 }  // namespace notification