summaryrefslogtreecommitdiff
path: root/src/dbus-common.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2011-05-23 21:36:52 +0200
committerLennart Poettering <lennart@poettering.net>2011-06-21 19:29:43 +0200
commit3df5bf612325b0f6a19acb67befe28d6b07d3804 (patch)
tree9b46afe30a073f303227d3af2606857476cacdbe /src/dbus-common.c
parent3661ac04b4f2840d3345605aa35963bbde3c469d (diff)
dbus: make bus_flags_to_events() and friends generally useful
Diffstat (limited to 'src/dbus-common.c')
-rw-r--r--src/dbus-common.c36
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;
+}