D-Bus
1.10.12
|
00001 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ 00002 /* 00003 * dbus-socket-set.h - used to bolt file descriptors onto a bus 00004 * 00005 * Copyright © 2011 Nokia Corporation 00006 * 00007 * Licensed under the Academic Free License version 2.1 00008 * 00009 * This program is free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program; if not, write to the Free Software 00021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00022 * MA 02110-1301 USA 00023 * 00024 */ 00025 00026 #ifndef DBUS_SOCKET_SET_H 00027 #define DBUS_SOCKET_SET_H 00028 00029 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00030 00031 #include <dbus/dbus.h> 00032 #include <dbus/dbus-sysdeps.h> 00033 00034 typedef struct { 00035 DBusPollable fd; 00036 unsigned int flags; 00037 } DBusSocketEvent; 00038 00039 typedef struct DBusSocketSet DBusSocketSet; 00040 00041 typedef struct DBusSocketSetClass DBusSocketSetClass; 00042 struct DBusSocketSetClass { 00043 void (*free) (DBusSocketSet *self); 00044 dbus_bool_t (*add) (DBusSocketSet *self, 00045 DBusPollable fd, 00046 unsigned int flags, 00047 dbus_bool_t enabled); 00048 void (*remove) (DBusSocketSet *self, 00049 DBusPollable fd); 00050 void (*enable) (DBusSocketSet *self, 00051 DBusPollable fd, 00052 unsigned int flags); 00053 void (*disable) (DBusSocketSet *self, 00054 DBusPollable fd); 00055 int (*poll) (DBusSocketSet *self, 00056 DBusSocketEvent *revents, 00057 int max_events, 00058 int timeout_ms); 00059 }; 00060 00061 struct DBusSocketSet { 00062 DBusSocketSetClass *cls; 00063 }; 00064 00065 DBusSocketSet *_dbus_socket_set_new (int size_hint); 00066 00067 static inline void 00068 _dbus_socket_set_free (DBusSocketSet *self) 00069 { 00070 (self->cls->free) (self); 00071 } 00072 00073 static inline dbus_bool_t 00074 _dbus_socket_set_add (DBusSocketSet *self, 00075 DBusPollable fd, 00076 unsigned int flags, 00077 dbus_bool_t enabled) 00078 { 00079 return (self->cls->add) (self, fd, flags, enabled); 00080 } 00081 00082 static inline void 00083 _dbus_socket_set_remove (DBusSocketSet *self, 00084 DBusPollable fd) 00085 { 00086 (self->cls->remove) (self, fd); 00087 } 00088 00089 static inline void 00090 _dbus_socket_set_enable (DBusSocketSet *self, 00091 DBusPollable fd, 00092 unsigned int flags) 00093 { 00094 (self->cls->enable) (self, fd, flags); 00095 } 00096 00097 static inline void 00098 _dbus_socket_set_disable (DBusSocketSet *self, 00099 DBusPollable fd) 00100 { 00101 (self->cls->disable) (self, fd); 00102 } 00103 00104 00105 static inline int 00106 _dbus_socket_set_poll (DBusSocketSet *self, 00107 DBusSocketEvent *revents, 00108 int max_events, 00109 int timeout_ms) 00110 { 00111 return (self->cls->poll) (self, revents, max_events, timeout_ms); 00112 } 00113 00114 /* concrete implementations, not necessarily built on all platforms */ 00115 00116 extern DBusSocketSetClass _dbus_socket_set_poll_class; 00117 extern DBusSocketSetClass _dbus_socket_set_epoll_class; 00118 00119 DBusSocketSet *_dbus_socket_set_poll_new (int size_hint); 00120 DBusSocketSet *_dbus_socket_set_epoll_new (void); 00121 00122 #endif /* !DOXYGEN_SHOULD_SKIP_THIS */ 00123 #endif /* multiple-inclusion guard */