D-Bus: dbus-socket-set.h Source File

D-Bus 1.12.2

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 #include <dbus/dbus-sysdeps.h>
33
34 typedef struct {
35 DBusPollable fd;
36 unsigned int flags;
37 } DBusSocketEvent;
38
39 typedef struct DBusSocketSet DBusSocketSet;
40
41 typedef struct DBusSocketSetClass DBusSocketSetClass;
42 struct DBusSocketSetClass {
43 void (*free) (DBusSocketSet *self);
44 dbus_bool_t (*add) (DBusSocketSet *self,
45 DBusPollable fd,
46 unsigned int flags,
47 dbus_bool_t enabled);
48 void (*remove) (DBusSocketSet *self,
49 DBusPollable fd);
50 void (*enable) (DBusSocketSet *self,
51 DBusPollable fd,
52 unsigned int flags);
53 void (*disable) (DBusSocketSet *self,
54 DBusPollable fd);
55 int (*poll) (DBusSocketSet *self,
56 DBusSocketEvent *revents,
57 int max_events,
58 int timeout_ms);
59 };
60
61 struct DBusSocketSet {
62 DBusSocketSetClass *cls;
63 };
64
65 DBusSocketSet *_dbus_socket_set_new (int size_hint);
66
67 static inline void
68 _dbus_socket_set_free (DBusSocketSet *self)
69 {
70 (self->cls->free) (self);
71 }
72
73 static inline dbus_bool_t
74 _dbus_socket_set_add (DBusSocketSet *self,
75 DBusPollable fd,
76 unsigned int flags,
77 dbus_bool_t enabled)
78 {
79 return (self->cls->add) (self, fd, flags, enabled);
80 }
81
82 static inline void
83 _dbus_socket_set_remove (DBusSocketSet *self,
84 DBusPollable fd)
85 {
86 (self->cls->remove) (self, fd);
87 }
88
89 static inline void
90 _dbus_socket_set_enable (DBusSocketSet *self,
91 DBusPollable fd,
92 unsigned int flags)
93 {
94 (self->cls->enable) (self, fd, flags);
95 }
96
97 static inline void
98 _dbus_socket_set_disable (DBusSocketSet *self,
99 DBusPollable fd)
100 {
101 (self->cls->disable) (self, fd);
102 }
103
104
105 static inline int
106 _dbus_socket_set_poll (DBusSocketSet *self,
107 DBusSocketEvent *revents,
108 int max_events,
109 int timeout_ms)
110 {
111 return (self->cls->poll) (self, revents, max_events, timeout_ms);
112 }
113
114 /* concrete implementations, not necessarily built on all platforms */
115
116 extern DBusSocketSetClass _dbus_socket_set_poll_class;
117 extern DBusSocketSetClass _dbus_socket_set_epoll_class;
118
119 DBusSocketSet *_dbus_socket_set_poll_new (int size_hint);
120 DBusSocketSet *_dbus_socket_set_epoll_new (void);
121
122 #endif /* !DOXYGEN_SHOULD_SKIP_THIS */
123 #endif /* multiple-inclusion guard */
dbus_bool_t
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Definition: dbus-types.h:35