From d2c062959c55c61a4e350f6df480d46d2a8d769c Mon Sep 17 00:00:00 2001 From: Kazumasa Mitsunari Date: Tue, 25 Sep 2018 12:19:14 +0900 Subject: Implement attachApp Change-Id: I4082fd400fd2f82fcb6cbbcc66d584fb0a572827 Signed-off-by: Kazumasa Mitsunari --- src/window_manager.cpp | 51 +++++++++++++++++++++++++++++++++++--------------- src/window_manager.hpp | 13 ++++++++++++- src/wm_client.cpp | 25 +++++++++++++++++++++++++ src/wm_client.hpp | 3 +++ 4 files changed, 76 insertions(+), 16 deletions(-) diff --git a/src/window_manager.cpp b/src/window_manager.cpp index 0eeebcd..f0258f7 100644 --- a/src/window_manager.cpp +++ b/src/window_manager.cpp @@ -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 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}); + } } } } diff --git a/src/window_manager.hpp b/src/window_manager.hpp index 7bd0802..481d16c 100644 --- a/src/window_manager.hpp +++ b/src/window_manager.hpp @@ -135,6 +135,17 @@ struct TmpClient unsigned pid; }; +struct TmpService +{ + std::string appid; // Used to search who create service surface + std::string dest; // Used to attach service to destination application + std::string service;// The name of service surface + std::string uuid; // uuid + TmpService(const std::string& app, const std::string& dst, + const std::string& svc, const std::string& uuid) + : appid(app), dest(dst), service(svc), uuid(uuid) {} +}; + class WindowManager { public: @@ -249,7 +260,7 @@ class WindowManager rect_map area_info; // FOR CES DEMO std::unordered_map tmp_surface2app; - std::vector tmp_apps; + std::vector tmp_services; static const char* kDefaultOldRoleDb; }; diff --git a/src/wm_client.cpp b/src/wm_client.cpp index 84f9842..356cd6f 100644 --- a/src/wm_client.cpp +++ b/src/wm_client.cpp @@ -18,6 +18,8 @@ #include "wm_client.hpp" #include "util.hpp" #include +#include + #define INVALID_SURFACE_ID 0 @@ -188,6 +190,29 @@ WMError WMClient::setRenderOrder(const vector &order) return ret; } +string WMClient::attachTmpServiceSurface(const string& supplier, const string& service_surface) +{ + string uuid; + uuid_t u; + char out[37]; // uuid is 36 characters + uuid_generate_random(u); + uuid_unparse(u, out); + uuid = out; + this->service2supplier.emplace(service_surface, supplier); + return uuid; +} + +WMError WMClient::attachServiceSurface(const string& service_surface, unsigned surface) +{ + WMError ret = WMError::NOT_REGISTERED; + if(this->service2supplier.count(service_surface) != 0) + { + this->service2surfaces.emplace(service_surface, surface); + ret = WMError::SUCCESS; + } + return ret; +} + #if GTEST_ENABLED bool WMClient::subscribe(afb_req req, const string &evname) { diff --git a/src/wm_client.hpp b/src/wm_client.hpp index 65c68b9..fc171f4 100644 --- a/src/wm_client.hpp +++ b/src/wm_client.hpp @@ -59,6 +59,8 @@ class WMClient // bool removeRole(const std::string& role); std::vector renderOrder() const; WMError setRenderOrder(const std::vector& order); + std::string attachTmpServiceSurface(const std::string& from, const std::string& service_surface); + WMError attachServiceSurface(const std::string& service_surface, unsigned surface); #if GTEST_ENABLED bool subscribe(afb_req req, const std::string &event_name); @@ -77,6 +79,7 @@ class WMClient std::vector surface_render_order; std::unordered_map service2surfaces; std::unordered_map role2surface; + std::unordered_map service2supplier; #if GTEST_ENABLED // This is for unit test. afb_make_event occurs sig11 if call not in afb-binding std::unordered_map evname2afb_event; -- cgit 1.2.3-korg