Move the process when an app is ternminated
[apps/agl-service-windowmanager-2017.git] / src / main.cpp
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);