- struct Poller p {};
- p.add_fd(STDIN_FILENO, [&c](int fd) {
- int buf;
- ssize_t ret;
- ret = read(fd, &buf, sizeof(buf));
- c.c->debug_dump_current_status();
- return ret == 0 ? -1 : 0;
- });
+ sd_event *ev = afb_daemon_get_event_loop();
+ sd_event_add_io(
+ ev, &g_wayland->event_source, g_wayland->display->get_fd(),
+ EPOLLIN | EPOLLHUP,
+ [](sd_event_source *evs, int fd, uint32_t events, void *data) {
+ if ((events & EPOLLHUP) != 0) {
+ sd_event_source_unref(evs);
+ delete g_wayland;
+ g_wayland = nullptr;
+ return 1;
+ }
+
+ if (events & EPOLLIN) {
+ int ret = g_wayland->display->dispatch();
+ g_wayland->display->flush();
+
+ // execute pending tasks, that is layout changes etc.
+ g_wayland->controller->execute_pending();
+ g_wayland->display->roundtrip();
+ return ret == -1 ? -1 : 0;
+ }
+
+ return 0;
+ },
+ g_wayland);
+
+ atexit([] { delete g_wayland; });
+
+ return 0;
+}
+
+int binding_init() noexcept {
+ try {
+ return binding_init_();
+ } catch (std::exception &e) {
+ AFB_ERROR("Uncaught exception in binding_init(): %s", e.what());
+ }
+ return -1;
+}