Fix termination logic 68/213768/1
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 11 Sep 2019 06:19:56 +0000 (15:19 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 11 Sep 2019 06:22:09 +0000 (15:22 +0900)
Change-Id: If45818dab519818e33a6ae83c84f943b67e21d20
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
component_based/base/application_base.cc
component_based/base/application_base_implementation.h
component_based/base/component.cc
component_based/base/component_manager_internal.cc
component_based/base/component_manager_internal.h

index 576cdc7c0b8fe4c93d013fabdb53f01b76aa29d3..877c38996ec78bd5ae383d171624287eb2527712 100644 (file)
@@ -60,6 +60,12 @@ void ApplicationBase::Impl::OnBaseRun() {
 
 void ApplicationBase::Impl::OnBaseExit() {
   LOGD("");
+  if (exiting_) {
+    LOGD("Already exiting");
+    return;
+  }
+
+  exiting_ = true;
   parent_->OnExit();
 }
 
index aef1c8d12522d0b66ea0bc49725b3e837236fc4d..5821cf862b1b5e3087b3e128051c52897bf3d669 100644 (file)
@@ -58,6 +58,7 @@ class ApplicationBase::Impl : internal::CoreBase::IEventListener {
   ApplicationBase* parent_;
   std::unique_ptr<internal::CoreBase> core_base_;
   std::string app_id_;
+  bool exiting_ = false;
 };
 
 }  // namespace component_based
index cec29a8b400b025348dfa5c2c29e15105ec51dfd..29656fc3a3d4489f0ddce1a1a38b0b103a0d55b9 100644 (file)
@@ -311,7 +311,7 @@ std::string Component::GetInstanceID() {
 
 void Component::Finish() {
   auto& mgr = internal::ComponentManager::GetInst();
-  mgr.Exit(impl_->GetInstanceID());
+  mgr.ExitAtIdle(impl_->GetInstanceID());
 }
 
 Component::Type Component::GetType() {
index 8bb18c10e5d5158d7547e0ff3893680d48cb4ede..c4e10652bc6409ac866a86369685e5f59b30cbb3 100644 (file)
@@ -18,6 +18,7 @@
 #include <aul_app_group.h>
 #include <app_control_internal.h>
 #include <bundle_internal.h>
+#include <glib.h>
 
 #include <algorithm>
 #include <memory>
@@ -143,6 +144,15 @@ void ComponentManager::Exit(const std::string& inst_id) {
   appcore_multiwindow_base_instance_exit(context);
 }
 
+void ComponentManager::ExitAtIdle(const std::string& inst_id) {
+  g_idle_add([](gpointer data) -> gboolean {
+        char* inst_id = static_cast<char*>(data);
+        ComponentManager::GetInst().Exit(inst_id);
+        free(inst_id);
+        return G_SOURCE_REMOVE;
+      }, strdup(inst_id.c_str()));
+}
+
 void ComponentManager::ExitAll() {
   if (inst_map_.empty())
     return;
@@ -315,6 +325,11 @@ void ComponentManager::OnTerminateCB(
   ev->OnStop();
   ev->OnDestroy();
   mgr.Remove(inst_id);
+
+  if (appcore_multiwindow_base_instance_get_cnt() == 1) {
+    LOGD("Exit");
+    appcore_multiwindow_base_exit();
+  }
 }
 
 void ComponentManager::OnPauseCB(appcore_multiwindow_base_instance_h context,
index 3fec0a003d8f2218c87c7f5da569aa4b90178155..7dbb12b722b6dccb48ecbfc70cbaff2c88e9bcd6 100644 (file)
@@ -63,6 +63,7 @@ class ComponentManager {
   void Stop(const std::string& inst_id);
 
   void Exit(const std::string& inst_id);
+  void ExitAtIdle(const std::string& inst_id);
   void ExitAll();
   bool Bind(const std::string& inst_id, std::unique_ptr<IWindow> win);
   void Unbind(const std::string& inst_id);