#include "notification-ex/button_item.h"
#include "notification-ex/button_item_implementation.h"
-#include "notification-ex/item_factory.h"
+#include "notification-ex/factory_manager.h"
#ifdef LOG_TAG
#undef LOG_TAG
AbstractItem& ButtonItem::FindByID(std::string id) {
if (GetId() == id)
return *this;
- return ItemFactory::GetNullItem();
+ return FactoryManager::GetInst().GetNullItem();
}
std::string ButtonItem::GetTitle() const {
#include "notification-ex/chat_message_item.h"
#include "notification-ex/chat_message_item_implementation.h"
-#include "notification-ex/item_factory.h"
+#include "notification-ex/factory_manager.h"
#include "notification-ex/exception.h"
#ifdef LOG_TAG
}
void ChatMessageItem::Deserialize(Bundle b) {
- ItemFactory factory;
-
AbstractItem::Deserialize(b);
- std::shared_ptr<AbstractItem> name = factory.CreateItem(AbstractItem::Text);
+ std::shared_ptr<AbstractItem> name =
+ FactoryManager::GetInst().CreateItem(AbstractItem::Text);
name.get()->Deserialize(Bundle(b.GetString(CHATMESSAGE_NAME_KEY)));
impl_->name_ = std::static_pointer_cast<TextItem>(name);
- std::shared_ptr<AbstractItem> text = factory.CreateItem(AbstractItem::Text);
+ std::shared_ptr<AbstractItem> text =
+ FactoryManager::GetInst().CreateItem(AbstractItem::Text);
text.get()->Deserialize(Bundle(b.GetString(CHATMESSAGE_TEXT_KEY)));
impl_->text_ = std::static_pointer_cast<TextItem>(text);
- std::shared_ptr<AbstractItem> data = factory.CreateItem(AbstractItem::Text);
+ std::shared_ptr<AbstractItem> data =
+ FactoryManager::GetInst().CreateItem(AbstractItem::Text);
data.get()->Deserialize(Bundle(b.GetString(CHATMESSAGE_DATA_KEY)));
impl_->data_ = std::static_pointer_cast<TextItem>(data);
- std::shared_ptr<AbstractItem> time = factory.CreateItem(AbstractItem::Time);
+ std::shared_ptr<AbstractItem> time =
+ FactoryManager::GetInst().CreateItem(AbstractItem::Time);
time.get()->Deserialize(Bundle(b.GetString(CHATMESSAGE_TIME_KEY)));
impl_->time_ = std::static_pointer_cast<TimeItem>(time);
if (GetId() == id)
return *this;
- return ItemFactory::GetNullItem();
+ return FactoryManager::GetInst().GetNullItem();
}
TextItem& ChatMessageItem::GetNameItem() const {
#include "notification-ex/checkbox_item.h"
#include "notification-ex/checkbox_item_implementation.h"
-#include "notification-ex/item_factory.h"
+#include "notification-ex/factory_manager.h"
#include "notification-ex/exception.h"
#ifdef LOG_TAG
if (GetId() == id)
return *this;
- return ItemFactory::GetNullItem();
+ return FactoryManager::GetInst().GetNullItem();
}
std::string CheckBoxItem::GetTitle(void) const {
#include <memory>
-#include "notification-ex/item_factory.h"
+#include "notification-ex/default_item_factory.h"
#include "notification-ex/button_item.h"
#include "notification-ex/group_item.h"
-#include "notification-ex/null_item.h"
#include "notification-ex/entry_item.h"
#include "notification-ex/text_item.h"
#include "notification-ex/exception.h"
namespace notification {
namespace item {
-unique_ptr<AbstractItem> ItemFactory::CreateItem(AbstractItem::Type type) {
+unique_ptr<AbstractItem> DefaultItemFactory::CreateItem(AbstractItem::Type type) {
switch (type) {
case AbstractItem::NullObject :
THROW(NOTIFICATION_ERROR_INVALID_PARAMETER);
return nullptr;
}
-AbstractItem& ItemFactory::GetNullItem() {
- static NullItem item;
- return item;
-}
-
} // namespace item
} // namespace notification
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef NOTIFICATION_EX_DEFAULT_ITEM_FACTORY_H_
+#define NOTIFICATION_EX_DEFAULT_ITEM_FACTORY_H_
+
+#include <memory>
+
+#include "notification-ex/iitem_factory.h"
+
+namespace notification {
+namespace item {
+
+class EXPORT_API DefaultItemFactory : public IItemFactory {
+ public:
+ virtual ~DefaultItemFactory() = default;
+ std::unique_ptr<AbstractItem> CreateItem(AbstractItem::Type type);
+};
+
+} // namespace item
+} // namespace notification
+
+#endif // NOTIFICATION_EX_DEFAULT_ITEM_FACTORY_H_
#include "notification-ex/entry_item.h"
#include "notification-ex/entry_item_implementation.h"
-#include "notification-ex/item_factory.h"
+#include "notification-ex/factory_manager.h"
#ifdef LOG_TAG
#undef LOG_TAG
AbstractItem& EntryItem::FindByID(std::string id) {
if (GetId() == id)
return *this;
- return ItemFactory::GetNullItem();
+ return FactoryManager::GetInst().GetNullItem();
}
std::string EntryItem::GetText() const {
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dlog.h>
+
+#include "notification-ex/factory_manager.h"
+#include "notification-ex/default_item_factory.h"
+#include "notification-ex/null_item.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "NOTIFICATION_EX"
+
+using namespace std;
+namespace notification {
+namespace item {
+
+FactoryManager& FactoryManager::GetInst() {
+ static FactoryManager manager;
+
+ return manager;
+}
+
+void FactoryManager::RegisterFactory(std::unique_ptr<IItemFactory> factory) {
+ factory_ = std::move(factory);
+}
+
+std::unique_ptr<AbstractItem> FactoryManager::CreateItem(
+ AbstractItem::Type type) {
+ if (factory_.get() == nullptr)
+ factory_.reset(new DefaultItemFactory());
+
+ return factory_->CreateItem(type);
+}
+
+AbstractItem& FactoryManager::GetNullItem() {
+ static NullItem item;
+ return item;
+}
+
+} // namespace item
+} // namespace notification
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef NOTIFICATION_EX_FACTORY_MANAGER_H_
+#define NOTIFICATION_EX_FACTORY_MANAGER_H_
+
+#include <string>
+#include <memory>
+#include <list>
+
+#include "notification-ex/iitem_factory.h"
+
+namespace notification {
+namespace item {
+
+class EXPORT_API FactoryManager {
+ public:
+ static FactoryManager& GetInst();
+ void RegisterFactory(std::unique_ptr<IItemFactory> factory);
+ std::unique_ptr<AbstractItem> CreateItem(AbstractItem::Type type);
+ AbstractItem& GetNullItem();
+
+ private:
+ FactoryManager() {}
+
+ private:
+ std::unique_ptr<IItemFactory> factory_;
+};
+
+} // namespace item
+} // namespace notification
+
+#endif // NOTIFICATION_EX_FACTORY_MANAGER_H_
#include "notification-ex/group_item.h"
#include "notification-ex/group_item_implementation.h"
-#include "notification-ex/item_factory.h"
+#include "notification-ex/factory_manager.h"
#include "notification-ex/exception.h"
#ifdef LOG_TAG
if (str_arr.size() == 0)
return;
- ItemFactory factory;
for (string str : str_arr) {
Bundle serialized(str);
string type_str = serialized.GetString(GROUP_CHILDREN_TYPE_KEY);
AbstractItem::Type child_type =
static_cast<AbstractItem::Type>(strtol(type_str.c_str(), NULL, 10));
- shared_ptr<AbstractItem> child = factory.CreateItem(child_type);
+ shared_ptr<AbstractItem> child =
+ FactoryManager::GetInst().CreateItem(child_type);
child.get()->Deserialize(serialized);
AddChild(child);
}
if (i.get()->GetId() == id)
return *i;
}
- return ItemFactory::GetNullItem();
+ return FactoryManager::GetInst().GetNullItem();
}
void GroupItem::AddChild(shared_ptr<AbstractItem> child) {
#include "notification-ex/icon_text_item.h"
#include "notification-ex/icon_text_item_implementation.h"
-#include "notification-ex/item_factory.h"
+#include "notification-ex/factory_manager.h"
#include "notification-ex/exception.h"
#ifdef LOG_TAG
}
void IconTextItem::Deserialize(Bundle b) {
- ItemFactory factory;
-
AbstractItem::Deserialize(b);
- std::shared_ptr<AbstractItem> icon = factory.CreateItem(AbstractItem::Icon);
+ std::shared_ptr<AbstractItem> icon =
+ FactoryManager::GetInst().CreateItem(AbstractItem::Icon);
icon.get()->Deserialize(Bundle(b.GetString(ICONTEXT_PATH_KEY)));
impl_->icon_ = std::static_pointer_cast<IconItem>(icon);
- std::shared_ptr<AbstractItem> text = factory.CreateItem(AbstractItem::Text);
+ std::shared_ptr<AbstractItem> text =
+ FactoryManager::GetInst().CreateItem(AbstractItem::Text);
text.get()->Deserialize(Bundle(b.GetString(ICONTEXT_TITLE_KEY)));
impl_->text_ = std::static_pointer_cast<TextItem>(text);
}
if (GetId() == id)
return *this;
- return ItemFactory::GetNullItem();
+ return FactoryManager::GetInst().GetNullItem();
}
IconItem& IconTextItem::GetIconItem() const {
* limitations under the License.
*/
-#ifndef NOTIFICATION_EX_ITEM_FACTORY_H_
-#define NOTIFICATION_EX_ITEM_FACTORY_H_
+#ifndef NOTIFICATION_EX_IITEM_FACTORY_H_
+#define NOTIFICATION_EX_IITEM_FACTORY_H_
#include <string>
#include <memory>
namespace notification {
namespace item {
-class EXPORT_API ItemFactory {
+class EXPORT_API IItemFactory {
public:
- std::unique_ptr<AbstractItem> CreateItem(AbstractItem::Type type);
- static AbstractItem& GetNullItem();
+ virtual ~IItemFactory() = default;
+ virtual std::unique_ptr<AbstractItem> CreateItem(AbstractItem::Type type) = 0;
};
} // namespace item
#include "notification-ex/image_item.h"
#include "notification-ex/image_item_implementation.h"
-#include "notification-ex/item_factory.h"
+#include "notification-ex/factory_manager.h"
#include "notification-ex/exception.h"
#ifdef LOG_TAG
if (GetId() == id)
return *this;
- return ItemFactory::GetNullItem();
+ return FactoryManager::GetInst().GetNullItem();
}
std::string ImageItem::GetImagePath() const {
#include "notification-ex/input_selector_item.h"
#include "notification-ex/input_selector_item_implementation.h"
-#include "notification-ex/item_factory.h"
+#include "notification-ex/factory_manager.h"
#ifdef LOG_TAG
#undef LOG_TAG
AbstractItem& InputSelectorItem::FindByID(std::string id) {
if (GetId() == id)
return *this;
- return ItemFactory::GetNullItem();
+ return FactoryManager::GetInst().GetNullItem();
}
list<string> InputSelectorItem::GetContents() const {
#include <memory>
-#include "notification-ex/item_factory.h"
+#include "notification-ex/factory_manager.h"
#include "notification-ex/item_inflator.h"
#ifdef LOG_TAG
namespace notification {
namespace item {
-shared_ptr<AbstractItem> ItemInflator::Create(ItemFactory factory, Bundle b) {
- shared_ptr<AbstractItem> item = factory.CreateItem(AbstractItem::GetType(b));
+shared_ptr<AbstractItem> ItemInflator::Create(Bundle b) {
+ shared_ptr<AbstractItem> item =
+ FactoryManager::GetInst().CreateItem(AbstractItem::GetType(b));
item.get()->Deserialize(b);
return item;
}
#include <list>
#include "notification-ex/abstract_item.h"
-#include "notification-ex/item_factory.h"
namespace notification {
namespace item {
class EXPORT_API ItemInflator {
public:
- static std::shared_ptr<AbstractItem> Create(ItemFactory factory, Bundle b);
+ static std::shared_ptr<AbstractItem> Create(Bundle b);
};
} // namespace item
#include "notification-ex/exception.h"
#include "notification-ex/progress_item.h"
#include "notification-ex/progress_item_implementation.h"
-#include "notification-ex/item_factory.h"
+#include "notification-ex/factory_manager.h"
#ifdef LOG_TAG
#undef LOG_TAG
AbstractItem& ProgressItem::FindByID(std::string id) {
if (GetId() == id)
return *this;
- return ItemFactory::GetNullItem();
+ return FactoryManager::GetInst().GetNullItem();
}
float ProgressItem::GetCurrent() const {
#include "notification-ex/text_item.h"
#include "notification-ex/text_item_implementation.h"
-#include "notification-ex/item_factory.h"
+#include "notification-ex/factory_manager.h"
#ifdef LOG_TAG
#undef LOG_TAG
AbstractItem& TextItem::FindByID(std::string id) {
if (GetId() == id)
return *this;
- return ItemFactory::GetNullItem();
+ return FactoryManager::GetInst().GetNullItem();
}
void TextItem::SetContents(std::string contents) {
#include "notification-ex/time_item.h"
#include "notification-ex/time_item_implementation.h"
-#include "notification-ex/item_factory.h"
+#include "notification-ex/factory_manager.h"
#include "notification-ex/exception.h"
#ifdef LOG_TAG
if (GetId() == id)
return *this;
- return ItemFactory::GetNullItem();
+ return FactoryManager::GetInst().GetNullItem();
}
time_t TimeItem::GetTime() const {
TEST_F(ButtonItemTest, SerializeDeserializeGetTitle) {
ButtonItem item("title");
Bundle b = item.Serialize();
- ItemFactory factory;
- shared_ptr<AbstractItem> gen_item = ItemInflator::Create(factory, b);
+ shared_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
ASSERT_EQ(gen_item.get()->GetType(), item.GetType());
ButtonItem* gen_btn = static_cast<ButtonItem*>(gen_item.get());
TEST_F(ChatMessageItemTest, SerializeDeserialize) {
Bundle b = ChatMessageItemTest::item->Serialize();
- ItemFactory factory;
- std::shared_ptr<AbstractItem> gen_item = ItemInflator::Create(factory, b);
+ std::shared_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
ChatMessageItem* gen_message = static_cast<ChatMessageItem*>(gen_item.get());
ASSERT_EQ(gen_message->GetNameItem().GetContents(), "name");
ASSERT_EQ(gen_message->GetTextItem().GetContents(), "text");
TEST_F(CheckBoxItemTest, SerializeDeserialize) {
Bundle b = CheckBoxItemTest::item->Serialize();
- ItemFactory factory;
- std::shared_ptr<AbstractItem> gen_item = ItemInflator::Create(factory, b);
+ std::shared_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
ASSERT_EQ(CheckBoxItemTest::item->GetType(), gen_item.get()->GetType());
CheckBoxItem* gen_checkbox = static_cast<CheckBoxItem*>(gen_item.get());
TEST_F(EntryItemTest, SerializeDeserialize) {
EntryItem item("entry_id");
Bundle b = item.Serialize();
- ItemFactory factory;
- std::shared_ptr<AbstractItem> gen_item = ItemInflator::Create(factory, b);
+ std::shared_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
ASSERT_EQ(gen_item.get()->GetType(), item.GetType());
EntryItem* gen_effect = static_cast<EntryItem*>(gen_item.get());
item.AddChild(std::make_shared<ButtonItem>("btn2", "test2"));
Bundle b = item.Serialize();
- ItemFactory factory;
- shared_ptr<AbstractItem> gen_item = ItemInflator::Create(factory, b);
+ shared_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
ASSERT_EQ(gen_item.get()->GetType(), item.GetType());
GroupItem* gen_group = static_cast<GroupItem*>(gen_item.get());
TEST_F(IconItemTest, SerializeDeserialize) {
Bundle b = IconItemTest::item->Serialize();
- ItemFactory factory;
- std::shared_ptr<AbstractItem> gen_item = ItemInflator::Create(factory, b);
+ std::shared_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
ASSERT_EQ(IconItemTest::item->GetType(), gen_item.get()->GetType());
IconItem* gen_icon = static_cast<IconItem*>(gen_item.get());
TEST_F(IconTextItemTest, SerializeDeserialize) {
Bundle b = IconTextItemTest::item->Serialize();
- ItemFactory factory;
- std::shared_ptr<AbstractItem> gen_item = ItemInflator::Create(factory, b);
+ std::shared_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
IconTextItem* gen_icon = static_cast<IconTextItem*>(gen_item.get());
ASSERT_EQ(IconTextItemTest::item->GetIconItem().GetImagePath(), gen_icon->GetIconItem().GetImagePath());
ASSERT_EQ(IconTextItemTest::item->GetTextItem().GetContents(), gen_icon->GetTextItem().GetContents());
TEST_F(ImageItemTest, SerializeDeserialize) {
Bundle b = ImageItemTest::item->Serialize();
- ItemFactory factory;
- std::shared_ptr<AbstractItem> gen_item = ItemInflator::Create(factory, b);
+ std::shared_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
ASSERT_EQ(ImageItemTest::item->GetType(), gen_item.get()->GetType());
ImageItem* gen_image = static_cast<ImageItem*>(gen_item.get());
item.SetContents(contents);
Bundle b = item.Serialize();
- ItemFactory factory;
- shared_ptr<AbstractItem> gen_item = ItemInflator::Create(factory, b);
+ shared_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
ASSERT_EQ(gen_item.get()->GetType(), item.GetType());
InputSelectorItem* gen_input = static_cast<InputSelectorItem*>(gen_item.get());
TEST_F(ProgressItemTest, SerializeDeserializeGetTitle) {
ProgressItem item(1.0, 10.0, 100.0);
Bundle b = item.Serialize();
- ItemFactory factory;
- shared_ptr<AbstractItem> gen_item = ItemInflator::Create(factory, b);
+ shared_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
ASSERT_EQ(gen_item.get()->GetType(), item.GetType());
ProgressItem* gen_progress = static_cast<ProgressItem*>(gen_item.get());
TEST_F(TexttItemTest, SerializeDeserializeGetContents) {
TextItem item("text_id", "contents");
Bundle b = item.Serialize();
- ItemFactory factory;
- std::shared_ptr<AbstractItem> gen_item = ItemInflator::Create(factory, b);
+ std::shared_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
ASSERT_EQ(gen_item.get()->GetType(), item.GetType());
TextItem* gen_text = static_cast<TextItem*>(gen_item.get());
TEST_F(TimeItemTest, SerializeDeserialize) {
Bundle b = TimeItemTest::item->Serialize();
- ItemFactory factory;
- std::shared_ptr<AbstractItem> gen_item = ItemInflator::Create(factory, b);
+ std::shared_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
ASSERT_EQ(TimeItemTest::item->GetType(), gen_item.get()->GetType());
TimeItem* gen_time = static_cast<TimeItem*>(gen_item.get());