diff options
-rw-r--r-- | src/main.cpp | 74 |
1 files changed, 38 insertions, 36 deletions
diff --git a/src/main.cpp b/src/main.cpp index 965599d..d4da785 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,19 +11,21 @@ extern "C" { } namespace { -struct wayland { +struct afb_instance { std::unique_ptr<wl::display> display; std::unique_ptr<genivi::controller> controller; std::vector<std::unique_ptr<wl::output>> outputs; - wayland() : display(new wl::display), controller(nullptr), outputs() {} + wm::App app; + + afb_instance() : display{new wl::display}, controller{nullptr}, outputs{}, app{} {} int init(); }; -struct wayland *g_wayland; +struct afb_instance *g_afb_instance; -int wayland::init() { +int afb_instance::init() { if (!this->display->ok()) { return -1; } @@ -31,20 +33,20 @@ int wayland::init() { this->display->r.add_global_handler("wl_output", [](wl_registry *r, uint32_t name, uint32_t v) { - g_wayland->outputs.emplace_back(std::make_unique<wl::output>(r, name, v)); + g_afb_instance->outputs.emplace_back(std::make_unique<wl::output>(r, name, v)); }); this->display->r.add_global_handler( "ivi_controller", [](wl_registry *r, uint32_t name, uint32_t v) { - g_wayland->controller = + g_afb_instance->controller = std::make_unique<genivi::controller>(r, name, v); // XXX: This protocol needs the output, so lets just add our mapping // here... - g_wayland->controller->add_proxy_to_id_mapping( - g_wayland->outputs.back()->proxy.get(), + g_afb_instance->controller->add_proxy_to_id_mapping( + g_afb_instance->outputs.back()->proxy.get(), wl_proxy_get_id(reinterpret_cast<struct wl_proxy *>( - g_wayland->outputs.back()->proxy.get()))); + g_afb_instance->outputs.back()->proxy.get()))); }); // First level objects @@ -64,17 +66,17 @@ int wayland::init() { // |_|_| |_|_|\__|___|_|\__,_|\__, |\___/ \__,_|\__| | | | // |_____| |___/ \_\/_/ char const *init_layout() { - if (!g_wayland->controller) { + if (!g_afb_instance->controller) { return "ivi_controller global not available"; } - if (g_wayland->outputs.empty()) { + if (g_afb_instance->outputs.empty()) { return "no output was set up!"; } - auto &c = g_wayland->controller; + auto &c = g_afb_instance->controller; - auto &o = g_wayland->outputs.front(); + auto &o = g_afb_instance->outputs.front(); auto &s = c->screens.begin()->second; auto &layers = c->layers; @@ -105,7 +107,7 @@ char const *init_layout() { c->commit_changes(); - g_wayland->display->flush(); + g_afb_instance->display->flush(); return nullptr; } @@ -114,23 +116,23 @@ int display_event_callback(sd_event_source *evs, int fd, uint32_t events, void *data) { if ((events & EPOLLHUP) != 0) { logerror("The compositor hung up, dying now."); - delete g_wayland; - g_wayland = nullptr; + delete g_afb_instance; + g_afb_instance = nullptr; goto error; } if (events & EPOLLIN) { - int ret = g_wayland->display->dispatch(); + int ret = g_afb_instance->display->dispatch(); if (ret == -1) { logerror("wl_display_dipatch() returned error %d", - g_wayland->display->get_error()); + g_afb_instance->display->get_error()); goto error; } - g_wayland->display->flush(); + g_afb_instance->display->flush(); // execute pending tasks, that is layout changes etc. - g_wayland->controller->execute_pending(); - g_wayland->display->roundtrip(); + g_afb_instance->controller->execute_pending(); + g_afb_instance->display->roundtrip(); } return 0; @@ -149,7 +151,7 @@ error: int binding_init_() { lognotice("WinMan ver. %s", WINMAN_VERSION_STRING); - if (g_wayland != nullptr) { + if (g_afb_instance != nullptr) { logerror("Wayland context already initialized?"); return 0; } @@ -159,8 +161,8 @@ int binding_init_() { goto error; } - g_wayland = new wayland; - if (g_wayland->init() == -1) { + g_afb_instance = new afb_instance; + if (g_afb_instance->init() == -1) { logerror("Could not connect to compositor"); goto error; } @@ -172,21 +174,21 @@ int binding_init_() { { int ret = sd_event_add_io(afb_daemon_get_event_loop(), nullptr, - g_wayland->display->get_fd(), EPOLLIN, - display_event_callback, g_wayland); + g_afb_instance->display->get_fd(), EPOLLIN, + display_event_callback, g_afb_instance); if (ret < 0) { - logerror("Could not initialize wayland event handler: %d", -ret); + logerror("Could not initialize afb_instance event handler: %d", -ret); goto error; } } - atexit([] { delete g_wayland; }); + atexit([] { delete g_afb_instance; }); return 0; error: - delete g_wayland; - g_wayland = nullptr; + delete g_afb_instance; + g_afb_instance = nullptr; return -1; } @@ -211,20 +213,20 @@ void debug_status(struct afb_req req) { auto o = json_object_new_object(); json_object_object_add(o, "surfaces", - to_json(g_wayland->controller->sprops)); - json_object_object_add(o, "layers", to_json(g_wayland->controller->lprops)); + to_json(g_afb_instance->controller->sprops)); + json_object_object_add(o, "layers", to_json(g_afb_instance->controller->lprops)); // json_object_object_add(o, "screens", -// to_json(g_wayland->controller->screens)); +// to_json(g_afb_instance->controller->screens)); afb_req_success(req, o, "status"); } void debug_surfaces(afb_req req) { - afb_req_success(req, to_json(g_wayland->controller->sprops), "surfaces"); + afb_req_success(req, to_json(g_afb_instance->controller->sprops), "surfaces"); } void debug_layers(afb_req req) { - afb_req_success(req, to_json(g_wayland->controller->lprops), "layers"); + afb_req_success(req, to_json(g_afb_instance->controller->lprops), "layers"); } // Dummy register_surface implementation @@ -264,7 +266,7 @@ void register_surface(afb_req req) { #define WRAP(F) \ [](afb_req req) noexcept { \ - if (g_wayland == nullptr) { \ + if (g_afb_instance == nullptr) { \ afb_req_fail(req, "failed", \ "Binding not initialized, did the compositor die?"); \ return; \ |