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

D-Bus 1.13.18

dbus-pollable-set.h
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /*
3 * dbus-pollable-set.h - a set of pollable objects (file descriptors, sockets or handles)
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_POLLABLE_SET_H
27 #define DBUS_POLLABLE_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 } DBusPollableEvent;
38
39 typedef struct DBusPollableSet DBusPollableSet;
40
41 typedef struct DBusPollableSetClass DBusPollableSetClass;
42 struct DBusPollableSetClass {
43 void (*free) (DBusPollableSet *self);
44 dbus_bool_t (*add) (DBusPollableSet *self,
45 DBusPollable fd,
46 unsigned int flags,
47 dbus_bool_t enabled);
48 void (*remove) (DBusPollableSet *self,
49 DBusPollable fd);
50 void (*enable) (DBusPollableSet *self,
51 DBusPollable fd,
52 unsigned int flags);
53 void (*disable) (DBusPollableSet *self,
54 DBusPollable fd);
55 int (*poll) (DBusPollableSet *self,
56 DBusPollableEvent *revents,
57 int max_events,
58 int timeout_ms);
59 };
60
61 struct DBusPollableSet {
62 DBusPollableSetClass *cls;
63 };
64
65 DBusPollableSet *_dbus_pollable_set_new (int size_hint);
66
67 static inline void
68 _dbus_pollable_set_free (DBusPollableSet *self)
69 {
70 (self->cls->free) (self);
71 }
72
73 static inline dbus_bool_t
74 _dbus_pollable_set_add (DBusPollableSet *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_pollable_set_remove (DBusPollableSet *self,
84 DBusPollable fd)
85 {
86 (self->cls->remove) (self, fd);
87 }
88
89 static inline void
90 _dbus_pollable_set_enable (DBusPollableSet *self,
91 DBusPollable fd,
92 unsigned int flags)
93 {
94 (self->cls->enable) (self, fd, flags);
95 }
96
97 static inline void
98 _dbus_pollable_set_disable (DBusPollableSet *self,
99 DBusPollable fd)
100 {
101 (self->cls->disable) (self, fd);
102 }
103
104
105 static inline int
106 _dbus_pollable_set_poll (DBusPollableSet *self,
107 DBusPollableEvent *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 DBusPollableSetClass _dbus_pollable_set_poll_class;
117 extern DBusPollableSetClass _dbus_pollable_set_epoll_class;
118
119 DBusPollableSet *_dbus_pollable_set_poll_new (int size_hint);
120 DBusPollableSet *_dbus_pollable_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
Definition: dbus-types.h:35