aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp62
1 files changed, 62 insertions, 0 deletions
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<std::mutex> 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<std::mutex> 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},