From: Ralf Habacker Date: Mon, 7 Jan 2019 12:07:12 +0000 (+0100) Subject: Rename structure DBusSocketSet to DBusPollableSet and adjust the corresponding functi... X-Git-Tag: dbus-1.13.10~27^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4573c15ebbf5b62a381c62a58bb833c4e95f2433;p=thirdparty%2Fdbus.git Rename structure DBusSocketSet to DBusPollableSet and adjust the corresponding functions/files Because the implementation of DBusSocketSet already supports non-socket pollables like pipes and inotify fd on Unix, DBusPollableSet is a better name. --- diff --git a/cmake/dbus/CMakeLists.txt b/cmake/dbus/CMakeLists.txt index 960dbdaff..77b6c10ab 100644 --- a/cmake/dbus/CMakeLists.txt +++ b/cmake/dbus/CMakeLists.txt @@ -162,8 +162,8 @@ set (DBUS_UTIL_SOURCES ${DBUS_DIR}/dbus-message-factory.c ${DBUS_DIR}/dbus-message-util.c ${DBUS_DIR}/dbus-shell.c - ${DBUS_DIR}/dbus-socket-set.c - ${DBUS_DIR}/dbus-socket-set-poll.c + ${DBUS_DIR}/dbus-pollable-set.c + ${DBUS_DIR}/dbus-pollable-set-poll.c ${DBUS_DIR}/dbus-string-util.c ${DBUS_DIR}/dbus-sysdeps-util.c ) @@ -182,7 +182,7 @@ set (DBUS_UTIL_HEADERS ${DBUS_DIR}/dbus-mainloop.h ${DBUS_DIR}/dbus-message-factory.h ${DBUS_DIR}/dbus-shell.h - ${DBUS_DIR}/dbus-socket-set.h + ${DBUS_DIR}/dbus-pollable-set.h ${DBUS_DIR}/dbus-spawn.h ${DBUS_DIR}/dbus-test.h ${DBUS_DIR}/dbus-test-wrappers.h @@ -237,7 +237,7 @@ endif (WIN32) if(DBUS_HAVE_LINUX_EPOLL) set(DBUS_UTIL_SOURCES ${DBUS_UTIL_SOURCES} - ${DBUS_DIR}/dbus-socket-set-epoll.c + ${DBUS_DIR}/dbus-pollable-set-epoll.c ) endif() diff --git a/dbus/Makefile.am b/dbus/Makefile.am index 3ca6f050f..08fb850ec 100644 --- a/dbus/Makefile.am +++ b/dbus/Makefile.am @@ -122,7 +122,7 @@ DBUS_UTIL_arch_sources = \ endif if DBUS_HAVE_LINUX_EPOLL -DBUS_UTIL_arch_sources += dbus-socket-set-epoll.c +DBUS_UTIL_arch_sources += dbus-pollable-set-epoll.c endif dbusinclude_HEADERS= \ @@ -260,9 +260,9 @@ DBUS_UTIL_SOURCES= \ dbus-shell.c \ dbus-shell.h \ $(DBUS_UTIL_arch_sources) \ - dbus-socket-set.h \ - dbus-socket-set.c \ - dbus-socket-set-poll.c \ + dbus-pollable-set.h \ + dbus-pollable-set.c \ + dbus-pollable-set-poll.c \ dbus-spawn.h \ dbus-string-util.c \ dbus-sysdeps-util.c \ diff --git a/dbus/dbus-mainloop.c b/dbus/dbus-mainloop.c index 5a7315973..c4b7151be 100644 --- a/dbus/dbus-mainloop.c +++ b/dbus/dbus-mainloop.c @@ -29,7 +29,7 @@ #include #include -#include +#include #include #include @@ -40,7 +40,7 @@ struct DBusLoop int refcount; /** DBusPollable => dbus_malloc'd DBusList ** of references to DBusWatch */ DBusHashTable *watches; - DBusSocketSet *socket_set; + DBusPollableSet *pollable_set; DBusList *timeouts; int callback_list_serial; int watch_count; @@ -116,15 +116,15 @@ _dbus_loop_new (void) loop->watches = _dbus_hash_table_new (DBUS_HASH_POLLABLE, NULL, free_watch_table_entry); - loop->socket_set = _dbus_socket_set_new (0); + loop->pollable_set = _dbus_pollable_set_new (0); - if (loop->watches == NULL || loop->socket_set == NULL) + if (loop->watches == NULL || loop->pollable_set == NULL) { if (loop->watches != NULL) _dbus_hash_table_unref (loop->watches); - if (loop->socket_set != NULL) - _dbus_socket_set_free (loop->socket_set); + if (loop->pollable_set != NULL) + _dbus_pollable_set_free (loop->pollable_set); dbus_free (loop); return NULL; @@ -163,7 +163,7 @@ _dbus_loop_unref (DBusLoop *loop) } _dbus_hash_table_unref (loop->watches); - _dbus_socket_set_free (loop->socket_set); + _dbus_pollable_set_free (loop->pollable_set); dbus_free (loop); } } @@ -263,9 +263,9 @@ refresh_watches_for_fd (DBusLoop *loop, } if (interested) - _dbus_socket_set_enable (loop->socket_set, fd, flags); + _dbus_pollable_set_enable (loop->pollable_set, fd, flags); else - _dbus_socket_set_disable (loop->socket_set, fd); + _dbus_pollable_set_disable (loop->pollable_set, fd); } dbus_bool_t @@ -293,7 +293,7 @@ _dbus_loop_add_watch (DBusLoop *loop, if (_dbus_list_length_is_one (watches)) { - if (!_dbus_socket_set_add (loop->socket_set, fd, + if (!_dbus_pollable_set_add (loop->pollable_set, fd, dbus_watch_get_flags (watch), dbus_watch_get_enabled (watch))) { @@ -354,7 +354,7 @@ _dbus_loop_remove_watch (DBusLoop *loop, * entry, and stop reserving space for it in the socket set */ if (gc_watch_table_entry (loop, watches, fd)) { - _dbus_socket_set_remove (loop->socket_set, fd); + _dbus_pollable_set_remove (loop->pollable_set, fd); } return; @@ -570,7 +570,7 @@ _dbus_loop_iterate (DBusLoop *loop, { #define N_STACK_DESCRIPTORS 64 dbus_bool_t retval; - DBusSocketEvent ready_fds[N_STACK_DESCRIPTORS]; + DBusPollableEvent ready_fds[N_STACK_DESCRIPTORS]; int i; DBusList *link; int n_ready; @@ -660,8 +660,8 @@ _dbus_loop_iterate (DBusLoop *loop, _dbus_verbose (" polling on %d descriptors timeout %ld\n", _DBUS_N_ELEMENTS (ready_fds), timeout); #endif - n_ready = _dbus_socket_set_poll (loop->socket_set, ready_fds, - _DBUS_N_ELEMENTS (ready_fds), timeout); + n_ready = _dbus_pollable_set_poll (loop->pollable_set, ready_fds, + _DBUS_N_ELEMENTS (ready_fds), timeout); /* re-enable any watches we skipped this time */ if (loop->oom_watch_pending) diff --git a/dbus/dbus-socket-set-epoll.c b/dbus/dbus-pollable-set-epoll.c similarity index 81% rename from dbus/dbus-socket-set-epoll.c rename to dbus/dbus-pollable-set-epoll.c index 4692cbe45..7bd200b3f 100644 --- a/dbus/dbus-socket-set-epoll.c +++ b/dbus/dbus-pollable-set-epoll.c @@ -1,5 +1,5 @@ /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* dbus-socket-set-epoll.c - a socket set implemented via Linux epoll(4) +/* dbus-pollable-set-epoll.c - a pollable set implemented via Linux epoll(4) * * Copyright © 2011 Nokia Corporation * @@ -23,7 +23,7 @@ */ #include -#include "dbus-socket-set.h" +#include "dbus-pollable-set.h" #include #include @@ -40,22 +40,22 @@ #ifndef DOXYGEN_SHOULD_SKIP_THIS typedef struct { - DBusSocketSet parent; + DBusPollableSet parent; int epfd; -} DBusSocketSetEpoll; +} DBusPollableSetEpoll; -static inline DBusSocketSetEpoll * -socket_set_epoll_cast (DBusSocketSet *set) +static inline DBusPollableSetEpoll * +socket_set_epoll_cast (DBusPollableSet *set) { - _dbus_assert (set->cls == &_dbus_socket_set_epoll_class); - return (DBusSocketSetEpoll *) set; + _dbus_assert (set->cls == &_dbus_pollable_set_epoll_class); + return (DBusPollableSetEpoll *) set; } /* this is safe to call on a partially-allocated socket set */ static void -socket_set_epoll_free (DBusSocketSet *set) +socket_set_epoll_free (DBusPollableSet *set) { - DBusSocketSetEpoll *self = socket_set_epoll_cast (set); + DBusPollableSetEpoll *self = socket_set_epoll_cast (set); if (self == NULL) return; @@ -66,17 +66,17 @@ socket_set_epoll_free (DBusSocketSet *set) dbus_free (self); } -DBusSocketSet * -_dbus_socket_set_epoll_new (void) +DBusPollableSet * +_dbus_pollable_set_epoll_new (void) { - DBusSocketSetEpoll *self; + DBusPollableSetEpoll *self; - self = dbus_new0 (DBusSocketSetEpoll, 1); + self = dbus_new0 (DBusPollableSetEpoll, 1); if (self == NULL) return NULL; - self->parent.cls = &_dbus_socket_set_epoll_class; + self->parent.cls = &_dbus_pollable_set_epoll_class; self->epfd = epoll_create1 (EPOLL_CLOEXEC); @@ -97,11 +97,11 @@ _dbus_socket_set_epoll_new (void) if (self->epfd == -1) { - socket_set_epoll_free ((DBusSocketSet *) self); + socket_set_epoll_free ((DBusPollableSet *) self); return NULL; } - return (DBusSocketSet *) self; + return (DBusPollableSet *) self; } static uint32_t @@ -135,12 +135,12 @@ epoll_events_to_watch_flags (uint32_t events) } static dbus_bool_t -socket_set_epoll_add (DBusSocketSet *set, - DBusPollable fd, - unsigned int flags, - dbus_bool_t enabled) +socket_set_epoll_add (DBusPollableSet *set, + DBusPollable fd, + unsigned int flags, + dbus_bool_t enabled) { - DBusSocketSetEpoll *self = socket_set_epoll_cast (set); + DBusPollableSetEpoll *self = socket_set_epoll_cast (set); struct epoll_event event; int err; @@ -189,11 +189,11 @@ socket_set_epoll_add (DBusSocketSet *set, } static void -socket_set_epoll_enable (DBusSocketSet *set, - DBusPollable fd, - unsigned int flags) +socket_set_epoll_enable (DBusPollableSet *set, + DBusPollable fd, + unsigned int flags) { - DBusSocketSetEpoll *self = socket_set_epoll_cast (set); + DBusPollableSetEpoll *self = socket_set_epoll_cast (set); struct epoll_event event; int err; @@ -230,10 +230,10 @@ socket_set_epoll_enable (DBusSocketSet *set, } static void -socket_set_epoll_disable (DBusSocketSet *set, - DBusPollable fd) +socket_set_epoll_disable (DBusPollableSet *set, + DBusPollable fd) { - DBusSocketSetEpoll *self = socket_set_epoll_cast (set); + DBusPollableSetEpoll *self = socket_set_epoll_cast (set); struct epoll_event event; int err; @@ -266,10 +266,10 @@ socket_set_epoll_disable (DBusSocketSet *set, } static void -socket_set_epoll_remove (DBusSocketSet *set, - DBusPollable fd) +socket_set_epoll_remove (DBusPollableSet *set, + DBusPollable fd) { - DBusSocketSetEpoll *self = socket_set_epoll_cast (set); + DBusPollableSetEpoll *self = socket_set_epoll_cast (set); int err; /* Kernels < 2.6.9 require a non-NULL struct pointer, even though its * contents are ignored */ @@ -289,12 +289,12 @@ socket_set_epoll_remove (DBusSocketSet *set, #define N_STACK_DESCRIPTORS 64 static int -socket_set_epoll_poll (DBusSocketSet *set, - DBusSocketEvent *revents, - int max_events, - int timeout_ms) +socket_set_epoll_poll (DBusPollableSet *set, + DBusPollableEvent *revents, + int max_events, + int timeout_ms) { - DBusSocketSetEpoll *self = socket_set_epoll_cast (set); + DBusPollableSetEpoll *self = socket_set_epoll_cast (set); struct epoll_event events[N_STACK_DESCRIPTORS]; int n_ready; int i; @@ -317,7 +317,7 @@ socket_set_epoll_poll (DBusSocketSet *set, return n_ready; } -DBusSocketSetClass _dbus_socket_set_epoll_class = { +DBusPollableSetClass _dbus_pollable_set_epoll_class = { socket_set_epoll_free, socket_set_epoll_add, socket_set_epoll_remove, diff --git a/dbus/dbus-socket-set-poll.c b/dbus/dbus-pollable-set-poll.c similarity index 79% rename from dbus/dbus-socket-set-poll.c rename to dbus/dbus-pollable-set-poll.c index 623e28fa3..24c2c9610 100644 --- a/dbus/dbus-socket-set-poll.c +++ b/dbus/dbus-pollable-set-poll.c @@ -1,5 +1,5 @@ /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* dbus-socket-set-poll.c - a socket set implemented via _dbus_poll +/* dbus-pollable-set-poll.c - a pollable set implemented via _dbus_poll * * Copyright © 2011 Nokia Corporation * @@ -23,7 +23,7 @@ */ #include -#include "dbus-socket-set.h" +#include "dbus-pollable-set.h" #include #include @@ -33,12 +33,12 @@ #ifndef DOXYGEN_SHOULD_SKIP_THIS typedef struct { - DBusSocketSet parent; - DBusPollFD *fds; - int n_fds; - int n_reserved; - int n_allocated; -} DBusSocketSetPoll; + DBusPollableSet parent; + DBusPollFD *fds; + int n_fds; + int n_reserved; + int n_allocated; +} DBusPollableSetPoll; #define REALLOC_INCREMENT 8 #define MINIMUM_SIZE 8 @@ -50,38 +50,38 @@ typedef struct { #define DEFAULT_SIZE_HINT MINIMUM_SIZE #endif -static inline DBusSocketSetPoll * -socket_set_poll_cast (DBusSocketSet *set) +static inline DBusPollableSetPoll * +socket_set_poll_cast (DBusPollableSet *set) { - _dbus_assert (set->cls == &_dbus_socket_set_poll_class); - return (DBusSocketSetPoll *) set; + _dbus_assert (set->cls == &_dbus_pollable_set_poll_class); + return (DBusPollableSetPoll *) set; } /* this is safe to call on a partially-allocated socket set */ static void -socket_set_poll_free (DBusSocketSet *set) +socket_set_poll_free (DBusPollableSet *set) { - DBusSocketSetPoll *self = socket_set_poll_cast (set); + DBusPollableSetPoll *self = socket_set_poll_cast (set); dbus_free (self->fds); dbus_free (self); _dbus_verbose ("freed socket set %p\n", self); } -DBusSocketSet * -_dbus_socket_set_poll_new (int size_hint) +DBusPollableSet * +_dbus_pollable_set_poll_new (int size_hint) { - DBusSocketSetPoll *ret; + DBusPollableSetPoll *ret; if (size_hint <= 0) size_hint = DEFAULT_SIZE_HINT; - ret = dbus_new0 (DBusSocketSetPoll, 1); + ret = dbus_new0 (DBusPollableSetPoll, 1); if (ret == NULL) return NULL; - ret->parent.cls = &_dbus_socket_set_poll_class; + ret->parent.cls = &_dbus_pollable_set_poll_class; ret->n_fds = 0; ret->n_allocated = size_hint; @@ -91,12 +91,12 @@ _dbus_socket_set_poll_new (int size_hint) { /* socket_set_poll_free specifically supports half-constructed * socket sets */ - socket_set_poll_free ((DBusSocketSet *) ret); + socket_set_poll_free ((DBusPollableSet *) ret); return NULL; } _dbus_verbose ("new socket set at %p\n", ret); - return (DBusSocketSet *) ret; + return (DBusPollableSet *) ret; } static short @@ -113,12 +113,12 @@ watch_flags_to_poll_events (unsigned int flags) } static dbus_bool_t -socket_set_poll_add (DBusSocketSet *set, - DBusPollable fd, - unsigned int flags, - dbus_bool_t enabled) +socket_set_poll_add (DBusPollableSet *set, + DBusPollable fd, + unsigned int flags, + dbus_bool_t enabled) { - DBusSocketSetPoll *self = socket_set_poll_cast (set); + DBusPollableSetPoll *self = socket_set_poll_cast (set); #ifndef DBUS_DISABLE_ASSERT int i; @@ -160,11 +160,11 @@ socket_set_poll_add (DBusSocketSet *set, } static void -socket_set_poll_enable (DBusSocketSet *set, - DBusPollable fd, - unsigned int flags) +socket_set_poll_enable (DBusPollableSet *set, + DBusPollable fd, + unsigned int flags) { - DBusSocketSetPoll *self = socket_set_poll_cast (set); + DBusPollableSetPoll *self = socket_set_poll_cast (set); int i; for (i = 0; i < self->n_fds; i++) @@ -186,10 +186,10 @@ socket_set_poll_enable (DBusSocketSet *set, } static void -socket_set_poll_disable (DBusSocketSet *set, +socket_set_poll_disable (DBusPollableSet *set, DBusPollable fd) { - DBusSocketSetPoll *self = socket_set_poll_cast (set); + DBusPollableSetPoll *self = socket_set_poll_cast (set); int i; for (i = 0; i < self->n_fds; i++) @@ -209,10 +209,10 @@ socket_set_poll_disable (DBusSocketSet *set, } static void -socket_set_poll_remove (DBusSocketSet *set, - DBusPollable fd) +socket_set_poll_remove (DBusPollableSet *set, + DBusPollable fd) { - DBusSocketSetPoll *self = socket_set_poll_cast (set); + DBusPollableSetPoll *self = socket_set_poll_cast (set); socket_set_poll_disable (set, fd); self->n_reserved--; @@ -266,12 +266,12 @@ watch_flags_from_poll_revents (short revents) /** This is basically Linux's epoll_wait(2) implemented in terms of poll(2); * it returns results into a caller-supplied buffer so we can be reentrant. */ static int -socket_set_poll_poll (DBusSocketSet *set, - DBusSocketEvent *revents, - int max_events, - int timeout_ms) +socket_set_poll_poll (DBusPollableSet *set, + DBusPollableEvent *revents, + int max_events, + int timeout_ms) { - DBusSocketSetPoll *self = socket_set_poll_cast (set); + DBusPollableSetPoll *self = socket_set_poll_cast (set); int i; int n_events; int n_ready; @@ -308,7 +308,7 @@ socket_set_poll_poll (DBusSocketSet *set, return n_events; } -DBusSocketSetClass _dbus_socket_set_poll_class = { +DBusPollableSetClass _dbus_pollable_set_poll_class = { socket_set_poll_free, socket_set_poll_add, socket_set_poll_remove, diff --git a/dbus/dbus-socket-set.c b/dbus/dbus-pollable-set.c similarity index 78% rename from dbus/dbus-socket-set.c rename to dbus/dbus-pollable-set.c index 210d600e3..e3aaedc59 100644 --- a/dbus/dbus-socket-set.c +++ b/dbus/dbus-pollable-set.c @@ -1,6 +1,6 @@ /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ /* - * dbus-socket-set.c - used to bolt file descriptors onto a bus + * dbus-pollable-set.c - a set of pollable objects (file descriptors, sockets or handles) * * Copyright © 2011 Nokia Corporation * @@ -24,21 +24,21 @@ */ #include -#include +#include -DBusSocketSet * -_dbus_socket_set_new (int size_hint) +DBusPollableSet * +_dbus_pollable_set_new (int size_hint) { - DBusSocketSet *ret; + DBusPollableSet *ret; #ifdef DBUS_HAVE_LINUX_EPOLL - ret = _dbus_socket_set_epoll_new (); + ret = _dbus_pollable_set_epoll_new (); if (ret != NULL) return ret; #endif - ret = _dbus_socket_set_poll_new (size_hint); + ret = _dbus_pollable_set_poll_new (size_hint); if (ret != NULL) return ret; diff --git a/dbus/dbus-pollable-set.h b/dbus/dbus-pollable-set.h new file mode 100644 index 000000000..b92d776ab --- /dev/null +++ b/dbus/dbus-pollable-set.h @@ -0,0 +1,123 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* + * dbus-pollable-set.h - a set of pollable objects (file descriptors, sockets or handles) + * + * Copyright © 2011 Nokia Corporation + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + * + */ + +#ifndef DBUS_POLLABLE_SET_H +#define DBUS_POLLABLE_SET_H + +#ifndef DOXYGEN_SHOULD_SKIP_THIS + +#include +#include + +typedef struct { + DBusPollable fd; + unsigned int flags; +} DBusPollableEvent; + +typedef struct DBusPollableSet DBusPollableSet; + +typedef struct DBusPollableSetClass DBusPollableSetClass; +struct DBusPollableSetClass { + void (*free) (DBusPollableSet *self); + dbus_bool_t (*add) (DBusPollableSet *self, + DBusPollable fd, + unsigned int flags, + dbus_bool_t enabled); + void (*remove) (DBusPollableSet *self, + DBusPollable fd); + void (*enable) (DBusPollableSet *self, + DBusPollable fd, + unsigned int flags); + void (*disable) (DBusPollableSet *self, + DBusPollable fd); + int (*poll) (DBusPollableSet *self, + DBusPollableEvent *revents, + int max_events, + int timeout_ms); +}; + +struct DBusPollableSet { + DBusPollableSetClass *cls; +}; + +DBusPollableSet *_dbus_pollable_set_new (int size_hint); + +static inline void +_dbus_pollable_set_free (DBusPollableSet *self) +{ + (self->cls->free) (self); +} + +static inline dbus_bool_t +_dbus_pollable_set_add (DBusPollableSet *self, + DBusPollable fd, + unsigned int flags, + dbus_bool_t enabled) +{ + return (self->cls->add) (self, fd, flags, enabled); +} + +static inline void +_dbus_pollable_set_remove (DBusPollableSet *self, + DBusPollable fd) +{ + (self->cls->remove) (self, fd); +} + +static inline void +_dbus_pollable_set_enable (DBusPollableSet *self, + DBusPollable fd, + unsigned int flags) +{ + (self->cls->enable) (self, fd, flags); +} + +static inline void +_dbus_pollable_set_disable (DBusPollableSet *self, + DBusPollable fd) +{ + (self->cls->disable) (self, fd); +} + + +static inline int +_dbus_pollable_set_poll (DBusPollableSet *self, + DBusPollableEvent *revents, + int max_events, + int timeout_ms) +{ + return (self->cls->poll) (self, revents, max_events, timeout_ms); +} + +/* concrete implementations, not necessarily built on all platforms */ + +extern DBusPollableSetClass _dbus_pollable_set_poll_class; +extern DBusPollableSetClass _dbus_pollable_set_epoll_class; + +DBusPollableSet *_dbus_pollable_set_poll_new (int size_hint); +DBusPollableSet *_dbus_pollable_set_epoll_new (void); + +#endif /* !DOXYGEN_SHOULD_SKIP_THIS */ +#endif /* multiple-inclusion guard */ diff --git a/dbus/dbus-socket-set.h b/dbus/dbus-socket-set.h deleted file mode 100644 index bcc263a7b..000000000 --- a/dbus/dbus-socket-set.h +++ /dev/null @@ -1,123 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* - * dbus-socket-set.h - used to bolt file descriptors onto a bus - * - * Copyright © 2011 Nokia Corporation - * - * Licensed under the Academic Free License version 2.1 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - */ - -#ifndef DBUS_SOCKET_SET_H -#define DBUS_SOCKET_SET_H - -#ifndef DOXYGEN_SHOULD_SKIP_THIS - -#include -#include - -typedef struct { - DBusPollable fd; - unsigned int flags; -} DBusSocketEvent; - -typedef struct DBusSocketSet DBusSocketSet; - -typedef struct DBusSocketSetClass DBusSocketSetClass; -struct DBusSocketSetClass { - void (*free) (DBusSocketSet *self); - dbus_bool_t (*add) (DBusSocketSet *self, - DBusPollable fd, - unsigned int flags, - dbus_bool_t enabled); - void (*remove) (DBusSocketSet *self, - DBusPollable fd); - void (*enable) (DBusSocketSet *self, - DBusPollable fd, - unsigned int flags); - void (*disable) (DBusSocketSet *self, - DBusPollable fd); - int (*poll) (DBusSocketSet *self, - DBusSocketEvent *revents, - int max_events, - int timeout_ms); -}; - -struct DBusSocketSet { - DBusSocketSetClass *cls; -}; - -DBusSocketSet *_dbus_socket_set_new (int size_hint); - -static inline void -_dbus_socket_set_free (DBusSocketSet *self) -{ - (self->cls->free) (self); -} - -static inline dbus_bool_t -_dbus_socket_set_add (DBusSocketSet *self, - DBusPollable fd, - unsigned int flags, - dbus_bool_t enabled) -{ - return (self->cls->add) (self, fd, flags, enabled); -} - -static inline void -_dbus_socket_set_remove (DBusSocketSet *self, - DBusPollable fd) -{ - (self->cls->remove) (self, fd); -} - -static inline void -_dbus_socket_set_enable (DBusSocketSet *self, - DBusPollable fd, - unsigned int flags) -{ - (self->cls->enable) (self, fd, flags); -} - -static inline void -_dbus_socket_set_disable (DBusSocketSet *self, - DBusPollable fd) -{ - (self->cls->disable) (self, fd); -} - - -static inline int -_dbus_socket_set_poll (DBusSocketSet *self, - DBusSocketEvent *revents, - int max_events, - int timeout_ms) -{ - return (self->cls->poll) (self, revents, max_events, timeout_ms); -} - -/* concrete implementations, not necessarily built on all platforms */ - -extern DBusSocketSetClass _dbus_socket_set_poll_class; -extern DBusSocketSetClass _dbus_socket_set_epoll_class; - -DBusSocketSet *_dbus_socket_set_poll_new (int size_hint); -DBusSocketSet *_dbus_socket_set_epoll_new (void); - -#endif /* !DOXYGEN_SHOULD_SKIP_THIS */ -#endif /* multiple-inclusion guard */