Implement attachApp
[apps/agl-service-windowmanager-2017.git] / src / window_manager.cpp
index 0eeebcd..f0258f7 100644 (file)
@@ -514,21 +514,21 @@ bool WindowManager::api_client_set_render_order(char const* appid, const vector<
     return ret;
 }
 
-string api_client_attach_service_surface(const char* appid, const char* dest, const char* service_surface)
+string WindowManager::api_client_attach_service_surface
+    (const char* appid, const char* dest, const char* service_surface)
 {
-    string uuid = "", s_dest;
-    s_dest = dest;
-    // uuid = generate_uuid_randam());
+    string uuid, s_dest = dest;
     auto client = g_app_list.lookUpClient(s_dest);
     if(!client)
     {
         HMI_ERROR("Failed to look up destination [%s]", dest);
         return uuid;
     }
-    //string uuid = client->attachServiceSurface(appid);
+    uuid = client->attachTmpServiceSurface(appid, service_surface);
+    this->tmp_services.emplace_back(TmpService{appid, dest, service_surface, uuid});
+    return uuid;
 }
 
-
 result<json_object *> WindowManager::api_get_display_info()
 {
     Screen screen = this->lc->getScreenInfo();
@@ -613,6 +613,7 @@ void WindowManager::send_event(char const *evname, char const *label, char const
  */
 void WindowManager::surface_created(unsigned pid, unsigned surface_id)
 {
+    // requestSurface
     if(this->tmp_surface2app.count(surface_id) != 0)
     {
         string appid = this->tmp_surface2app[surface_id].appid;
@@ -684,19 +685,39 @@ void WindowManager::surface_created(unsigned pid, unsigned surface_id)
             }
         }
         json_object_put(response);
-        auto client = g_app_list.lookUpClient(appid);
-        if(client != nullptr)
+
+        auto elem = std::find_if(this->tmp_services.begin(), this->tmp_services.end(),
+                [&appid](TmpService& ts){
+                    return (ts.dest == appid );
+                    });
+        if(elem == this->tmp_services.end())
         {
-            client->addSurface(surface_id);
-            this->id_alloc.register_name_id(client->role(), surface_id);
+            // attachApp
+            auto client = g_app_list.lookUpClient(elem->dest);
+            if(client == nullptr)
+            {
+                return;
+            }
+            HMI_INFO("Attach surface %d (service %s) to app %s", surface_id, elem->service.c_str(), elem->dest.c_str());
+            client->attachServiceSurface(elem->service, surface_id);
         }
         else
         {
-            /*
-             * Store tmp surface and appid for application
-             * who requests setRole after creating shell surface
-             */
-            this->tmp_surface2app.emplace(surface_id, TmpClient{appid, ppid});
+            // setRole
+            auto client = g_app_list.lookUpClient(appid);
+            if(client != nullptr)
+            {
+                client->addSurface(surface_id);
+                this->id_alloc.register_name_id(client->role(), surface_id);
+            }
+            else
+            {
+                /*
+                * Store tmp surface and appid for application
+                * who requests setRole after creating shell surface
+                */
+                this->tmp_surface2app.emplace(surface_id, TmpClient{appid, ppid});
+            }
         }
     }
 }