X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fmain.cpp;h=bf78b52dfd31f3479e2dbfead32c8ad29c68469e;hb=5ba849b33c433730c586da57cfe7851e0c2a9b91;hp=1ac26f117df2669694cd83095cd50e00ef08b876;hpb=ba5360ac03286364abd9fde6b500e2c0fabe56b1;p=staging%2Fwindowmanager.git diff --git a/src/main.cpp b/src/main.cpp index 1ac26f1..bf78b52 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,18 +1,16 @@ +#include "json_helper.hpp" #include "util.hpp" #include "wayland.hpp" #include #include -#define AFB_BINDING_VERSION 2 - extern "C" { +#define AFB_BINDING_VERSION 2 #include #include } -#include - namespace { struct wayland { std::unique_ptr display; @@ -178,8 +176,7 @@ int binding_init_() { g_wayland->display->get_fd(), EPOLLIN, display_event_callback, g_wayland); if (ret < 0) { - AFB_ERROR("Could not initialize wayland event handler: %s", - std::strerror(-ret)); + AFB_ERROR("Could not initialize wayland event handler: %d", -ret); goto error; } } @@ -218,79 +215,42 @@ int binding_init() noexcept { // | (_| | __/ |_) | |_| | (_| | \__ \ || (_| | |_| |_| \__ \ | | | // \__,_|\___|_.__/ \__,_|\__, |___|___/\__\__,_|\__|\__,_|___/ | | | // |___/_____| \_\/_/ -void debug_status(struct afb_req req) noexcept { +void debug_status(struct afb_req req) { // Quick and dirty, dump current surfaces and layers AFB_REQ_DEBUG(req, "status"); - CHECK_WAYLAND(); + auto o = json_object_new_object(); + json_object_object_add(o, "surfaces", + to_json(g_wayland->controller->surfaces)); + json_object_object_add(o, "layers", to_json(g_wayland->controller->layers)); + json_object_object_add(o, "screens", + to_json(g_wayland->controller->screens)); - try { - using json = nlohmann::json; - - json j; - - if (!g_wayland->controller->surfaces.empty()) { - auto a = json::array(); - for (auto const &i : g_wayland->controller->surfaces) { - auto const &r = i.second->dst_rect; - auto const &s = i.second->size; - a.push_back({{"id", i.first}, - {"size", {s.w, s.h}}, - {"dst_rect", {r.w, r.h, r.x, r.y}}}); - } - j["surfaces"] = a; - } - - if (!g_wayland->controller->layers.empty()) { - auto a = json::array(); - for (auto const &i : g_wayland->controller->layers) { - auto const &r = i.second->dst_rect; - auto const &s = i.second->size; - a.push_back({{"id", i.first}, - {"size", {s.w, s.h}}, - {"dst_rect", {r.w, r.h, r.x, r.y}}}); - } - j["layers"] = a; - } - - afb_req_success(req, json_tokener_parse(j.dump().c_str()), "status"); - } catch (std::exception &e) { - afb_req_fail_f(req, "failed", "Uncaught exception: %s", e.what()); - } + afb_req_success(req, o, "status"); } -void debug_surfaces(afb_req req) noexcept { - CHECK_WAYLAND(); - - auto a = json_object_new_array(); - - if (!g_wayland->controller->surfaces.empty()) { - for (auto const &i : g_wayland->controller->surfaces) { - json_object_array_add(a, json_object_new_int(i.first)); - } - } - - afb_req_success(req, a, "surfaces"); +void debug_surfaces(afb_req req) { + afb_req_success(req, to_json(g_wayland->controller->surfaces), "surfaces"); } -void debug_layers(afb_req req) noexcept { - CHECK_WAYLAND(); - - auto a = json_object_new_array(); +void debug_layers(afb_req req) { + afb_req_success(req, to_json(g_wayland->controller->layers), "layers"); +} - if (!g_wayland->controller->layers.empty()) { - for (auto const &i : g_wayland->controller->layers) { - json_object_array_add(a, json_object_new_int(i.first)); - } +#define WRAP(F) \ + [](afb_req req) noexcept { \ + CHECK_WAYLAND(); \ + try { \ + F(req); \ + } catch (std::exception & e) { \ + afb_req_fail_f(req, "failed", "Uncaught exception: %s", e.what()); \ + } \ } - afb_req_success(req, a, "surfaces"); -} - const struct afb_verb_v2 verbs[] = { - {"status", debug_status, NULL, NULL, AFB_SESSION_NONE_V2}, - {"layers", debug_layers, NULL, NULL, AFB_SESSION_NONE_V2}, - {"surfaces", debug_surfaces, NULL, NULL, AFB_SESSION_NONE_V2}, + {"debug::status", WRAP(debug_status), NULL, NULL, AFB_SESSION_NONE_V2}, + {"debug::layers", WRAP(debug_layers), NULL, NULL, AFB_SESSION_NONE_V2}, + {"debug::surfaces", WRAP(debug_surfaces), NULL, NULL, AFB_SESSION_NONE_V2}, {}, }; } // namespace