summaryrefslogtreecommitdiffstats
path: root/src/main.cpp
diff options
context:
space:
mode:
authorMarcus Fritzsch <marcus_fritzsch@mentor.com>2017-07-06 11:32:50 +0200
committerMarcus Fritzsch <marcus_fritzsch@mentor.com>2017-08-08 17:24:00 +0200
commit9dfa6b9427115e7402ce25e40e4d78b20d559c93 (patch)
treea790ce4ce7b15930c1550c5b08bc51930dd75dbc /src/main.cpp
parentba5360ac03286364abd9fde6b500e2c0fabe56b1 (diff)
Move all nlohmann::json to json_helper.cpp
Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp65
1 files changed, 11 insertions, 54 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 1ac26f1..a2331c4 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,3 +1,4 @@
+#include "json_helper.hpp"
#include "util.hpp"
#include "wayland.hpp"
@@ -11,8 +12,6 @@ extern "C" {
#include <systemd/sd-event.h>
}
-#include <json.hpp>
-
namespace {
struct wayland {
std::unique_ptr<wl::display> display;
@@ -178,8 +177,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;
}
}
@@ -224,67 +222,26 @@ void debug_status(struct afb_req req) noexcept {
CHECK_WAYLAND();
- 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;
- }
+ 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));
- 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");
+ 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();
-
- 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));
- }
- }
-
- afb_req_success(req, a, "surfaces");
+ afb_req_success(req, to_json(g_wayland->controller->layers), "layers");
}
const struct afb_verb_v2 verbs[] = {