PipeWire  0.3.66
spa/include/spa/support/loop.h
Go to the documentation of this file.
1 /* Simple Plugin API */
2 /* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
3 /* SPDX-License-Identifier: MIT */
4 
5 #ifndef SPA_LOOP_H
6 #define SPA_LOOP_H
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 #include <spa/utils/defs.h>
13 #include <spa/utils/hook.h>
14 #include <spa/support/system.h>
15 
25 #define SPA_TYPE_INTERFACE_Loop SPA_TYPE_INFO_INTERFACE_BASE "Loop"
26 #define SPA_TYPE_INTERFACE_DataLoop SPA_TYPE_INFO_INTERFACE_BASE "DataLoop"
27 #define SPA_VERSION_LOOP 0
28 struct spa_loop { struct spa_interface iface; };
29 
30 #define SPA_TYPE_INTERFACE_LoopControl SPA_TYPE_INFO_INTERFACE_BASE "LoopControl"
31 #define SPA_VERSION_LOOP_CONTROL 0
32 struct spa_loop_control { struct spa_interface iface; };
33 
34 #define SPA_TYPE_INTERFACE_LoopUtils SPA_TYPE_INFO_INTERFACE_BASE "LoopUtils"
35 #define SPA_VERSION_LOOP_UTILS 0
36 struct spa_loop_utils { struct spa_interface iface; };
37 
38 struct spa_source;
39 
40 typedef void (*spa_source_func_t) (struct spa_source *source);
41 
42 struct spa_source {
43  struct spa_loop *loop;
45  void *data;
46  int fd;
47  uint32_t mask;
48  uint32_t rmask;
49  /* private data for the loop implementer */
50  void *priv;
51 };
52 
53 typedef int (*spa_invoke_func_t) (struct spa_loop *loop,
54  bool async,
55  uint32_t seq,
56  const void *data,
57  size_t size,
58  void *user_data);
59 
64  /* the version of this structure. This can be used to expand this
65  * structure in the future */
66 #define SPA_VERSION_LOOP_METHODS 0
67  uint32_t version;
68 
70  int (*add_source) (void *object,
71  struct spa_source *source);
72 
74  int (*update_source) (void *object,
75  struct spa_source *source);
76 
78  int (*remove_source) (void *object,
79  struct spa_source *source);
80 
82  int (*invoke) (void *object,
84  uint32_t seq,
85  const void *data,
86  size_t size,
87  bool block,
88  void *user_data);
89 };
90 
91 #define spa_loop_method(o,method,version,...) \
92 ({ \
93  int _res = -ENOTSUP; \
94  struct spa_loop *_o = o; \
95  spa_interface_call_res(&_o->iface, \
96  struct spa_loop_methods, _res, \
97  method, version, ##__VA_ARGS__); \
98  _res; \
99 })
100 
101 #define spa_loop_add_source(l,...) spa_loop_method(l,add_source,0,##__VA_ARGS__)
102 #define spa_loop_update_source(l,...) spa_loop_method(l,update_source,0,##__VA_ARGS__)
103 #define spa_loop_remove_source(l,...) spa_loop_method(l,remove_source,0,##__VA_ARGS__)
104 #define spa_loop_invoke(l,...) spa_loop_method(l,invoke,0,##__VA_ARGS__)
105 
106 
110 struct spa_loop_control_hooks {
111 #define SPA_VERSION_LOOP_CONTROL_HOOKS 0
112  uint32_t version;
115  void (*before) (void *data);
118  void (*after) (void *data);
119 };
120 
121 #define spa_loop_control_hook_before(l) \
122 ({ \
123  struct spa_hook_list *_l = l; \
124  struct spa_hook *_h; \
125  spa_list_for_each_reverse(_h, &_l->list, link) \
126  spa_callbacks_call(&_h->cb, struct spa_loop_control_hooks, before, 0); \
127 })
128 
129 #define spa_loop_control_hook_after(l) \
130 ({ \
131  struct spa_hook_list *_l = l; \
132  struct spa_hook *_h; \
133  spa_list_for_each(_h, &_l->list, link) \
134  spa_callbacks_call(&_h->cb, struct spa_loop_control_hooks, after, 0); \
135 })
136 
141  /* the version of this structure. This can be used to expand this
142  * structure in the future */
143 #define SPA_VERSION_LOOP_CONTROL_METHODS 0
144  uint32_t version;
145 
146  int (*get_fd) (void *object);
147 
154  void (*add_hook) (void *object,
155  struct spa_hook *hook,
156  const struct spa_loop_control_hooks *hooks,
157  void *data);
158 
166  void (*enter) (void *object);
173  void (*leave) (void *object);
174 
184  int (*iterate) (void *object, int timeout);
185 };
186 
187 #define spa_loop_control_method_v(o,method,version,...) \
188 ({ \
189  struct spa_loop_control *_o = o; \
190  spa_interface_call(&_o->iface, \
191  struct spa_loop_control_methods, \
192  method, version, ##__VA_ARGS__); \
193 })
194 
195 #define spa_loop_control_method_r(o,method,version,...) \
196 ({ \
197  int _res = -ENOTSUP; \
198  struct spa_loop_control *_o = o; \
199  spa_interface_call_res(&_o->iface, \
200  struct spa_loop_control_methods, _res, \
201  method, version, ##__VA_ARGS__); \
202  _res; \
203 })
204 
205 #define spa_loop_control_get_fd(l) spa_loop_control_method_r(l,get_fd,0)
206 #define spa_loop_control_add_hook(l,...) spa_loop_control_method_v(l,add_hook,0,__VA_ARGS__)
207 #define spa_loop_control_enter(l) spa_loop_control_method_v(l,enter,0)
208 #define spa_loop_control_leave(l) spa_loop_control_method_v(l,leave,0)
209 #define spa_loop_control_iterate(l,...) spa_loop_control_method_r(l,iterate,0,__VA_ARGS__)
210 
211 typedef void (*spa_source_io_func_t) (void *data, int fd, uint32_t mask);
212 typedef void (*spa_source_idle_func_t) (void *data);
213 typedef void (*spa_source_event_func_t) (void *data, uint64_t count);
214 typedef void (*spa_source_timer_func_t) (void *data, uint64_t expirations);
215 typedef void (*spa_source_signal_func_t) (void *data, int signal_number);
216 
220 struct spa_loop_utils_methods {
221  /* the version of this structure. This can be used to expand this
222  * structure in the future */
223 #define SPA_VERSION_LOOP_UTILS_METHODS 0
224  uint32_t version;
225 
226  struct spa_source *(*add_io) (void *object,
227  int fd,
228  uint32_t mask,
229  bool close,
231 
232  int (*update_io) (void *object, struct spa_source *source, uint32_t mask);
233 
234  struct spa_source *(*add_idle) (void *object,
235  bool enabled,
237  int (*enable_idle) (void *object, struct spa_source *source, bool enabled);
238 
239  struct spa_source *(*add_event) (void *object,
241  int (*signal_event) (void *object, struct spa_source *source);
242 
243  struct spa_source *(*add_timer) (void *object,
245  int (*update_timer) (void *object,
246  struct spa_source *source,
247  struct timespec *value,
248  struct timespec *interval,
249  bool absolute);
250  struct spa_source *(*add_signal) (void *object,
251  int signal_number,
253 
257  void (*destroy_source) (void *object, struct spa_source *source);
258 };
259 
260 #define spa_loop_utils_method_v(o,method,version,...) \
261 ({ \
262  struct spa_loop_utils *_o = o; \
263  spa_interface_call(&_o->iface, \
264  struct spa_loop_utils_methods, \
265  method, version, ##__VA_ARGS__); \
266 })
267 
268 #define spa_loop_utils_method_r(o,method,version,...) \
269 ({ \
270  int _res = -ENOTSUP; \
271  struct spa_loop_utils *_o = o; \
272  spa_interface_call_res(&_o->iface, \
273  struct spa_loop_utils_methods, _res, \
274  method, version, ##__VA_ARGS__); \
275  _res; \
276 })
277 #define spa_loop_utils_method_s(o,method,version,...) \
278 ({ \
279  struct spa_source *_res = NULL; \
280  struct spa_loop_utils *_o = o; \
281  spa_interface_call_res(&_o->iface, \
282  struct spa_loop_utils_methods, _res, \
283  method, version, ##__VA_ARGS__); \
284  _res; \
285 })
286 
287 
288 #define spa_loop_utils_add_io(l,...) spa_loop_utils_method_s(l,add_io,0,__VA_ARGS__)
289 #define spa_loop_utils_update_io(l,...) spa_loop_utils_method_r(l,update_io,0,__VA_ARGS__)
290 #define spa_loop_utils_add_idle(l,...) spa_loop_utils_method_s(l,add_idle,0,__VA_ARGS__)
291 #define spa_loop_utils_enable_idle(l,...) spa_loop_utils_method_r(l,enable_idle,0,__VA_ARGS__)
292 #define spa_loop_utils_add_event(l,...) spa_loop_utils_method_s(l,add_event,0,__VA_ARGS__)
293 #define spa_loop_utils_signal_event(l,...) spa_loop_utils_method_r(l,signal_event,0,__VA_ARGS__)
294 #define spa_loop_utils_add_timer(l,...) spa_loop_utils_method_s(l,add_timer,0,__VA_ARGS__)
295 #define spa_loop_utils_update_timer(l,...) spa_loop_utils_method_r(l,update_timer,0,__VA_ARGS__)
296 #define spa_loop_utils_add_signal(l,...) spa_loop_utils_method_s(l,add_signal,0,__VA_ARGS__)
297 #define spa_loop_utils_destroy_source(l,...) spa_loop_utils_method_v(l,destroy_source,0,__VA_ARGS__)
298 
303 #ifdef __cplusplus
304 } /* extern "C" */
305 #endif
306 
307 #endif /* SPA_LOOP_H */
spa/utils/defs.h
void(* spa_source_timer_func_t)(void *data, uint64_t expirations)
Definition: spa/include/spa/support/loop.h:248
void(* spa_source_event_func_t)(void *data, uint64_t count)
Definition: spa/include/spa/support/loop.h:247
void(* spa_source_signal_func_t)(void *data, int signal_number)
Definition: spa/include/spa/support/loop.h:249
void(* spa_source_idle_func_t)(void *data)
Definition: spa/include/spa/support/loop.h:246
void(* spa_source_func_t)(struct spa_source *source)
Definition: spa/include/spa/support/loop.h:53
int(* spa_invoke_func_t)(struct spa_loop *loop, bool async, uint32_t seq, const void *data, size_t size, void *user_data)
Definition: spa/include/spa/support/loop.h:66
void(* spa_source_io_func_t)(void *data, int fd, uint32_t mask)
Definition: spa/include/spa/support/loop.h:245
spa/utils/hook.h
A hook, contains the structure with functions and the data passed to the functions.
Definition: hook.h:331
Definition: hook.h:138
Control hooks.
Definition: spa/include/spa/support/loop.h:132
void(* before)(void *data)
Executed right before waiting for events.
Definition: spa/include/spa/support/loop.h:138
uint32_t version
Definition: spa/include/spa/support/loop.h:135
void(* after)(void *data)
Executed right after waiting for events.
Definition: spa/include/spa/support/loop.h:141
Control an event loop.
Definition: spa/include/spa/support/loop.h:163
int(* get_fd)(void *object)
Definition: spa/include/spa/support/loop.h:170
int(* iterate)(void *object, int timeout)
Perform one iteration of the loop.
Definition: spa/include/spa/support/loop.h:208
void(* enter)(void *object)
Enter a loop.
Definition: spa/include/spa/support/loop.h:190
void(* add_hook)(void *object, struct spa_hook *hook, const struct spa_loop_control_hooks *hooks, void *data)
Add a hook.
Definition: spa/include/spa/support/loop.h:178
void(* leave)(void *object)
Leave a loop.
Definition: spa/include/spa/support/loop.h:197
uint32_t version
Definition: spa/include/spa/support/loop.h:168
Definition: spa/include/spa/support/loop.h:42
struct spa_interface iface
Definition: spa/include/spa/support/loop.h:42
Register sources and work items to an event loop.
Definition: spa/include/spa/support/loop.h:76
int(* add_source)(void *object, struct spa_source *source)
add a source to the loop
Definition: spa/include/spa/support/loop.h:84
int(* remove_source)(void *object, struct spa_source *source)
remove a source from the loop
Definition: spa/include/spa/support/loop.h:92
int(* invoke)(void *object, spa_invoke_func_t func, uint32_t seq, const void *data, size_t size, bool block, void *user_data)
invoke a function in the context of this loop
Definition: spa/include/spa/support/loop.h:96
int(* update_source)(void *object, struct spa_source *source)
update the source io mask
Definition: spa/include/spa/support/loop.h:88
uint32_t version
Definition: spa/include/spa/support/loop.h:81
Create sources for an event loop.
Definition: spa/include/spa/support/loop.h:254
int(* update_io)(void *object, struct spa_source *source, uint32_t mask)
Definition: spa/include/spa/support/loop.h:267
int(* enable_idle)(void *object, struct spa_source *source, bool enabled)
Definition: spa/include/spa/support/loop.h:272
int(* signal_event)(void *object, struct spa_source *source)
Definition: spa/include/spa/support/loop.h:276
int(* update_timer)(void *object, struct spa_source *source, struct timespec *value, struct timespec *interval, bool absolute)
Definition: spa/include/spa/support/loop.h:280
void(* destroy_source)(void *object, struct spa_source *source)
destroy a source allocated with this interface.
Definition: spa/include/spa/support/loop.h:292
uint32_t version
Definition: spa/include/spa/support/loop.h:259
Definition: spa/include/spa/support/loop.h:48
struct spa_interface iface
Definition: spa/include/spa/support/loop.h:48
Definition: spa/include/spa/support/loop.h:36
struct spa_interface iface
Definition: spa/include/spa/support/loop.h:36
Definition: spa/include/spa/support/loop.h:55
uint32_t rmask
Definition: spa/include/spa/support/loop.h:61
void * data
Definition: spa/include/spa/support/loop.h:58
void * priv
Definition: spa/include/spa/support/loop.h:63
uint32_t mask
Definition: spa/include/spa/support/loop.h:60
spa_source_func_t func
Definition: spa/include/spa/support/loop.h:57
int fd
Definition: spa/include/spa/support/loop.h:59
struct spa_loop * loop
Definition: spa/include/spa/support/loop.h:56
spa/support/system.h