Add "request_surface_id" option
authorKazumasa Mitsunari <knimitz@witz-inc.co.jp>
Wed, 31 Oct 2018 01:38:25 +0000 (10:38 +0900)
committerKazumasa Mitsunari <knimitz@witz-inc.co.jp>
Wed, 31 Oct 2018 01:38:25 +0000 (10:38 +0900)
Change-Id: I1461efb544ace5c1bde6eac1ff0209aa96934e32
Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
src/main.cpp
src/window_manager.cpp
src/window_manager.hpp

index 5141def..c45f39f 100644 (file)
@@ -520,31 +520,35 @@ void windowmanager_attach_app(afb_req req) noexcept
     if(appid)
     {
         json_object *jreq = afb_req_json(req);
-        json_object *j_dest, *j_id; // Do not free this. binder frees jreq, then free j_ro
+        json_object *j_dest, *j_id, *j_req_sid; // Do not free this. binder frees jreq, then free j_ro
         if (json_object_object_get_ex(jreq, "destination", &j_dest) &&
             json_object_object_get_ex(jreq, "service_surface", &j_id))
         {
             const char* dest_app = json_object_get_string(j_dest);
             const char* service = json_object_get_string(j_id);
-
-            std::string uuid = g_afb_instance->wmgr.api_client_attach_service_surface(appid, dest_app, service);
-            if (uuid.empty())
+            bool req_sid = false;
+            if(json_object_object_get_ex(jreq, "request_surface_id", &j_req_sid))
             {
-                afb_req_fail(req, "failed", nullptr);
+                req_sid = json_object_get_boolean(j_req_sid);
             }
-            else
+
+            auto ret = g_afb_instance->wmgr.api_client_attach_service_surface(appid, dest_app, service, req_sid);
+            if (ret.is_err())
             {
-                json_object *resp = json_object_new_object();
-                json_object_object_add(resp, "uuid", json_object_new_string(uuid.c_str()));
-                afb_req_success(req, resp, nullptr);
+                afb_req_fail(req, "failed", ret.unwrap_err());
+                return;
             }
+
+            afb_req_success(req, ret.unwrap(), "success");
+        }
+        else
+        {
+            afb_req_fail(req, "failed", nullptr);
         }
         free(appid);
+        return;
     }
-    else
-    {
-        afb_req_fail(req, "failed", nullptr);
-    }
+    afb_req_fail(req, "failed", nullptr);
 }
 
 void windowmanager_wm_subscribe(afb_req req) noexcept
@@ -746,7 +750,7 @@ const struct afb_verb_v2 windowmanager_verbs[] = {
     {"getDisplayInfo", windowmanager_getdisplayinfo_thunk, nullptr, nullptr, AFB_SESSION_NONE},
     {"getAreaInfo", windowmanager_getareainfo_thunk, nullptr, nullptr, AFB_SESSION_NONE},
     {"setRenderOrder", windowmanager_set_render_order, nullptr, nullptr, AFB_SESSION_NONE},
-    {"attachApp", windowmanager_attach_app, nullptr, nullptr, AFB_SESSION_NONE},
+    {"attachSurfaceToApp", windowmanager_attach_app, nullptr, nullptr, AFB_SESSION_NONE},
     {"wm_subscribe", windowmanager_wm_subscribe, nullptr, nullptr, AFB_SESSION_NONE},
     {"list_drawing_names", windowmanager_list_drawing_names, nullptr, nullptr, AFB_SESSION_NONE},
     {"ping", windowmanager_ping, nullptr, nullptr, AFB_SESSION_NONE},
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()
index 6811110..18d3619 100644 (file)
@@ -189,7 +189,7 @@ class WindowManager
     void api_deactivate_surface(char const *appid, char const *role, const reply_func &reply);
     void api_enddraw(char const *appid, char const *role);
     bool api_client_set_render_order(const char *appid, const std::vector<std::string> &render_order);
-    std::string api_client_attach_service_surface(const char* appid, const char* dest, const char* service_surface);
+    result<json_object *> api_client_attach_service_surface(const char* appid, const char* dest, const char* service_surface, bool req_sid = false);
     result<json_object *> api_get_display_info();
     result<json_object *> api_get_area_info(char const *role);
     void send_event(char const *evname, char const *label);