Move the process when an app is ternminated
authorKazumasa Mitsunari <knimitz@witz-inc.co.jp>
Fri, 10 Aug 2018 04:14:14 +0000 (13:14 +0900)
committerKazumasa Mitsunari <knimitz@witz-inc.co.jp>
Fri, 10 Aug 2018 04:14:14 +0000 (13:14 +0900)
Change-Id: Iac943acfab5f32332aab6c0e5ca0fead4a577b02
Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
src/main.cpp
src/window_manager.cpp
src/window_manager.hpp

index 261df8b..e1351be 100644 (file)
@@ -29,17 +29,6 @@ extern "C"
 #include <systemd/sd-event.h>
 }
 
-typedef struct WMClientCtxt
-{
-    std::string name;
-    std::string role;
-    WMClientCtxt(const char *appName, const char* appRole)
-    {
-        name = appName;
-        role = appRole;
-    }
-} WMClientCtxt;
-
 struct afb_instance
 {
     std::unique_ptr<wl::display> display;
@@ -178,45 +167,24 @@ int binding_init() noexcept
 
 static void cbRemoveClientCtxt(void *data)
 {
-    WMClientCtxt *ctxt = (WMClientCtxt *)data;
+    wm::WMClientCtxt *ctxt = (wm::WMClientCtxt *)data;
     if (ctxt == nullptr)
     {
         return;
     }
     HMI_DEBUG("wm", "remove app %s", ctxt->name.c_str());
-    // Lookup surfaceID and remove it because App is dead.
-    auto pSid = g_afb_instance->wmgr.id_alloc.lookup(ctxt->role.c_str());
-    if (pSid)
-    {
-        auto sid = *pSid;
-        auto o_state = *g_afb_instance->wmgr.layers.get_layout_state(sid);
-        if (o_state != nullptr)
-        {
-            if (o_state->main == sid)
-            {
-                o_state->main = -1;
-            }
-            else if (o_state->sub == sid)
-            {
-                o_state->sub = -1;
-            }
-        }
-        g_afb_instance->wmgr.id_alloc.remove_id(sid);
-        g_afb_instance->wmgr.layers.remove_surface(sid);
-        HMI_DEBUG("wm", "delete surfaceID %d", sid);
-    }
-    g_afb_instance->wmgr.removeClient(ctxt->name);
+    g_afb_instance->wmgr.onApplicationTerminated(*ctxt);
     delete ctxt;
 }
 
 static void createSecurityContext(afb_req req, const char* appid, const char* role)
 {
-    WMClientCtxt *ctxt = (WMClientCtxt *)afb_req_context_get(req);
+    wm::WMClientCtxt *ctxt = (wm::WMClientCtxt *)afb_req_context_get(req);
     if (!ctxt)
     {
         // Create Security Context at first time
         const char *new_role = g_afb_instance->wmgr.convertRoleOldToNew(role);
-        WMClientCtxt *ctxt = new WMClientCtxt(appid, new_role);
+        wm::WMClientCtxt *ctxt = new wm::WMClientCtxt(appid, new_role);
         HMI_DEBUG("wm", "create session for %s", ctxt->name.c_str());
         afb_req_session_set_LOA(req, 1);
         afb_req_context_set(req, ctxt, cbRemoveClientCtxt);
index aa42d82..aa9a459 100644 (file)
@@ -620,6 +620,36 @@ void WindowManager::timerHandler()
     this->processNextRequest();
 }
 
+void WindowManager::onApplicationTerminated(const WMClientCtxt& ctxt)
+{
+    if(!g_app_list.contains(ctxt.name))
+    {
+        return;
+    }
+    auto client = g_app_list.lookUpClient(ctxt.name);
+    unsigned sid = client->surfaceID(ctxt.role);
+    if (sid != 0)
+    {
+        // update state
+        auto o_state = *this->layers.get_layout_state(sid);
+        if (o_state != nullptr)
+        {
+            if (o_state->main == sid)
+            {
+                o_state->main = -1;
+            }
+            else if (o_state->sub == sid)
+            {
+                o_state->sub = -1;
+            }
+        }
+        this->id_alloc.remove_id(sid);
+        this->layers.remove_surface(sid);
+        HMI_DEBUG("wm", "delete surfaceID %d", sid);
+    }
+    g_app_list.removeClient(ctxt.name);
+}
+
 /*
  ******* Private Functions *******
  */
index 2358c5a..a820aa5 100644 (file)
@@ -68,6 +68,17 @@ extern const char kKeyHeightMm[];
 extern const char kKeyScale[];
 extern const char kKeyIds[];
 
+typedef struct WMClientCtxt
+{
+    std::string name;
+    std::string role;
+    WMClientCtxt(const char *appName, const char* appRole)
+    {
+        name = appName;
+        role = appRole;
+    }
+} WMClientCtxt;
+
 struct id_allocator
 {
     unsigned next = 1;
@@ -229,6 +240,7 @@ class WindowManager
     const char* convertRoleOldToNew(char const *role);
     // Do not use this function
     void timerHandler();
+    void onApplicationTerminated(const WMClientCtxt& ctxt);
 
   private:
     bool pop_pending_events();