PipeWire 1.2.1
Loading...
Searching...
No Matches
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
9extern "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
28struct 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 1
32struct spa_loop_control { struct spa_interface iface; };
34#define SPA_TYPE_INTERFACE_LoopUtils SPA_TYPE_INFO_INTERFACE_BASE "LoopUtils"
35#define SPA_VERSION_LOOP_UTILS 0
37
38struct spa_source;
40typedef void (*spa_source_func_t) (struct spa_source *source);
42struct 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
53typedef 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);
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
75 int (*add_source) (void *object,
76 struct spa_source *source);
77
84 int (*update_source) (void *object,
85 struct spa_source *source);
86
93 int (*remove_source) (void *object,
94 struct spa_source *source);
95
119 int (*invoke) (void *object,
121 uint32_t seq,
122 const void *data,
123 size_t size,
124 bool block,
125 void *user_data);
126};
127
128#define spa_loop_method(o,method,version,...) \
129({ \
130 int _res = -ENOTSUP; \
131 struct spa_loop *_o = o; \
132 spa_interface_call_res(&_o->iface, \
133 struct spa_loop_methods, _res, \
134 method, version, ##__VA_ARGS__); \
135 _res; \
136})
137
138#define spa_loop_add_source(l,...) spa_loop_method(l,add_source,0,##__VA_ARGS__)
139#define spa_loop_update_source(l,...) spa_loop_method(l,update_source,0,##__VA_ARGS__)
140#define spa_loop_remove_source(l,...) spa_loop_method(l,remove_source,0,##__VA_ARGS__)
141#define spa_loop_invoke(l,...) spa_loop_method(l,invoke,0,##__VA_ARGS__)
143
148#define SPA_VERSION_LOOP_CONTROL_HOOKS 0
149 uint32_t version;
152 void (*before) (void *data);
155 void (*after) (void *data);
156};
157
158#define spa_loop_control_hook_before(l) \
159({ \
160 struct spa_hook_list *_l = l; \
161 struct spa_hook *_h; \
162 spa_list_for_each_reverse(_h, &_l->list, link) \
163 spa_callbacks_call_fast(&_h->cb, struct spa_loop_control_hooks, before, 0); \
164})
165
166#define spa_loop_control_hook_after(l) \
167({ \
168 struct spa_hook_list *_l = l; \
169 struct spa_hook *_h; \
170 spa_list_for_each(_h, &_l->list, link) \
171 spa_callbacks_call_fast(&_h->cb, struct spa_loop_control_hooks, after, 0); \
173
178 /* the version of this structure. This can be used to expand this
179 * structure in the future */
180#define SPA_VERSION_LOOP_CONTROL_METHODS 1
181 uint32_t version;
182
183 int (*get_fd) (void *object);
184
191 void (*add_hook) (void *object,
192 struct spa_hook *hook,
193 const struct spa_loop_control_hooks *hooks,
194 void *data);
195
203 void (*enter) (void *object);
210 void (*leave) (void *object);
211
221 int (*iterate) (void *object, int timeout);
222
231 int (*check) (void *object);
232};
233
234#define spa_loop_control_method_v(o,method,version,...) \
235({ \
236 struct spa_loop_control *_o = o; \
237 spa_interface_call(&_o->iface, \
238 struct spa_loop_control_methods, \
239 method, version, ##__VA_ARGS__); \
240})
241
242#define spa_loop_control_method_r(o,method,version,...) \
243({ \
244 int _res = -ENOTSUP; \
245 struct spa_loop_control *_o = o; \
246 spa_interface_call_res(&_o->iface, \
247 struct spa_loop_control_methods, _res, \
248 method, version, ##__VA_ARGS__); \
249 _res; \
250})
251
252#define spa_loop_control_method_fast_r(o,method,version,...) \
253({ \
254 int _res; \
255 struct spa_loop_control *_o = o; \
256 spa_interface_call_fast_res(&_o->iface, \
257 struct spa_loop_control_methods, _res, \
258 method, version, ##__VA_ARGS__); \
259 _res; \
260})
261
262#define spa_loop_control_get_fd(l) spa_loop_control_method_r(l,get_fd,0)
263#define spa_loop_control_add_hook(l,...) spa_loop_control_method_v(l,add_hook,0,__VA_ARGS__)
264#define spa_loop_control_enter(l) spa_loop_control_method_v(l,enter,0)
265#define spa_loop_control_leave(l) spa_loop_control_method_v(l,leave,0)
266#define spa_loop_control_iterate(l,...) spa_loop_control_method_r(l,iterate,0,__VA_ARGS__)
267#define spa_loop_control_check(l) spa_loop_control_method_r(l,check,1)
268
269#define spa_loop_control_iterate_fast(l,...) spa_loop_control_method_fast_r(l,iterate,0,__VA_ARGS__)
270
271typedef void (*spa_source_io_func_t) (void *data, int fd, uint32_t mask);
272typedef void (*spa_source_idle_func_t) (void *data);
273typedef void (*spa_source_event_func_t) (void *data, uint64_t count);
274typedef void (*spa_source_timer_func_t) (void *data, uint64_t expirations);
275typedef void (*spa_source_signal_func_t) (void *data, int signal_number);
281 /* the version of this structure. This can be used to expand this
282 * structure in the future */
283#define SPA_VERSION_LOOP_UTILS_METHODS 0
284 uint32_t version;
285
286 struct spa_source *(*add_io) (void *object,
287 int fd,
288 uint32_t mask,
289 bool close,
290 spa_source_io_func_t func, void *data);
291
292 int (*update_io) (void *object, struct spa_source *source, uint32_t mask);
293
294 struct spa_source *(*add_idle) (void *object,
295 bool enabled,
296 spa_source_idle_func_t func, void *data);
297 int (*enable_idle) (void *object, struct spa_source *source, bool enabled);
299 struct spa_source *(*add_event) (void *object,
300 spa_source_event_func_t func, void *data);
301 int (*signal_event) (void *object, struct spa_source *source);
302
303 struct spa_source *(*add_timer) (void *object,
304 spa_source_timer_func_t func, void *data);
305 int (*update_timer) (void *object,
306 struct spa_source *source,
307 struct timespec *value,
308 struct timespec *interval,
309 bool absolute);
310 struct spa_source *(*add_signal) (void *object,
311 int signal_number,
312 spa_source_signal_func_t func, void *data);
313
317 void (*destroy_source) (void *object, struct spa_source *source);
318};
319
320#define spa_loop_utils_method_v(o,method,version,...) \
321({ \
322 struct spa_loop_utils *_o = o; \
323 spa_interface_call(&_o->iface, \
324 struct spa_loop_utils_methods, \
325 method, version, ##__VA_ARGS__); \
326})
327
328#define spa_loop_utils_method_r(o,method,version,...) \
329({ \
330 int _res = -ENOTSUP; \
331 struct spa_loop_utils *_o = o; \
332 spa_interface_call_res(&_o->iface, \
333 struct spa_loop_utils_methods, _res, \
334 method, version, ##__VA_ARGS__); \
335 _res; \
336})
337#define spa_loop_utils_method_s(o,method,version,...) \
338({ \
339 struct spa_source *_res = NULL; \
340 struct spa_loop_utils *_o = o; \
341 spa_interface_call_res(&_o->iface, \
342 struct spa_loop_utils_methods, _res, \
343 method, version, ##__VA_ARGS__); \
344 _res; \
345})
346
347
348#define spa_loop_utils_add_io(l,...) spa_loop_utils_method_s(l,add_io,0,__VA_ARGS__)
349#define spa_loop_utils_update_io(l,...) spa_loop_utils_method_r(l,update_io,0,__VA_ARGS__)
350#define spa_loop_utils_add_idle(l,...) spa_loop_utils_method_s(l,add_idle,0,__VA_ARGS__)
351#define spa_loop_utils_enable_idle(l,...) spa_loop_utils_method_r(l,enable_idle,0,__VA_ARGS__)
352#define spa_loop_utils_add_event(l,...) spa_loop_utils_method_s(l,add_event,0,__VA_ARGS__)
353#define spa_loop_utils_signal_event(l,...) spa_loop_utils_method_r(l,signal_event,0,__VA_ARGS__)
354#define spa_loop_utils_add_timer(l,...) spa_loop_utils_method_s(l,add_timer,0,__VA_ARGS__)
355#define spa_loop_utils_update_timer(l,...) spa_loop_utils_method_r(l,update_timer,0,__VA_ARGS__)
356#define spa_loop_utils_add_signal(l,...) spa_loop_utils_method_s(l,add_signal,0,__VA_ARGS__)
357#define spa_loop_utils_destroy_source(l,...) spa_loop_utils_method_v(l,destroy_source,0,__VA_ARGS__)
358
363#ifdef __cplusplus
364} /* extern "C" */
365#endif
366
367#endif /* SPA_LOOP_H */
spa/utils/defs.h
void(* spa_source_timer_func_t)(void *data, uint64_t expirations)
Definition loop.h:310
void(* spa_source_event_func_t)(void *data, uint64_t count)
Definition loop.h:309
void(* spa_source_signal_func_t)(void *data, int signal_number)
Definition loop.h:311
void(* spa_source_idle_func_t)(void *data)
Definition loop.h:308
void(* spa_source_func_t)(struct spa_source *source)
Definition 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 loop.h:66
void(* spa_source_io_func_t)(void *data, int fd, uint32_t mask)
Definition loop.h:307
spa/utils/hook.h
A hook, contains the structure with functions and the data passed to the functions.
Definition hook.h:350
Definition hook.h:138
Control hooks.
Definition loop.h:169
void(* before)(void *data)
Executed right before waiting for events.
Definition loop.h:175
uint32_t version
Definition loop.h:172
void(* after)(void *data)
Executed right after waiting for events.
Definition loop.h:178
Control an event loop.
Definition loop.h:200
int(* get_fd)(void *object)
Definition loop.h:207
int(* iterate)(void *object, int timeout)
Perform one iteration of the loop.
Definition loop.h:245
void(* enter)(void *object)
Enter a loop.
Definition loop.h:227
void(* add_hook)(void *object, struct spa_hook *hook, const struct spa_loop_control_hooks *hooks, void *data)
Add a hook.
Definition loop.h:215
int(* check)(void *object)
Check context of the loop.
Definition loop.h:255
void(* leave)(void *object)
Leave a loop.
Definition loop.h:234
uint32_t version
Definition loop.h:205
Definition loop.h:42
struct spa_interface iface
Definition loop.h:42
Register sources and work items to an event loop.
Definition loop.h:76
int(* add_source)(void *object, struct spa_source *source)
Add a source to the loop.
Definition loop.h:89
int(* remove_source)(void *object, struct spa_source *source)
Remove a source from the loop.
Definition loop.h:107
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 loop.h:133
int(* update_source)(void *object, struct spa_source *source)
Update the source io mask.
Definition loop.h:98
uint32_t version
Definition loop.h:81
Create sources for an event loop.
Definition loop.h:316
int(* update_io)(void *object, struct spa_source *source, uint32_t mask)
Definition loop.h:329
int(* enable_idle)(void *object, struct spa_source *source, bool enabled)
Definition loop.h:334
int(* signal_event)(void *object, struct spa_source *source)
Definition loop.h:338
int(* update_timer)(void *object, struct spa_source *source, struct timespec *value, struct timespec *interval, bool absolute)
Definition loop.h:342
void(* destroy_source)(void *object, struct spa_source *source)
destroy a source allocated with this interface.
Definition loop.h:354
uint32_t version
Definition loop.h:321
Definition loop.h:48
struct spa_interface iface
Definition loop.h:48
Definition loop.h:36
struct spa_interface iface
Definition loop.h:36
Definition loop.h:55
uint32_t rmask
Definition loop.h:61
void * data
Definition loop.h:58
void * priv
Definition loop.h:63
uint32_t mask
Definition loop.h:60
spa_source_func_t func
Definition loop.h:57
int fd
Definition loop.h:59
struct spa_loop * loop
Definition loop.h:56
spa/support/system.h