Fix saving content info 54/211354/3
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 2 Aug 2019 00:12:21 +0000 (09:12 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Mon, 5 Aug 2019 02:11:13 +0000 (02:11 +0000)
If a component is a single instance, the name of the content info
is using the component name. Even if a component is started by a new
instance, the component should use the previous content info.

Change-Id: I7226764e3f757c294a506ca07c0afdf4a2fab329
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
component_based/base/component.cc
component_based/base/component_manager_internal.cc
component_based/base/component_manager_internal.h
component_based/base/content_manager_internal.cc
component_based/base/content_manager_internal.h

index 52b211702123692d103c4d06cd2802fd5b214ddb..93c1e0e1b62d4bcad4839470d381f34748eaf356 100644 (file)
@@ -32,9 +32,13 @@ Component::Impl::Impl(Component* parent, Component::Type type,
                       std::string comp_id, std::string inst_id)
   : parent_(parent), type_(std::move(type)),
     comp_id_(std::move(comp_id)), inst_id_(std::move(inst_id)),
-    sys_ev_(new internal::SystemEvent(this)),
-    content_mgr_(new internal::ContentManager(inst_id_)) {
+    sys_ev_(new internal::SystemEvent(this)) {
   auto& mgr = internal::ComponentManager::GetInst();
+  if (mgr.IsSingleInstance(inst_id_))
+    content_mgr_.reset(new (std::nothrow) internal::ContentManager(comp_id_));
+  else
+    content_mgr_.reset(new (std::nothrow) internal::ContentManager(inst_id_));
+
   mgr.AddEventListener(inst_id_, this);
 }
 
index fef7b58104ecf8af92a9d2d8b519d38c06b91f3b..99fb6cf9d42e9d0e60fb787bca3cd29cd72c0824 100644 (file)
  * limitations under the License.
  */
 
+#include <aul.h>
 #include <aul_app_group.h>
 #include <app_control_internal.h>
+#include <bundle_internal.h>
 
+#include <algorithm>
 #include <memory>
 #include <string>
 
@@ -63,6 +66,12 @@ void ComponentManager::Start(const std::string& comp_id,
       LOGE("Failed to find factory map. %s", comp_id.c_str());
       return;
     }
+
+    const char *val = bundle_get_val(b, AUL_K_NEW_INSTANCE);
+    std::string new_inst(val ? val : "");
+    if (new_inst == "true")
+      multi_inst_list_.push_back(inst_id);
+
     std::unique_ptr<Component> component = fac_map_[comp_id]->Create(comp_id,
         inst_id);
     if (component == nullptr || component.get() == nullptr) {
@@ -248,6 +257,15 @@ void ComponentManager::PauseAll() {
   }
 }
 
+bool ComponentManager::IsSingleInstance(const std::string& inst_id) {
+  auto it = std::find(multi_inst_list_.begin(), multi_inst_list_.end(),
+      inst_id);
+  if (it == multi_inst_list_.end())
+    return true;
+
+  return false;
+}
+
 Ecore_Wl2_Window* ComponentManager::GetWl2Window(const std::string& inst_id) {
   auto win_iter = win_map_.find(inst_id);
   if (win_iter == win_map_.end())
@@ -260,6 +278,7 @@ Ecore_Wl2_Window* ComponentManager::GetWl2Window(const std::string& inst_id) {
 }
 
 void ComponentManager::Remove(const std::string& inst_id) {
+  multi_inst_list_.remove(inst_id);
   RemoveGroup(inst_id);
   ev_map_.erase(inst_id);
   inst_map_.erase(inst_id);
index 34c424e51a3cdd237cf9e6c3035d0b0288a46c89..3fec0a003d8f2218c87c7f5da569aa4b90178155 100644 (file)
@@ -73,6 +73,7 @@ class ComponentManager {
   bool IsEmpty();
   void ResumeAll();
   void PauseAll();
+  bool IsSingleInstance(const std::string& inst_id);
 
  private:
   IEventListener* GetEventListener(const std::string& inst_id);
@@ -95,6 +96,7 @@ class ComponentManager {
   std::map<std::string, std::unique_ptr<Component>> inst_map_;
   std::map<std::string, std::unique_ptr<IWindow>> win_map_;
   std::map<std::string, int> group_map_;
+  std::list<std::string> multi_inst_list_;
 };
 
 }  // namespace internal
index bfa4b9046ac2398d011acc403891db4ed5c5c6b8..66c66188ebed8ffabb0fd5f52d1e07c905aa224c 100644 (file)
@@ -30,9 +30,9 @@
 namespace component_based {
 namespace internal {
 
-ContentManager::ContentManager(std::string inst_id) {
+ContentManager::ContentManager(std::string name) {
   auto& path = ContentManager::Path::GetInst();
-  file_ = std::unique_ptr<File>(new File(path.GetPath(inst_id)));
+  file_ = std::unique_ptr<File>(new File(path.GetPath(name)));
 }
 
 ContentManager::~ContentManager() = default;
index bc16ec59398b43a08017b581e466d80e4ad07e6c..9eabb24a847a5164628c4d9be5298ee10e53a751 100644 (file)
@@ -32,7 +32,7 @@ namespace internal {
 
 class ContentManager {
  public:
-  explicit ContentManager(std::string inst_id);
+  explicit ContentManager(std::string name);
   virtual ~ContentManager();
 
   void SetContent(tizen_base::Bundle content);