D-Bus  1.6.12
dbus-socket-set.h
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /*
3  * dbus-socket-set.h - used to bolt file descriptors onto a bus
4  *
5  * Copyright © 2011 Nokia Corporation
6  *
7  * Licensed under the Academic Free License version 2.1
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22  * MA 02110-1301 USA
23  *
24  */
25 
26 #ifndef DBUS_SOCKET_SET_H
27 #define DBUS_SOCKET_SET_H
28 
29 #ifndef DOXYGEN_SHOULD_SKIP_THIS
30 
31 #include <dbus/dbus.h>
32 
33 typedef struct {
34  int fd;
35  unsigned int flags;
36 } DBusSocketEvent;
37 
38 typedef struct DBusSocketSet DBusSocketSet;
39 
40 typedef struct DBusSocketSetClass DBusSocketSetClass;
41 struct DBusSocketSetClass {
42  void (*free) (DBusSocketSet *self);
43  dbus_bool_t (*add) (DBusSocketSet *self,
44  int fd,
45  unsigned int flags,
46  dbus_bool_t enabled);
47  void (*remove) (DBusSocketSet *self,
48  int fd);
49  void (*enable) (DBusSocketSet *self,
50  int fd,
51  unsigned int flags);
52  void (*disable) (DBusSocketSet *self,
53  int fd);
54  int (*poll) (DBusSocketSet *self,
55  DBusSocketEvent *revents,
56  int max_events,
57  int timeout_ms);
58 };
59 
60 struct DBusSocketSet {
61  DBusSocketSetClass *cls;
62 };
63 
64 DBusSocketSet *_dbus_socket_set_new (int size_hint);
65 
66 static inline void
67 _dbus_socket_set_free (DBusSocketSet *self)
68 {
69  (self->cls->free) (self);
70 }
71 
72 static inline dbus_bool_t
73 _dbus_socket_set_add (DBusSocketSet *self,
74  int fd,
75  unsigned int flags,
76  dbus_bool_t enabled)
77 {
78  return (self->cls->add) (self, fd, flags, enabled);
79 }
80 
81 static inline void
82 _dbus_socket_set_remove (DBusSocketSet *self,
83  int fd)
84 {
85  (self->cls->remove) (self, fd);
86 }
87 
88 static inline void
89 _dbus_socket_set_enable (DBusSocketSet *self,
90  int fd,
91  unsigned int flags)
92 {
93  (self->cls->enable) (self, fd, flags);
94 }
95 
96 static inline void
97 _dbus_socket_set_disable (DBusSocketSet *self,
98  int fd)
99 {
100  (self->cls->disable) (self, fd);
101 }
102 
103 
104 static inline int
105 _dbus_socket_set_poll (DBusSocketSet *self,
106  DBusSocketEvent *revents,
107  int max_events,
108  int timeout_ms)
109 {
110  return (self->cls->poll) (self, revents, max_events, timeout_ms);
111 }
112 
113 /* concrete implementations, not necessarily built on all platforms */
114 
115 extern DBusSocketSetClass _dbus_socket_set_poll_class;
116 extern DBusSocketSetClass _dbus_socket_set_epoll_class;
117 
118 DBusSocketSet *_dbus_socket_set_poll_new (int size_hint);
119 DBusSocketSet *_dbus_socket_set_epoll_new (void);
120 
121 #endif /* !DOXYGEN_SHOULD_SKIP_THIS */
122 #endif /* multiple-inclusion guard */
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Definition: dbus-types.h:35