binding/afbclient: use the correct binding names
[staging/windowmanager.git] / src / afb_binding_api.cpp
1 /*
2  * Copyright (C) 2017 Mentor Graphics Development (Deutschland) GmbH
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "app.hpp"
18 #include "json_helper.hpp"
19
20 #include <csignal>
21
22 #include <json.hpp>
23
24 using json = nlohmann::json;
25
26 #include <json-c/json.h>
27
28 namespace wm {
29 //  _     _           _ _                            _   _                 _
30 // | |__ (_)_ __   __| (_)_ __   __ _     __ _ _ __ (_) (_)_ __ ___  _ __ | |
31 // | '_ \| | '_ \ / _` | | '_ \ / _` |   / _` | '_ \| | | | '_ ` _ \| '_ \| |
32 // | |_) | | | | | (_| | | | | | (_| |  | (_| | |_) | | | | | | | | | |_) | |
33 // |_.__/|_|_| |_|\__,_|_|_| |_|\__, |___\__,_| .__/|_| |_|_| |_| |_| .__/|_|
34 //                              |___/_____|   |_|                   |_|
35 binding_api::result_type binding_api::requestsurface(
36    char const *drawing_name) {
37    auto r = this->app->api_request_surface(drawing_name);
38    if (r.is_err()) {
39       return Err<json_object *>(r.unwrap_err());
40    }
41    return Ok(json_object_new_int(r.unwrap()));
42 }
43
44 binding_api::result_type binding_api::activatesurface(
45    char const *drawing_name) {
46    logdebug("%s drawing_name %s", __func__, drawing_name);
47    auto r = this->app->api_activate_surface(drawing_name);
48    if (r != nullptr) {
49       logdebug("%s failed with error: %s", __func__, r);
50       return Err<json_object *>(r);
51    }
52    return Ok(json_object_new_object());
53 }
54
55 binding_api::result_type binding_api::deactivatesurface(char const* drawing_name) {
56    logdebug("%s drawing_name %s", __func__, drawing_name);
57    auto r = this->app->api_deactivate_surface(drawing_name);
58    if (r != nullptr) {
59       logdebug("%s failed with error: %s", __func__, r);
60       return Err<json_object *>(r);
61    }
62    return Ok(json_object_new_object());
63 }
64
65 binding_api::result_type binding_api::enddraw(char const* drawing_name) {
66    logdebug("%s drawing_name %s", __func__, drawing_name);
67    auto r = this->app->api_enddraw(drawing_name);
68    if (r != nullptr) {
69       logdebug("%s failed with error: %s", __func__, r);
70       return Err<json_object *>(r);
71    }
72    return Ok(json_object_new_object());
73 }
74
75 binding_api::result_type binding_api::list_drawing_names() {
76    logdebug("%s", __func__);
77    json j = this->app->id_alloc.name2id;
78    return Ok(json_tokener_parse(j.dump().c_str()));
79 }
80
81 binding_api::result_type binding_api::debug_layers() {
82    logdebug("%s", __func__);
83    return Ok(json_tokener_parse(this->app->layers.to_json().dump().c_str()));
84 }
85
86 binding_api::result_type binding_api::debug_surfaces() {
87    logdebug("%s", __func__);
88    return Ok(to_json(this->app->controller->sprops));
89 }
90
91 binding_api::result_type binding_api::debug_status() {
92    logdebug("%s", __func__);
93    json_object *jr = json_object_new_object();
94    json_object_object_add(jr, "surfaces",
95                           to_json(this->app->controller->sprops));
96    json_object_object_add(jr, "layers", to_json(this->app->controller->lprops));
97    return Ok(jr);
98 }
99
100 binding_api::result_type binding_api::debug_terminate() {
101    logdebug("%s", __func__);
102    if (getenv("WINMAN_DEBUG_TERMINATE") != nullptr) {
103       raise(SIGKILL);  // XXX afb-daemon kills it's pgroup using TERM, which
104                        // doesn't play well with perf
105    }
106    return Ok(json_object_new_object());
107 }
108
109 binding_api::result_type binding_api::ping() {
110    this->app->api_ping();
111    return Ok(json_object_new_object());
112 }
113
114 }  // namespace wm