summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcus Fritzsch <marcus_fritzsch@mentor.com>2017-07-06 15:31:31 +0200
committerMarcus Fritzsch <marcus_fritzsch@mentor.com>2017-08-08 17:24:00 +0200
commit5ba849b33c433730c586da57cfe7851e0c2a9b91 (patch)
treeb28062588700d920db870d7a2512ece0e6fe4b55
parentd45f8674ced71594fa9ba99900cc87a19fcecb20 (diff)
main: wrap afb verb handlers, "namepace" debug verbs
Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
-rw-r--r--src/main.cpp28
1 files 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