diff options
Diffstat (limited to 'src/dbus-common.c')
-rw-r--r-- | src/dbus-common.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/dbus-common.c b/src/dbus-common.c index 5db077b74f..c2650fdf33 100644 --- a/src/dbus-common.c +++ b/src/dbus-common.c @@ -27,6 +27,7 @@ #include <stdlib.h> #include <dbus/dbus.h> #include <string.h> +#include <sys/epoll.h> #include "log.h" #include "dbus-common.h" @@ -698,3 +699,38 @@ oom: return NULL; } + +uint32_t bus_flags_to_events(DBusWatch *bus_watch) { + unsigned flags; + uint32_t events = 0; + + assert(bus_watch); + + /* no watch flags for disabled watches */ + if (!dbus_watch_get_enabled(bus_watch)) + return 0; + + flags = dbus_watch_get_flags(bus_watch); + + if (flags & DBUS_WATCH_READABLE) + events |= EPOLLIN; + if (flags & DBUS_WATCH_WRITABLE) + events |= EPOLLOUT; + + return events | EPOLLHUP | EPOLLERR; +} + +unsigned bus_events_to_flags(uint32_t events) { + unsigned flags = 0; + + if (events & EPOLLIN) + flags |= DBUS_WATCH_READABLE; + if (events & EPOLLOUT) + flags |= DBUS_WATCH_WRITABLE; + if (events & EPOLLHUP) + flags |= DBUS_WATCH_HANGUP; + if (events & EPOLLERR) + flags |= DBUS_WATCH_ERROR; + + return flags; +} |