main: wrap afb verb handlers, "namepace" debug verbs
authorMarcus Fritzsch <marcus_fritzsch@mentor.com>
Thu, 6 Jul 2017 13:31:31 +0000 (15:31 +0200)
committerMarcus Fritzsch <marcus_fritzsch@mentor.com>
Tue, 8 Aug 2017 15:24:00 +0000 (17:24 +0200)
Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
src/main.cpp

index 7be0b57..bf78b52 100644 (file)
@@ -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