From ce0587201398f8704f8c8a9d5d4c96b3aafd476f Mon Sep 17 00:00:00 2001 From: Kazumasa Mitsunari Date: Fri, 8 Jun 2018 14:02:01 +0900 Subject: 1st Step: Add set_role function Change-Id: I779c9bdce78eb8b1bf601c461630dd8b7c3320bb Signed-off-by: Kazumasa Mitsunari --- src/app.cpp | 5 +++++ src/app.hpp | 1 + src/main.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) diff --git a/src/app.cpp b/src/app.cpp index 5bd597c..41b52c4 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -1266,6 +1266,11 @@ char const *App::api_request_surface(char const *appid, char const *drawing_name return nullptr; } +void App::api_set_role(char const *appid, char const *drawing_name, unsigned pid){ + std::string id = appid; + std::string role = drawing_name; +} + result App::api_get_display_info() { // Check controller diff --git a/src/app.hpp b/src/app.hpp index 7ead82e..a9b3961 100644 --- a/src/app.hpp +++ b/src/app.hpp @@ -220,6 +220,7 @@ struct App result api_request_surface(char const *appid, char const *drawing_name); char const *api_request_surface(char const *appid, char const *drawing_name, char const *ivi_id); + void api_set_role(char const *appid, char const *drawing_name, unsigned pid); void api_activate_surface(char const *appid, char const *drawing_name, char const *drawing_area, const reply_func &reply); void api_deactivate_surface(char const *appid, char const *drawing_name, const reply_func &reply); void api_enddraw(char const *appid, char const *drawing_name); diff --git a/src/main.cpp b/src/main.cpp index 332a158..be8db1d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -321,6 +321,67 @@ void windowmanager_requestsurfacexdg(afb_req req) noexcept } } +void windowmanager_setrole(afb_req req) noexcept +{ + std::lock_guard guard(binding_m); + if (g_afb_instance == nullptr) + { + afb_req_fail(req, "failed", "Binding not initialized, did the compositor die?"); + return; + } + try + { + unsigned pid = 0; + std::string appid = afb_req_get_application_id(req); + json_object *jreq = afb_req_json(req); + + json_object *j_role = nullptr; + if (!json_object_object_get_ex(jreq, "role", &j_role)) + { + afb_req_fail(req, "failed", "Need char const* argument role"); + return; + } + char const *a_role = json_object_get_string(j_role); + + /* Create Security Context */ + bool isFirstReq = checkFirstReq(req); + /* if (!isFirstReq) + { + WMClientCtxt *ctxt = (WMClientCtxt *)afb_req_context_get(req); + HMI_DEBUG("wm", "Set %s into %s.", a_role, appid.c_str()); + } */ + + json_object *j_pid = nullptr; + if (json_object_object_get_ex(jreq, "pid", &j_pid)) + { + HMI_DEBUG("wm", "PID is set"); + char const *a_pid = json_object_get_string(j_pid); + pid = std::stol(a_pid); + } + + g_afb_instance->app.api_set_role(appid.c_str(), a_role, pid); + + if (isFirstReq) + { + WMClientCtxt *ctxt = new WMClientCtxt(appid.c_str(), a_role); + HMI_DEBUG("wm", "create session for appid:%s, role: %s", ctxt->name.c_str(), ctxt->role.c_str()); + afb_req_session_set_LOA(req, 1); + afb_req_context_set(req, ctxt, cbRemoveClientCtxt); + } + else + { + HMI_DEBUG("wm", "session already created for %s", appid.c_str()); + } + + afb_req_success(req, NULL, "success"); + } + catch (std::exception &e) + { + afb_req_fail_f(req, "failed", "Uncaught exception while calling requestsurfacexdg: %s", e.what()); + return; + } +} + void windowmanager_activatesurface(afb_req req) noexcept { std::lock_guard guard(binding_m); @@ -726,6 +787,7 @@ void windowmanager_debug_terminate(afb_req req) noexcept const struct afb_verb_v2 windowmanager_verbs[] = { {"requestsurface", windowmanager_requestsurface, nullptr, nullptr, AFB_SESSION_NONE}, {"requestsurfacexdg", windowmanager_requestsurfacexdg, nullptr, nullptr, AFB_SESSION_NONE}, + {"setrole", windowmanager_setrole, nullptr, nullptr, AFB_SESSION_NONE}, {"activatesurface", windowmanager_activatesurface, nullptr, nullptr, AFB_SESSION_LOA_1}, {"deactivatesurface", windowmanager_deactivatesurface, nullptr, nullptr, AFB_SESSION_LOA_1}, {"enddraw", windowmanager_enddraw, nullptr, nullptr, AFB_SESSION_LOA_1}, -- cgit 1.2.3-korg