Loading...
Searching...
No Matches
loop.h
Go to the documentation of this file.
/* Simple Plugin API */
/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
/* SPDX-License-Identifier: MIT */
#ifndef SPA_LOOP_H
#define SPA_LOOP_H
#ifdef __cplusplus
extern "C" {
#endif
#include <spa/utils/defs.h>
#include <spa/utils/hook.h>
#include <spa/support/system.h>
#define SPA_TYPE_INTERFACE_Loop SPA_TYPE_INFO_INTERFACE_BASE "Loop"
#define SPA_TYPE_INTERFACE_DataLoop SPA_TYPE_INFO_INTERFACE_BASE "DataLoop"
#define SPA_VERSION_LOOP 0
struct spa_loop { struct spa_interface iface; };
#define SPA_TYPE_INTERFACE_LoopControl SPA_TYPE_INFO_INTERFACE_BASE "LoopControl"
#define SPA_VERSION_LOOP_CONTROL 1
struct spa_loop_control { struct spa_interface iface; };
#define SPA_TYPE_INTERFACE_LoopUtils SPA_TYPE_INFO_INTERFACE_BASE "LoopUtils"
#define SPA_VERSION_LOOP_UTILS 0
struct spa_loop_utils { struct spa_interface iface; };
struct spa_source;
typedef void (*spa_source_func_t) (struct spa_source *source);
struct spa_source {
struct spa_loop *loop;
spa_source_func_t func;
void *data;
int fd;
uint32_t mask;
uint32_t rmask;
/* private data for the loop implementer */
void *priv;
};
typedef int (*spa_invoke_func_t) (struct spa_loop *loop,
bool async,
uint32_t seq,
const void *data,
size_t size,
void *user_data);
struct spa_loop_methods {
/* the version of this structure. This can be used to expand this
* structure in the future */
#define SPA_VERSION_LOOP_METHODS 0
uint32_t version;
int (*add_source) (void *object,
struct spa_source *source);
int (*update_source) (void *object,
struct spa_source *source);
int (*remove_source) (void *object,
struct spa_source *source);
int (*invoke) (void *object,
spa_invoke_func_t func,
uint32_t seq,
const void *data,
size_t size,
bool block,
void *user_data);
};
#define spa_loop_method(o,method,version,...) \
({ \
int _res = -ENOTSUP; \
struct spa_loop *_o = o; \
spa_interface_call_res(&_o->iface, \
struct spa_loop_methods, _res, \
method, version, ##__VA_ARGS__); \
_res; \
})
#define spa_loop_add_source(l,...) spa_loop_method(l,add_source,0,##__VA_ARGS__)
#define spa_loop_update_source(l,...) spa_loop_method(l,update_source,0,##__VA_ARGS__)
#define spa_loop_remove_source(l,...) spa_loop_method(l,remove_source,0,##__VA_ARGS__)
#define spa_loop_invoke(l,...) spa_loop_method(l,invoke,0,##__VA_ARGS__)
struct spa_loop_control_hooks {
#define SPA_VERSION_LOOP_CONTROL_HOOKS 0
uint32_t version;
void (*before) (void *data);
void (*after) (void *data);
};
#define spa_loop_control_hook_before(l) \
({ \
struct spa_hook_list *_l = l; \
struct spa_hook *_h; \
spa_list_for_each_reverse(_h, &_l->list, link) \
spa_callbacks_call_fast(&_h->cb, struct spa_loop_control_hooks, before, 0); \
})
#define spa_loop_control_hook_after(l) \
({ \
struct spa_hook_list *_l = l; \
struct spa_hook *_h; \
spa_list_for_each(_h, &_l->list, link) \
spa_callbacks_call_fast(&_h->cb, struct spa_loop_control_hooks, after, 0); \
})
struct spa_loop_control_methods {
/* the version of this structure. This can be used to expand this
* structure in the future */
#define SPA_VERSION_LOOP_CONTROL_METHODS 1
uint32_t version;
int (*get_fd) (void *object);
void (*add_hook) (void *object,
struct spa_hook *hook,
const struct spa_loop_control_hooks *hooks,
void *data);
void (*enter) (void *object);
void (*leave) (void *object);
int (*iterate) (void *object, int timeout);
int (*check) (void *object);
};
#define spa_loop_control_method_v(o,method,version,...) \
({ \
struct spa_loop_control *_o = o; \
spa_interface_call(&_o->iface, \
struct spa_loop_control_methods, \
method, version, ##__VA_ARGS__); \
})
#define spa_loop_control_method_r(o,method,version,...) \
({ \
int _res = -ENOTSUP; \
struct spa_loop_control *_o = o; \
spa_interface_call_res(&_o->iface, \
struct spa_loop_control_methods, _res, \
method, version, ##__VA_ARGS__); \
_res; \
})
#define spa_loop_control_method_fast_r(o,method,version,...) \
({ \
int _res; \
struct spa_loop_control *_o = o; \
spa_interface_call_fast_res(&_o->iface, \
struct spa_loop_control_methods, _res, \
method, version, ##__VA_ARGS__); \
_res; \
})
#define spa_loop_control_get_fd(l) spa_loop_control_method_r(l,get_fd,0)
#define spa_loop_control_add_hook(l,...) spa_loop_control_method_v(l,add_hook,0,__VA_ARGS__)
#define spa_loop_control_enter(l) spa_loop_control_method_v(l,enter,0)
#define spa_loop_control_leave(l) spa_loop_control_method_v(l,leave,0)
#define spa_loop_control_iterate(l,...) spa_loop_control_method_r(l,iterate,0,__VA_ARGS__)
#define spa_loop_control_check(l) spa_loop_control_method_r(l,check,1)
#define spa_loop_control_iterate_fast(l,...) spa_loop_control_method_fast_r(l,iterate,0,__VA_ARGS__)
typedef void (*spa_source_io_func_t) (void *data, int fd, uint32_t mask);
typedef void (*spa_source_idle_func_t) (void *data);
typedef void (*spa_source_event_func_t) (void *data, uint64_t count);
typedef void (*spa_source_timer_func_t) (void *data, uint64_t expirations);
typedef void (*spa_source_signal_func_t) (void *data, int signal_number);
struct spa_loop_utils_methods {
/* the version of this structure. This can be used to expand this
* structure in the future */
#define SPA_VERSION_LOOP_UTILS_METHODS 0
uint32_t version;
struct spa_source *(*add_io) (void *object,
int fd,
uint32_t mask,
bool close,
spa_source_io_func_t func, void *data);
int (*update_io) (void *object, struct spa_source *source, uint32_t mask);
struct spa_source *(*add_idle) (void *object,
bool enabled,
spa_source_idle_func_t func, void *data);
int (*enable_idle) (void *object, struct spa_source *source, bool enabled);
struct spa_source *(*add_event) (void *object,
spa_source_event_func_t func, void *data);
int (*signal_event) (void *object, struct spa_source *source);
struct spa_source *(*add_timer) (void *object,
spa_source_timer_func_t func, void *data);
int (*update_timer) (void *object,
struct spa_source *source,
struct timespec *value,
struct timespec *interval,
bool absolute);
struct spa_source *(*add_signal) (void *object,
int signal_number,
spa_source_signal_func_t func, void *data);
void (*destroy_source) (void *object, struct spa_source *source);
};
#define spa_loop_utils_method_v(o,method,version,...) \
({ \
struct spa_loop_utils *_o = o; \
spa_interface_call(&_o->iface, \
struct spa_loop_utils_methods, \
method, version, ##__VA_ARGS__); \
})
#define spa_loop_utils_method_r(o,method,version,...) \
({ \
int _res = -ENOTSUP; \
struct spa_loop_utils *_o = o; \
spa_interface_call_res(&_o->iface, \
struct spa_loop_utils_methods, _res, \
method, version, ##__VA_ARGS__); \
_res; \
})
#define spa_loop_utils_method_s(o,method,version,...) \
({ \
struct spa_source *_res = NULL; \
struct spa_loop_utils *_o = o; \
spa_interface_call_res(&_o->iface, \
struct spa_loop_utils_methods, _res, \
method, version, ##__VA_ARGS__); \
_res; \
})
#define spa_loop_utils_add_io(l,...) spa_loop_utils_method_s(l,add_io,0,__VA_ARGS__)
#define spa_loop_utils_update_io(l,...) spa_loop_utils_method_r(l,update_io,0,__VA_ARGS__)
#define spa_loop_utils_add_idle(l,...) spa_loop_utils_method_s(l,add_idle,0,__VA_ARGS__)
#define spa_loop_utils_enable_idle(l,...) spa_loop_utils_method_r(l,enable_idle,0,__VA_ARGS__)
#define spa_loop_utils_add_event(l,...) spa_loop_utils_method_s(l,add_event,0,__VA_ARGS__)
#define spa_loop_utils_signal_event(l,...) spa_loop_utils_method_r(l,signal_event,0,__VA_ARGS__)
#define spa_loop_utils_add_timer(l,...) spa_loop_utils_method_s(l,add_timer,0,__VA_ARGS__)
#define spa_loop_utils_update_timer(l,...) spa_loop_utils_method_r(l,update_timer,0,__VA_ARGS__)
#define spa_loop_utils_add_signal(l,...) spa_loop_utils_method_s(l,add_signal,0,__VA_ARGS__)
#define spa_loop_utils_destroy_source(l,...) spa_loop_utils_method_v(l,destroy_source,0,__VA_ARGS__)
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* SPA_LOOP_H */
defs.h
spa/utils/defs.h
spa_source_timer_func_t
void(* spa_source_timer_func_t)(void *data, uint64_t expirations)
Definition loop.h:273
spa_source_event_func_t
void(* spa_source_event_func_t)(void *data, uint64_t count)
Definition loop.h:272
spa_source_signal_func_t
void(* spa_source_signal_func_t)(void *data, int signal_number)
Definition loop.h:274
spa_source_idle_func_t
void(* spa_source_idle_func_t)(void *data)
Definition loop.h:271
spa_source_func_t
void(* spa_source_func_t)(struct spa_source *source)
Definition loop.h:53
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 loop.h:66
spa_source_io_func_t
void(* spa_source_io_func_t)(void *data, int fd, uint32_t mask)
Definition loop.h:270
hook.h
spa/utils/hook.h
spa_hook
A hook, contains the structure with functions and the data passed to the functions.
Definition hook.h:350
spa_interface
Definition hook.h:138
spa_loop_control_hooks
Control hooks.
Definition loop.h:132
spa_loop_control_hooks::before
void(* before)(void *data)
Executed right before waiting for events.
Definition loop.h:138
spa_loop_control_hooks::version
uint32_t version
Definition loop.h:135
spa_loop_control_hooks::after
void(* after)(void *data)
Executed right after waiting for events.
Definition loop.h:141
spa_loop_control_methods
Control an event loop.
Definition loop.h:163
spa_loop_control_methods::get_fd
int(* get_fd)(void *object)
Definition loop.h:170
spa_loop_control_methods::iterate
int(* iterate)(void *object, int timeout)
Perform one iteration of the loop.
Definition loop.h:208
spa_loop_control_methods::enter
void(* enter)(void *object)
Enter a loop.
Definition loop.h:190
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 loop.h:178
spa_loop_control_methods::check
int(* check)(void *object)
Check context of the loop.
Definition loop.h:218
spa_loop_control_methods::leave
void(* leave)(void *object)
Leave a loop.
Definition loop.h:197
spa_loop_control_methods::version
uint32_t version
Definition loop.h:168
spa_loop_control
Definition loop.h:42
spa_loop_control::iface
struct spa_interface iface
Definition loop.h:42
spa_loop_methods
Register sources and work items to an event loop.
Definition loop.h:76
spa_loop_methods::add_source
int(* add_source)(void *object, struct spa_source *source)
add a source to the loop
Definition loop.h:84
spa_loop_methods::remove_source
int(* remove_source)(void *object, struct spa_source *source)
remove a source from the loop
Definition loop.h:92
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 loop.h:96
spa_loop_methods::update_source
int(* update_source)(void *object, struct spa_source *source)
update the source io mask
Definition loop.h:88
spa_loop_methods::version
uint32_t version
Definition loop.h:81
spa_loop_utils_methods
Create sources for an event loop.
Definition loop.h:279
spa_loop_utils_methods::update_io
int(* update_io)(void *object, struct spa_source *source, uint32_t mask)
Definition loop.h:292
spa_loop_utils_methods::enable_idle
int(* enable_idle)(void *object, struct spa_source *source, bool enabled)
Definition loop.h:297
spa_loop_utils_methods::signal_event
int(* signal_event)(void *object, struct spa_source *source)
Definition loop.h:301
spa_loop_utils_methods::update_timer
int(* update_timer)(void *object, struct spa_source *source, struct timespec *value, struct timespec *interval, bool absolute)
Definition loop.h:305
spa_loop_utils_methods::destroy_source
void(* destroy_source)(void *object, struct spa_source *source)
destroy a source allocated with this interface.
Definition loop.h:317
spa_loop_utils_methods::version
uint32_t version
Definition loop.h:284
spa_loop_utils
Definition loop.h:48
spa_loop_utils::iface
struct spa_interface iface
Definition loop.h:48
spa_loop
Definition loop.h:36
spa_loop::iface
struct spa_interface iface
Definition loop.h:36
spa_source
Definition loop.h:55
spa_source::rmask
uint32_t rmask
Definition loop.h:61
spa_source::data
void * data
Definition loop.h:58
spa_source::priv
void * priv
Definition loop.h:63
spa_source::mask
uint32_t mask
Definition loop.h:60
spa_source::func
spa_source_func_t func
Definition loop.h:57
spa_source::fd
int fd
Definition loop.h:59
spa_source::loop
struct spa_loop * loop
Definition loop.h:56
system.h
spa/support/system.h