PipeWire  0.3.33
build-12683127/doc/spa/support/loop.h
Go to the documentation of this file.
1 /* Simple Plugin API
2  *
3  * Copyright © 2018 Wim Taymans
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24 
25 #ifndef SPA_LOOP_H
26 #define SPA_LOOP_H
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #include <spa/utils/defs.h>
33 #include <spa/utils/hook.h>
34 #include <spa/support/system.h>
35 
41 #define SPA_TYPE_INTERFACE_Loop SPA_TYPE_INFO_INTERFACE_BASE "Loop"
42 #define SPA_TYPE_INTERFACE_DataLoop SPA_TYPE_INFO_INTERFACE_BASE "DataLoop"
43 #define SPA_VERSION_LOOP 0
44 struct spa_loop { struct spa_interface iface; };
45 
46 #define SPA_TYPE_INTERFACE_LoopControl SPA_TYPE_INFO_INTERFACE_BASE "LoopControl"
47 #define SPA_VERSION_LOOP_CONTROL 0
49 
50 #define SPA_TYPE_INTERFACE_LoopUtils SPA_TYPE_INFO_INTERFACE_BASE "LoopUtils"
51 #define SPA_VERSION_LOOP_UTILS 0
52 struct spa_loop_utils { struct spa_interface iface; };
53 
54 struct spa_source;
55 
56 typedef void (*spa_source_func_t) (struct spa_source *source);
57 
58 struct spa_source {
59  struct spa_loop *loop;
61  void *data;
62  int fd;
63  uint32_t mask;
64  uint32_t rmask;
65 };
66 
67 typedef int (*spa_invoke_func_t) (struct spa_loop *loop,
68  bool async,
69  uint32_t seq,
70  const void *data,
71  size_t size,
72  void *user_data);
73 
78  /* the version of this structure. This can be used to expand this
79  * structure in the future */
80 #define SPA_VERSION_LOOP_METHODS 0
81  uint32_t version;
82 
84  int (*add_source) (void *object,
85  struct spa_source *source);
86 
88  int (*update_source) (void *object,
89  struct spa_source *source);
90 
92  int (*remove_source) (void *object,
93  struct spa_source *source);
94 
96  int (*invoke) (void *object,
98  uint32_t seq,
99  const void *data,
100  size_t size,
101  bool block,
102  void *user_data);
103 };
104 
105 #define spa_loop_method(o,method,version,...) \
106 ({ \
107  int _res = -ENOTSUP; \
108  struct spa_loop *_o = o; \
109  spa_interface_call_res(&_o->iface, \
110  struct spa_loop_methods, _res, \
111  method, version, ##__VA_ARGS__); \
112  _res; \
113 })
114 
115 #define spa_loop_add_source(l,...) spa_loop_method(l,add_source,0,##__VA_ARGS__)
116 #define spa_loop_update_source(l,...) spa_loop_method(l,update_source,0,##__VA_ARGS__)
117 #define spa_loop_remove_source(l,...) spa_loop_method(l,remove_source,0,##__VA_ARGS__)
118 #define spa_loop_invoke(l,...) spa_loop_method(l,invoke,0,##__VA_ARGS__)
119 
120 
125 #define SPA_VERSION_LOOP_CONTROL_HOOKS 0
126  uint32_t version;
129  void (*before) (void *data);
132  void (*after) (void *data);
133 };
134 
135 #define spa_loop_control_hook_before(l) \
136 ({ \
137  struct spa_hook_list *_l = l; \
138  struct spa_hook *_h; \
139  spa_list_for_each_reverse(_h, &_l->list, link) \
140  spa_callbacks_call(&_h->cb, struct spa_loop_control_hooks, before, 0); \
141 })
142 
143 #define spa_loop_control_hook_after(l) \
144 ({ \
145  struct spa_hook_list *_l = l; \
146  struct spa_hook *_h; \
147  spa_list_for_each(_h, &_l->list, link) \
148  spa_callbacks_call(&_h->cb, struct spa_loop_control_hooks, after, 0); \
149 })
150 
155  /* the version of this structure. This can be used to expand this
156  * structure in the future */
157 #define SPA_VERSION_LOOP_CONTROL_METHODS 0
158  uint32_t version;
159 
160  int (*get_fd) (void *object);
161 
168  void (*add_hook) (void *object,
169  struct spa_hook *hook,
170  const struct spa_loop_control_hooks *hooks,
171  void *data);
172 
180  void (*enter) (void *object);
187  void (*leave) (void *object);
188 
198  int (*iterate) (void *object, int timeout);
199 };
200 
201 #define spa_loop_control_method_v(o,method,version,...) \
202 ({ \
203  struct spa_loop_control *_o = o; \
204  spa_interface_call(&_o->iface, \
205  struct spa_loop_control_methods, \
206  method, version, ##__VA_ARGS__); \
207 })
208 
209 #define spa_loop_control_method_r(o,method,version,...) \
210 ({ \
211  int _res = -ENOTSUP; \
212  struct spa_loop_control *_o = o; \
213  spa_interface_call_res(&_o->iface, \
214  struct spa_loop_control_methods, _res, \
215  method, version, ##__VA_ARGS__); \
216  _res; \
217 })
218 
219 #define spa_loop_control_get_fd(l) spa_loop_control_method_r(l,get_fd,0)
220 #define spa_loop_control_add_hook(l,...) spa_loop_control_method_v(l,add_hook,0,__VA_ARGS__)
221 #define spa_loop_control_enter(l) spa_loop_control_method_v(l,enter,0)
222 #define spa_loop_control_leave(l) spa_loop_control_method_v(l,leave,0)
223 #define spa_loop_control_iterate(l,...) spa_loop_control_method_r(l,iterate,0,__VA_ARGS__)
224 
225 typedef void (*spa_source_io_func_t) (void *data, int fd, uint32_t mask);
226 typedef void (*spa_source_idle_func_t) (void *data);
227 typedef void (*spa_source_event_func_t) (void *data, uint64_t count);
228 typedef void (*spa_source_timer_func_t) (void *data, uint64_t expirations);
229 typedef void (*spa_source_signal_func_t) (void *data, int signal_number);
230 
235  /* the version of this structure. This can be used to expand this
236  * structure in the future */
237 #define SPA_VERSION_LOOP_UTILS_METHODS 0
238  uint32_t version;
239 
240  struct spa_source *(*add_io) (void *object,
241  int fd,
242  uint32_t mask,
243  bool close,
245 
246  int (*update_io) (void *object, struct spa_source *source, uint32_t mask);
247 
248  struct spa_source *(*add_idle) (void *object,
249  bool enabled,
251  int (*enable_idle) (void *object, struct spa_source *source, bool enabled);
252 
253  struct spa_source *(*add_event) (void *object,
255  int (*signal_event) (void *object, struct spa_source *source);
256 
257  struct spa_source *(*add_timer) (void *object,
259  int (*update_timer) (void *object,
260  struct spa_source *source,
261  struct timespec *value,
262  struct timespec *interval,
263  bool absolute);
264  struct spa_source *(*add_signal) (void *object,
265  int signal_number,
267 
271  void (*destroy_source) (void *object, struct spa_source *source);
272 };
273 
274 #define spa_loop_utils_method_v(o,method,version,...) \
275 ({ \
276  struct spa_loop_utils *_o = o; \
277  spa_interface_call(&_o->iface, \
278  struct spa_loop_utils_methods, \
279  method, version, ##__VA_ARGS__); \
280 })
281 
282 #define spa_loop_utils_method_r(o,method,version,...) \
283 ({ \
284  int _res = -ENOTSUP; \
285  struct spa_loop_utils *_o = o; \
286  spa_interface_call_res(&_o->iface, \
287  struct spa_loop_utils_methods, _res, \
288  method, version, ##__VA_ARGS__); \
289  _res; \
290 })
291 #define spa_loop_utils_method_s(o,method,version,...) \
292 ({ \
293  struct spa_source *_res = NULL; \
294  struct spa_loop_utils *_o = o; \
295  spa_interface_call_res(&_o->iface, \
296  struct spa_loop_utils_methods, _res, \
297  method, version, ##__VA_ARGS__); \
298  _res; \
299 })
300 
301 
302 #define spa_loop_utils_add_io(l,...) spa_loop_utils_method_s(l,add_io,0,__VA_ARGS__)
303 #define spa_loop_utils_update_io(l,...) spa_loop_utils_method_r(l,update_io,0,__VA_ARGS__)
304 #define spa_loop_utils_add_idle(l,...) spa_loop_utils_method_s(l,add_idle,0,__VA_ARGS__)
305 #define spa_loop_utils_enable_idle(l,...) spa_loop_utils_method_r(l,enable_idle,0,__VA_ARGS__)
306 #define spa_loop_utils_add_event(l,...) spa_loop_utils_method_s(l,add_event,0,__VA_ARGS__)
307 #define spa_loop_utils_signal_event(l,...) spa_loop_utils_method_r(l,signal_event,0,__VA_ARGS__)
308 #define spa_loop_utils_add_timer(l,...) spa_loop_utils_method_s(l,add_timer,0,__VA_ARGS__)
309 #define spa_loop_utils_update_timer(l,...) spa_loop_utils_method_r(l,update_timer,0,__VA_ARGS__)
310 #define spa_loop_utils_add_signal(l,...) spa_loop_utils_method_s(l,add_signal,0,__VA_ARGS__)
311 #define spa_loop_utils_destroy_source(l,...) spa_loop_utils_method_v(l,destroy_source,0,__VA_ARGS__)
312 
317 #ifdef __cplusplus
318 } /* extern "C" */
319 #endif
320 
321 #endif /* SPA_LOOP_H */
spa_loop_methods::version
uint32_t version
Definition: build-12683127/doc/spa/support/loop.h:81
spa_source::mask
uint32_t mask
Definition: build-12683127/doc/spa/support/loop.h:63
spa_loop_utils_methods::enable_idle
int(* enable_idle)(void *object, struct spa_source *source, bool enabled)
Definition: build-12683127/doc/spa/support/loop.h:251
spa_interface
Definition: hook.h:146
spa_source_idle_func_t
void(* spa_source_idle_func_t)(void *data)
Definition: build-12683127/doc/spa/support/loop.h:226
spa_invoke_func_t
int(* spa_invoke_func_t)(struct spa_loop *loop, bool async, uint32_t seq, const void *data, size_t size, void *user_data)
Definition: build-12683127/doc/spa/support/loop.h:67
spa_loop_control::iface
struct spa_interface iface
Definition: build-12683127/doc/spa/support/loop.h:48
spa_loop_utils_methods::signal_event
int(* signal_event)(void *object, struct spa_source *source)
Definition: build-12683127/doc/spa/support/loop.h:255
spa_loop_utils_methods::update_timer
int(* update_timer)(void *object, struct spa_source *source, struct timespec *value, struct timespec *interval, bool absolute)
Definition: build-12683127/doc/spa/support/loop.h:259
spa_source_signal_func_t
void(* spa_source_signal_func_t)(void *data, int signal_number)
Definition: build-12683127/doc/spa/support/loop.h:229
data
user data to add to an object
Definition: filter.c:75
spa_loop_methods::remove_source
int(* remove_source)(void *object, struct spa_source *source)
remove a source from the loop
Definition: build-12683127/doc/spa/support/loop.h:92
spa_loop_utils_methods
Create sources for an event loop.
Definition: build-12683127/doc/spa/support/loop.h:234
spa_source::fd
int fd
Definition: build-12683127/doc/spa/support/loop.h:62
spa_loop_utils::iface
struct spa_interface iface
Definition: build-12683127/doc/spa/support/loop.h:52
spa_loop_control_methods::iterate
int(* iterate)(void *object, int timeout)
Perform one iteration of the loop.
Definition: build-12683127/doc/spa/support/loop.h:198
spa_source::func
spa_source_func_t func
Definition: build-12683127/doc/spa/support/loop.h:60
spa_source
Definition: build-12683127/doc/spa/support/loop.h:58
spa_source_event_func_t
void(* spa_source_event_func_t)(void *data, uint64_t count)
Definition: build-12683127/doc/spa/support/loop.h:227
spa_loop
Definition: build-12683127/doc/spa/support/loop.h:44
spa_loop_methods::add_source
int(* add_source)(void *object, struct spa_source *source)
add a source to the loop
Definition: build-12683127/doc/spa/support/loop.h:84
spa_source::data
void * data
Definition: build-12683127/doc/spa/support/loop.h:61
spa_hook
A hook, contains the structure with functions and the data passed to the functions.
Definition: hook.h:295
spa_loop_utils_methods::update_io
int(* update_io)(void *object, struct spa_source *source, uint32_t mask)
Definition: build-12683127/doc/spa/support/loop.h:246
spa_loop_control_hooks
Control hooks.
Definition: build-12683127/doc/spa/support/loop.h:124
spa_source::rmask
uint32_t rmask
Definition: build-12683127/doc/spa/support/loop.h:64
spa_loop_control
Definition: build-12683127/doc/spa/support/loop.h:48
spa_source_func_t
void(* spa_source_func_t)(struct spa_source *source)
Definition: build-12683127/doc/spa/support/loop.h:56
spa_source::loop
struct spa_loop * loop
Definition: build-12683127/doc/spa/support/loop.h:59
spa_loop_utils_methods::version
uint32_t version
Definition: build-12683127/doc/spa/support/loop.h:238
spa_loop_methods
Register sources and work items to an event loop.
Definition: build-12683127/doc/spa/support/loop.h:77
spa_source_io_func_t
void(* spa_source_io_func_t)(void *data, int fd, uint32_t mask)
Definition: build-12683127/doc/spa/support/loop.h:225
spa_loop_control_methods::enter
void(* enter)(void *object)
Enter a loop.
Definition: build-12683127/doc/spa/support/loop.h:180
system.h
spa_loop_control_methods::add_hook
void(* add_hook)(void *object, struct spa_hook *hook, const struct spa_loop_control_hooks *hooks, void *data)
Add a hook.
Definition: build-12683127/doc/spa/support/loop.h:168
spa_loop_methods::invoke
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: build-12683127/doc/spa/support/loop.h:96
spa_loop_control_methods
Control an event loop.
Definition: build-12683127/doc/spa/support/loop.h:154
spa_loop_methods::update_source
int(* update_source)(void *object, struct spa_source *source)
update the source io mask
Definition: build-12683127/doc/spa/support/loop.h:88
spa_loop_control_methods::version
uint32_t version
Definition: build-12683127/doc/spa/support/loop.h:158
spa_loop_control_methods::leave
void(* leave)(void *object)
Leave a loop.
Definition: build-12683127/doc/spa/support/loop.h:187
spa_loop_utils
Definition: build-12683127/doc/spa/support/loop.h:52
defs.h
spa_loop::iface
struct spa_interface iface
Definition: build-12683127/doc/spa/support/loop.h:44
spa_loop_control_hooks::after
void(* after)(void *data)
Executed right after waiting for events.
Definition: build-12683127/doc/spa/support/loop.h:132
spa_source_timer_func_t
void(* spa_source_timer_func_t)(void *data, uint64_t expirations)
Definition: build-12683127/doc/spa/support/loop.h:228
spa_loop_control_methods::get_fd
int(* get_fd)(void *object)
Definition: build-12683127/doc/spa/support/loop.h:160
hook.h
spa_loop_control_hooks::version
uint32_t version
Definition: build-12683127/doc/spa/support/loop.h:126
spa_loop_control_hooks::before
void(* before)(void *data)
Executed right before waiting for events.
Definition: build-12683127/doc/spa/support/loop.h:129
spa_loop_utils_methods::destroy_source
void(* destroy_source)(void *object, struct spa_source *source)
destroy a source allocated with this interface.
Definition: build-12683127/doc/spa/support/loop.h:271