Add "request_surface_id" option
[apps/agl-service-windowmanager-2017.git] / src / window_manager.cpp
index 32b8e25..deda66e 100644 (file)
@@ -524,19 +524,30 @@ bool WindowManager::api_client_set_render_order(char const* appid, const vector<
     return ret;
 }
 
-string WindowManager::api_client_attach_service_surface
-    (const char* appid, const char* dest, const char* service_surface)
+result<json_object *> WindowManager::api_client_attach_service_surface
+    (const char* appid, const char* dest, const char* service_surface, bool req_sid)
 {
     string uuid, s_dest = dest;
+    unsigned surface = 0;
     auto client = g_app_list.lookUpClient(s_dest);
     if(!client)
     {
         HMI_ERROR("Failed to look up destination [%s]", dest);
-        return uuid;
+        return Err<json_object *>("destination apploication is null");
     }
     uuid = client->attachTmpServiceSurface(appid, service_surface);
+    if(req_sid)
+    {
+        // name does not exist yet, allocate surface id...
+        surface = int(this->id_alloc.generate_id(uuid));
+    }
     this->tmp_services.emplace_back(TmpService{appid, dest, service_surface, uuid});
-    return uuid;
+
+    json_object *object = json_object_new_object();
+    json_object_object_add(object, "uuid", json_object_new_string(uuid.c_str()));
+    json_object_object_add(object, "surface", json_object_new_int(surface));
+
+    return Ok<json_object *>(object);
 }
 
 result<json_object *> WindowManager::api_get_display_info()