2 * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "json_helper.hpp"
24 using json = nlohmann::json;
26 #include <json-c/json.h>
32 binding_api::result_type binding_api::requestsurface(
33 char const *drawing_name) {
34 auto r = this->app->api_request_surface(drawing_name);
36 return Err<json_object *>(r.unwrap_err());
38 return Ok(json_object_new_int(r.unwrap()));
41 binding_api::result_type binding_api::requestsurfacexdg(
42 char const *drawing_name, char const *ivi_id) {
43 auto r = this->app->api_request_surface(drawing_name, ivi_id);
45 HMI_DEBUG("wm", "%s failed with error: %s", __func__, r);
46 return Err<json_object *>(r);
48 return Ok(json_object_new_object());
51 binding_api::result_type binding_api::activatesurface(
52 char const *drawing_name, char const *drawing_area) {
53 HMI_DEBUG("wm", "%s drawing_name %s, drawing_area %s", __func__, drawing_name, drawing_area);
54 auto r = this->app->api_activate_surface(drawing_name, drawing_area);
56 HMI_DEBUG("wm", "%s failed with error: %s", __func__, r);
57 return Err<json_object *>(r);
59 return Ok(json_object_new_object());
62 binding_api::result_type binding_api::deactivatesurface(char const* drawing_name) {
63 HMI_DEBUG("wm", "%s drawing_name %s", __func__, drawing_name);
64 auto r = this->app->api_deactivate_surface(drawing_name);
66 HMI_DEBUG("wm", "%s failed with error: %s", __func__, r);
67 return Err<json_object *>(r);
69 return Ok(json_object_new_object());
72 binding_api::result_type binding_api::enddraw(char const* drawing_name) {
73 HMI_DEBUG("wm", "%s drawing_name %s", __func__, drawing_name);
74 auto r = this->app->api_enddraw(drawing_name);
76 HMI_DEBUG("wm", "%s failed with error: %s", __func__, r);
77 return Err<json_object *>(r);
79 return Ok(json_object_new_object());
82 binding_api::result_type binding_api::list_drawing_names() {
83 HMI_DEBUG("wm", "%s", __func__);
84 json j = this->app->id_alloc.name2id;
85 return Ok(json_tokener_parse(j.dump().c_str()));
88 binding_api::result_type binding_api::debug_layers() {
89 HMI_DEBUG("wm", "%s", __func__);
90 return Ok(json_tokener_parse(this->app->layers.to_json().dump().c_str()));
93 binding_api::result_type binding_api::debug_surfaces() {
94 HMI_DEBUG("wm", "%s", __func__);
95 return Ok(to_json(this->app->controller->sprops));
98 binding_api::result_type binding_api::debug_status() {
99 HMI_DEBUG("wm", "%s", __func__);
100 json_object *jr = json_object_new_object();
101 json_object_object_add(jr, "surfaces",
102 to_json(this->app->controller->sprops));
103 json_object_object_add(jr, "layers", to_json(this->app->controller->lprops));
107 binding_api::result_type binding_api::debug_terminate() {
108 HMI_DEBUG("wm", "%s", __func__);
109 if (getenv("WINMAN_DEBUG_TERMINATE") != nullptr) {
110 raise(SIGKILL); // afb-daemon kills it's pgroup using TERM, which
111 // doesn't play well with perf
113 return Ok(json_object_new_object());
116 binding_api::result_type binding_api::ping() {
117 this->app->api_ping();
118 return Ok(json_object_new_object());