From 5ba849b33c433730c586da57cfe7851e0c2a9b91 Mon Sep 17 00:00:00 2001 From: Marcus Fritzsch Date: Thu, 6 Jul 2017 15:31:31 +0200 Subject: [PATCH] main: wrap afb verb handlers, "namepace" debug verbs Signed-off-by: Marcus Fritzsch --- src/main.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7be0b57..bf78b52 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -215,12 +215,10 @@ 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)); @@ -231,22 +229,28 @@ void debug_status(struct afb_req req) noexcept { afb_req_success(req, o, "status"); } -void debug_surfaces(afb_req req) noexcept { - CHECK_WAYLAND(); - +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(); - +void debug_layers(afb_req req) { afb_req_success(req, to_json(g_wayland->controller->layers), "layers"); } +#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()); \ + } \ + } + 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 -- 2.16.6