Create FactoryManager to register the other factory 50/201150/3
authorJunghoon Park <jh9216.park@samsung.com>
Mon, 11 Mar 2019 02:10:28 +0000 (11:10 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Mon, 11 Mar 2019 02:33:46 +0000 (11:33 +0900)
Change-Id: Ibd3b9131be2cba08796e04d4d3be459159442134
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
32 files changed:
notification-ex/button_item.cc
notification-ex/chat_message_item.cc
notification-ex/checkbox_item.cc
notification-ex/default_item_factory.cc [new file with mode: 0644]
notification-ex/default_item_factory.h [new file with mode: 0644]
notification-ex/entry_item.cc
notification-ex/factory_manager.cc [new file with mode: 0644]
notification-ex/factory_manager.h [new file with mode: 0644]
notification-ex/group_item.cc
notification-ex/icon_text_item.cc
notification-ex/iitem_factory.h [new file with mode: 0644]
notification-ex/image_item.cc
notification-ex/input_selector_item.cc
notification-ex/item_factory.cc [deleted file]
notification-ex/item_factory.h [deleted file]
notification-ex/item_inflator.cc
notification-ex/item_inflator.h
notification-ex/progress_item.cc
notification-ex/text_item.cc
notification-ex/time_item.cc
unittest/src/test_button_item.cc
unittest/src/test_chat_message_item.cc
unittest/src/test_checkbox_item.cc
unittest/src/test_entry_item.cc
unittest/src/test_group_item.cc
unittest/src/test_icon_item.cc
unittest/src/test_icon_text_item.cc
unittest/src/test_image_item.cc
unittest/src/test_input_selector_item.cc
unittest/src/test_progress_item.cc
unittest/src/test_text_item.cc
unittest/src/test_time_item.cc

index f4a33d8e92ae9ca2f99758bd68bdf8ab1d19e7a2..0ac285818c721a78d96b21f2fabe5b5973413313 100644 (file)
@@ -20,7 +20,7 @@
 
 #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
@@ -66,7 +66,7 @@ void ButtonItem::Deserialize(Bundle b) {
 AbstractItem& ButtonItem::FindByID(std::string id) {
   if (GetId() == id)
     return *this;
-  return ItemFactory::GetNullItem();
+  return FactoryManager::GetInst().GetNullItem();
 }
 
 std::string ButtonItem::GetTitle() const {
index e6747094052249e8107cc19defaedec2cab84850..0f889867c0b88114cb836fafc8c28f1c1400d0f7 100644 (file)
@@ -18,7 +18,7 @@
 
 #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
@@ -66,23 +66,25 @@ Bundle ChatMessageItem::Serialize() {
 }
 
 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);
 
@@ -93,7 +95,7 @@ AbstractItem&  ChatMessageItem::FindByID(std::string id) {
   if (GetId() == id)
     return *this;
 
-  return ItemFactory::GetNullItem();
+  return FactoryManager::GetInst().GetNullItem();
 }
 
 TextItem& ChatMessageItem::GetNameItem() const {
index c4e1e0c689931ed264491702153af79677cc7ce0..73211d2d1264d26395d689a82f88695061d94705 100644 (file)
@@ -18,7 +18,7 @@
 
 #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
@@ -64,7 +64,7 @@ AbstractItem& CheckBoxItem::FindByID(std::string id) {
   if (GetId() == id)
     return *this;
 
-  return ItemFactory::GetNullItem();
+  return FactoryManager::GetInst().GetNullItem();
 }
 
 std::string CheckBoxItem::GetTitle(void) const {
diff --git a/notification-ex/default_item_factory.cc b/notification-ex/default_item_factory.cc
new file mode 100644 (file)
index 0000000..569b4d9
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * 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 <memory>
+
+#include "notification-ex/default_item_factory.h"
+#include "notification-ex/button_item.h"
+#include "notification-ex/group_item.h"
+#include "notification-ex/entry_item.h"
+#include "notification-ex/text_item.h"
+#include "notification-ex/exception.h"
+#include "notification-ex/input_selector_item.h"
+#include "notification-ex/progress_item.h"
+#include "notification-ex/icon_item.h"
+#include "notification-ex/icon_text_item.h"
+#include "notification-ex/image_item.h"
+#include "notification-ex/checkbox_item.h"
+#include "notification-ex/chat_message_item.h"
+#include "notification-ex/time_item.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "NOTIFICATION_EX"
+
+using namespace std;
+namespace notification {
+namespace item {
+
+unique_ptr<AbstractItem> DefaultItemFactory::CreateItem(AbstractItem::Type type) {
+  switch (type) {
+  case AbstractItem::NullObject :
+    THROW(NOTIFICATION_ERROR_INVALID_PARAMETER);
+  case AbstractItem::Text :
+    return unique_ptr<AbstractItem>(new TextItem("",""));
+  case AbstractItem::Icon :
+    return unique_ptr<AbstractItem>(new IconItem(""));
+  case AbstractItem::Image :
+    return unique_ptr<AbstractItem>(new ImageItem(""));
+  case AbstractItem::Button :
+    return unique_ptr<AbstractItem>(new ButtonItem(""));
+  case AbstractItem::ChatMessage :
+    return unique_ptr<AbstractItem>(new ChatMessageItem("",
+        nullptr, nullptr, nullptr, nullptr, ChatMessageItem::Type::user));
+  case AbstractItem::CheckBox :
+    return unique_ptr<AbstractItem>(new CheckBoxItem("", ""));
+  case AbstractItem::IconText :
+    return unique_ptr<AbstractItem>(new IconTextItem("", nullptr, nullptr));
+  case AbstractItem::InputSelector :
+    return unique_ptr<AbstractItem>(new InputSelectorItem());
+  case AbstractItem::Group :
+    return unique_ptr<AbstractItem>(new GroupItem());
+  case AbstractItem::Entry :
+    return unique_ptr<AbstractItem>(new EntryItem(""));
+  case AbstractItem::Progress :
+    return unique_ptr<AbstractItem>(new ProgressItem(0.0, 0.0, 0.0));
+  case AbstractItem::Time :
+    return unique_ptr<AbstractItem>(new TimeItem());
+  case AbstractItem::Custom :
+    return unique_ptr<AbstractItem>(new ButtonItem(""));
+  }
+
+  return nullptr;
+}
+
+}  // namespace item
+}  // namespace notification
diff --git a/notification-ex/default_item_factory.h b/notification-ex/default_item_factory.h
new file mode 100644 (file)
index 0000000..489bd40
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * 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_
index b3a1674f67e83efa47e5ddd293c266986acaa6cf..143a311d86c333fab9200245fde0ba9d5b572c2e 100644 (file)
@@ -20,7 +20,7 @@
 
 #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
@@ -69,7 +69,7 @@ void EntryItem::Deserialize(Bundle b) {
 AbstractItem& EntryItem::FindByID(std::string id) {
   if (GetId() == id)
     return *this;
-  return ItemFactory::GetNullItem();
+  return FactoryManager::GetInst().GetNullItem();
 }
 
 std::string EntryItem::GetText() const {
diff --git a/notification-ex/factory_manager.cc b/notification-ex/factory_manager.cc
new file mode 100644 (file)
index 0000000..19df26f
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * 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
diff --git a/notification-ex/factory_manager.h b/notification-ex/factory_manager.h
new file mode 100644 (file)
index 0000000..e203000
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * 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_
index f3fa086b836ab1ee5785718c5134fce4ff97463b..2b5264488dfdcb04867c7cad5b5d2841ad17aca5 100644 (file)
@@ -22,7 +22,7 @@
 
 #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
@@ -90,13 +90,13 @@ void GroupItem::Deserialize(Bundle b) {
   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);
   }
@@ -107,7 +107,7 @@ AbstractItem& GroupItem::FindByID(std::string id) {
     if (i.get()->GetId() == id)
       return *i;
   }
-  return ItemFactory::GetNullItem();
+  return FactoryManager::GetInst().GetNullItem();
 }
 
 void GroupItem::AddChild(shared_ptr<AbstractItem> child) {
index 80c62ee2d57bc24825f6da80bf0fc25e78ed2a0e..bac2a7bedfe7b5bb116aa85d8d375f4628c40bea 100644 (file)
@@ -18,7 +18,7 @@
 
 #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
@@ -56,15 +56,15 @@ Bundle IconTextItem::Serialize() {
 }
 
 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);
 }
@@ -73,7 +73,7 @@ AbstractItem& IconTextItem::FindByID(std::string id) {
   if (GetId() == id)
     return *this;
 
-  return ItemFactory::GetNullItem();
+  return FactoryManager::GetInst().GetNullItem();
 }
 
 IconItem& IconTextItem::GetIconItem() const {
diff --git a/notification-ex/iitem_factory.h b/notification-ex/iitem_factory.h
new file mode 100644 (file)
index 0000000..aec8652
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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_IITEM_FACTORY_H_
+#define NOTIFICATION_EX_IITEM_FACTORY_H_
+
+#include <string>
+#include <memory>
+#include <list>
+
+#include "notification-ex/abstract_item.h"
+
+namespace notification {
+namespace item {
+
+class EXPORT_API IItemFactory {
+ public:
+  virtual ~IItemFactory() = default;
+  virtual std::unique_ptr<AbstractItem> CreateItem(AbstractItem::Type type) = 0;
+};
+
+}  // namespace item
+}  // namespace notification
+
+#endif  // NOTIFICATION_EX_ITEM_FACTORY_H_
index 991f16cc07195ebe9942032c603cd5c773a7436f..4c437b9b3bf4476cea017c286c21ee8340c12268 100644 (file)
@@ -18,7 +18,7 @@
 
 #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
@@ -64,7 +64,7 @@ AbstractItem& ImageItem::FindByID(std::string id) {
   if (GetId() == id)
     return *this;
 
-  return ItemFactory::GetNullItem();
+  return FactoryManager::GetInst().GetNullItem();
 }
 
 std::string ImageItem::GetImagePath() const {
index 73f4f7b2efee7ca0124729735dafa6c3e357a5f8..17385a74d8a8cbbd766f4e9db354f3f116c9f57f 100644 (file)
@@ -22,7 +22,7 @@
 
 #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
@@ -71,7 +71,7 @@ void InputSelectorItem::Deserialize(Bundle b) {
 AbstractItem& InputSelectorItem::FindByID(std::string id) {
   if (GetId() == id)
     return *this;
-  return ItemFactory::GetNullItem();
+  return FactoryManager::GetInst().GetNullItem();
 }
 
 list<string> InputSelectorItem::GetContents() const {
diff --git a/notification-ex/item_factory.cc b/notification-ex/item_factory.cc
deleted file mode 100644 (file)
index 1dc20ee..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * 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 <memory>
-
-#include "notification-ex/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"
-#include "notification-ex/input_selector_item.h"
-#include "notification-ex/progress_item.h"
-#include "notification-ex/icon_item.h"
-#include "notification-ex/icon_text_item.h"
-#include "notification-ex/image_item.h"
-#include "notification-ex/checkbox_item.h"
-#include "notification-ex/chat_message_item.h"
-#include "notification-ex/time_item.h"
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "NOTIFICATION_EX"
-
-using namespace std;
-namespace notification {
-namespace item {
-
-unique_ptr<AbstractItem> ItemFactory::CreateItem(AbstractItem::Type type) {
-  switch (type) {
-  case AbstractItem::NullObject :
-    THROW(NOTIFICATION_ERROR_INVALID_PARAMETER);
-  case AbstractItem::Text :
-    return unique_ptr<AbstractItem>(new TextItem("",""));
-  case AbstractItem::Icon :
-    return unique_ptr<AbstractItem>(new IconItem(""));
-  case AbstractItem::Image :
-    return unique_ptr<AbstractItem>(new ImageItem(""));
-  case AbstractItem::Button :
-    return unique_ptr<AbstractItem>(new ButtonItem(""));
-  case AbstractItem::ChatMessage :
-    return unique_ptr<AbstractItem>(new ChatMessageItem("",
-        nullptr, nullptr, nullptr, nullptr, ChatMessageItem::Type::user));
-  case AbstractItem::CheckBox :
-    return unique_ptr<AbstractItem>(new CheckBoxItem("", ""));
-  case AbstractItem::IconText :
-    return unique_ptr<AbstractItem>(new IconTextItem("", nullptr, nullptr));
-  case AbstractItem::InputSelector :
-    return unique_ptr<AbstractItem>(new InputSelectorItem());
-  case AbstractItem::Group :
-    return unique_ptr<AbstractItem>(new GroupItem());
-  case AbstractItem::Entry :
-    return unique_ptr<AbstractItem>(new EntryItem(""));
-  case AbstractItem::Progress :
-    return unique_ptr<AbstractItem>(new ProgressItem(0.0, 0.0, 0.0));
-  case AbstractItem::Time :
-    return unique_ptr<AbstractItem>(new TimeItem());
-  case AbstractItem::Custom :
-    return unique_ptr<AbstractItem>(new ButtonItem(""));
-  }
-
-  return nullptr;
-}
-
-AbstractItem& ItemFactory::GetNullItem() {
-  static NullItem item;
-  return item;
-}
-
-}  // namespace item
-}  // namespace notification
diff --git a/notification-ex/item_factory.h b/notification-ex/item_factory.h
deleted file mode 100644 (file)
index 70249f1..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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_ITEM_FACTORY_H_
-#define NOTIFICATION_EX_ITEM_FACTORY_H_
-
-#include <string>
-#include <memory>
-#include <list>
-
-#include "notification-ex/abstract_item.h"
-
-namespace notification {
-namespace item {
-
-class EXPORT_API ItemFactory {
- public:
-  std::unique_ptr<AbstractItem> CreateItem(AbstractItem::Type type);
-  static AbstractItem& GetNullItem();
-};
-
-}  // namespace item
-}  // namespace notification
-
-#endif  // NOTIFICATION_EX_ITEM_FACTORY_H_
index 183f940d1ac386334153e3c1ec2e1783152e2950..ffb014f3a285170482c7d1e2cf0556dfaf733186 100644 (file)
@@ -18,7 +18,7 @@
 
 #include <memory>
 
-#include "notification-ex/item_factory.h"
+#include "notification-ex/factory_manager.h"
 #include "notification-ex/item_inflator.h"
 
 #ifdef LOG_TAG
@@ -31,8 +31,9 @@ using namespace std;
 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;
 }
index b0a4122bad3a8db9ce4aadeb4ba2421032616dd9..0f2e9dfbae6b69717ab12cfd6e7d25b7f79157d3 100644 (file)
 #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
index 8868cfe7a81a24317c2b52a2b6d8972fe291b2bf..652007588b7585458164de2bd63e4625b2996aa9 100644 (file)
@@ -21,7 +21,7 @@
 #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
@@ -77,7 +77,7 @@ void ProgressItem::Deserialize(Bundle b) {
 AbstractItem& ProgressItem::FindByID(std::string id) {
   if (GetId() == id)
     return *this;
-  return ItemFactory::GetNullItem();
+  return FactoryManager::GetInst().GetNullItem();
 }
 
 float ProgressItem::GetCurrent() const {
index f01d3e03fb9cf723767d0e01a86de60e18ea154c..d8837828c6d039a9ef6cc43f97d32944a8807789 100644 (file)
@@ -20,7 +20,7 @@
 
 #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
@@ -67,7 +67,7 @@ void TextItem::Deserialize(Bundle b) {
 AbstractItem& TextItem::FindByID(std::string id) {
   if (GetId() == id)
     return *this;
-  return ItemFactory::GetNullItem();
+  return FactoryManager::GetInst().GetNullItem();
 }
 
 void TextItem::SetContents(std::string contents) {
index c375d167b8dedb61f0096277b6f3b9b89eadb9ab..c84563a42ddca59ef159d0241704b747fd10b855 100644 (file)
@@ -18,7 +18,7 @@
 
 #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
@@ -86,7 +86,7 @@ AbstractItem& TimeItem::FindByID(std::string id) {
   if (GetId() == id)
     return *this;
 
-  return ItemFactory::GetNullItem();
+  return FactoryManager::GetInst().GetNullItem();
 }
 
 time_t TimeItem::GetTime() const {
index 167aa951edaf9196ce0b4ecdb63bf6129926cf54..3320832029af90ea3ca899ad664f77621041914d 100644 (file)
@@ -37,8 +37,7 @@ TEST_F(ButtonItemTest, FindByIDNullItemReturn) {
 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());
index 6952b381c99f911e623c38361d6dcb591e5d97d5..abca486626fb9c74095a3d68612109f0a83c9c3b 100644 (file)
@@ -63,8 +63,7 @@ TEST_F(ChatMessageItemTest, FindByIDNullItemReturn) {
 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");
index 6fd38dd1da70ca6b3e9bc1d63eb28665eb676604..8aa0e6b3f32f8bfb1db0f0741e17bfccd4b9a26b 100644 (file)
@@ -55,8 +55,7 @@ TEST_F(CheckBoxItemTest, FindByIDNullItemReturn) {
 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());
index b81d8f99fb0e20eebeb8183afd017d472ffa2ec6..da933d337bff9ca982a93a63cad94ef2f00a292e 100644 (file)
@@ -48,8 +48,7 @@ TEST_F(EntryItemTest, FindByIDNullItemReturn) {
 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());
index cbe87ef1d7005f704d3690e3201cd7f5976bd935..6288c8df711953b5837c14504f566b8321ac5d35 100644 (file)
@@ -43,8 +43,7 @@ TEST_F(GroupItemTest, SerializeDeserialize) {
   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());
index 8deb06dcad0a14795083a513bdd3139f929893b7..cd2fdbfa82ac3ac5c0cbab4906ba05f55b3e6360 100644 (file)
@@ -52,8 +52,7 @@ TEST_F(IconItemTest, FindByIDNullItemReturn) {
 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());
index dfe8f727c1de1fc3df8a0ad6398eda9dbb335d8b..423d0522535c81ab41ce7a6c065b5eb8378dc1d6 100644 (file)
@@ -55,8 +55,7 @@ TEST_F(IconTextItemTest, FindByIDNullItemReturn) {
 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());
index 42a5caa69bd6168c9805c20acc343fb1f4e5170a..5aa45e2de79faf1756a1d422626a722d350ce79a 100644 (file)
@@ -53,8 +53,7 @@ TEST_F(ImageItemTest, FindByIDNullItemReturn) {
 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());
index 9c56bc6b2c8b241006346b03cd49d910fe553a1b..d2db27d9a32736463e32a97a927502c7351b4c3a 100644 (file)
@@ -27,8 +27,7 @@ TEST_F(InputSelectorItemTest, SerializeDeserialize) {
   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());
index 435fface11c8778b746d1d987f66f6be5d069adc..d62aab3832faf1753ea0c6f3d80458d8ec69bfc7 100644 (file)
@@ -21,8 +21,7 @@ class ProgressItemTest : public ::testing::Test {
 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());
index 316e2cdafa18a6e33e019ff05489e22915a54387..49ea0fc423141bb9234012b21679753aed76664f 100644 (file)
@@ -50,8 +50,7 @@ TEST_F(TexttItemTest, FindByIDNullItemReturn) {
 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());
index e0514f3aa8da87713be996636c9ad62aebbbec93..f595277a71d00676f917090f569e8bdafdb241da 100644 (file)
@@ -54,8 +54,7 @@ TEST_F(TimeItemTest, FindByIDNullItemReturn) {
 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());