D-Bus
1.6.8
|
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 00033 typedef struct { 00034 int fd; 00035 unsigned int flags; 00036 } DBusSocketEvent; 00037 00038 typedef struct DBusSocketSet DBusSocketSet; 00039 00040 typedef struct DBusSocketSetClass DBusSocketSetClass; 00041 struct DBusSocketSetClass { 00042 void (*free) (DBusSocketSet *self); 00043 dbus_bool_t (*add) (DBusSocketSet *self, 00044 int fd, 00045 unsigned int flags, 00046 dbus_bool_t enabled); 00047 void (*remove) (DBusSocketSet *self, 00048 int fd); 00049 void (*enable) (DBusSocketSet *self, 00050 int fd, 00051 unsigned int flags); 00052 void (*disable) (DBusSocketSet *self, 00053 int fd); 00054 int (*poll) (DBusSocketSet *self, 00055 DBusSocketEvent *revents, 00056 int max_events, 00057 int timeout_ms); 00058 }; 00059 00060 struct DBusSocketSet { 00061 DBusSocketSetClass *cls; 00062 }; 00063 00064 DBusSocketSet *_dbus_socket_set_new (int size_hint); 00065 00066 static inline void 00067 _dbus_socket_set_free (DBusSocketSet *self) 00068 { 00069 (self->cls->free) (self); 00070 } 00071 00072 static inline dbus_bool_t 00073 _dbus_socket_set_add (DBusSocketSet *self, 00074 int fd, 00075 unsigned int flags, 00076 dbus_bool_t enabled) 00077 { 00078 return (self->cls->add) (self, fd, flags, enabled); 00079 } 00080 00081 static inline void 00082 _dbus_socket_set_remove (DBusSocketSet *self, 00083 int fd) 00084 { 00085 (self->cls->remove) (self, fd); 00086 } 00087 00088 static inline void 00089 _dbus_socket_set_enable (DBusSocketSet *self, 00090 int fd, 00091 unsigned int flags) 00092 { 00093 (self->cls->enable) (self, fd, flags); 00094 } 00095 00096 static inline void 00097 _dbus_socket_set_disable (DBusSocketSet *self, 00098 int fd) 00099 { 00100 (self->cls->disable) (self, fd); 00101 } 00102 00103 00104 static inline int 00105 _dbus_socket_set_poll (DBusSocketSet *self, 00106 DBusSocketEvent *revents, 00107 int max_events, 00108 int timeout_ms) 00109 { 00110 return (self->cls->poll) (self, revents, max_events, timeout_ms); 00111 } 00112 00113 /* concrete implementations, not necessarily built on all platforms */ 00114 00115 extern DBusSocketSetClass _dbus_socket_set_poll_class; 00116 extern DBusSocketSetClass _dbus_socket_set_epoll_class; 00117 00118 DBusSocketSet *_dbus_socket_set_poll_new (int size_hint); 00119 DBusSocketSet *_dbus_socket_set_epoll_new (void); 00120 00121 #endif /* !DOXYGEN_SHOULD_SKIP_THIS */ 00122 #endif /* multiple-inclusion guard */