mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-10 13:30:05 -05:00
Move listeners to spa and rename to hooks
The listeners are generally useful in spa, move it there and rename to hooks. Implement loop hooks with it. Fix some cleanup issues in stream and remote
This commit is contained in:
parent
6b6b827a3b
commit
600055bd68
55 changed files with 428 additions and 383 deletions
93
spa/include/spa/hook.h
Normal file
93
spa/include/spa/hook.h
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
/* SPA
|
||||
* Copyright (C) 2017 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __SPA_HOOK_H__
|
||||
#define __SPA_HOOK_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <spa/list.h>
|
||||
|
||||
struct spa_hook_list {
|
||||
struct spa_list list;
|
||||
};
|
||||
|
||||
struct spa_hook {
|
||||
struct spa_list link;
|
||||
const void *funcs;
|
||||
void *data;
|
||||
};
|
||||
|
||||
static inline void spa_hook_list_init(struct spa_hook_list *list)
|
||||
{
|
||||
spa_list_init(&list->list);
|
||||
}
|
||||
|
||||
/** Add a hook \memberof spa_hook */
|
||||
static inline void spa_hook_list_append(struct spa_hook_list *list,
|
||||
struct spa_hook *hook,
|
||||
const void *funcs, void *data)
|
||||
{
|
||||
hook->funcs = funcs;
|
||||
hook->data = data;
|
||||
spa_list_append(&list->list, &hook->link);
|
||||
}
|
||||
|
||||
static inline void spa_hook_list_prepend(struct spa_hook_list *list,
|
||||
struct spa_hook *hook,
|
||||
const void *funcs, void *data)
|
||||
{
|
||||
hook->funcs = funcs;
|
||||
hook->data = data;
|
||||
spa_list_prepend(&list->list, &hook->link);
|
||||
}
|
||||
|
||||
/** Remove a listener \memberof spa_hook */
|
||||
static inline void spa_hook_remove(struct spa_hook *hook)
|
||||
{
|
||||
spa_list_remove(&hook->link);
|
||||
}
|
||||
|
||||
#define spa_hook_list_do_call(l,start,type,method,once,...) ({ \
|
||||
struct spa_hook_list *list = l; \
|
||||
struct spa_list *s = start ? (struct spa_list *)start : &list->list; \
|
||||
struct spa_hook *ci, *t; \
|
||||
spa_list_for_each_safe_next(ci, t, &list->list, s, link) { \
|
||||
const type *cb = ci->funcs; \
|
||||
if (cb->method) { \
|
||||
cb->method(ci->data, ## __VA_ARGS__); \
|
||||
if (once) \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
});
|
||||
|
||||
#define spa_hook_list_call(l,t,m,...) spa_hook_list_do_call(l,NULL,t,m,false,##__VA_ARGS__)
|
||||
#define spa_hook_list_call_once(l,t,m,...) spa_hook_list_do_call(l,NULL,t,m,true,##__VA_ARGS__)
|
||||
|
||||
#define spa_hook_list_call_start(l,s,t,m,...) spa_hook_list_do_call(l,s,t,m,false,##__VA_ARGS__)
|
||||
#define spa_hook_list_call_once_start(l,s,t,m,...) spa_hook_list_do_call(l,s,t,m,true,##__VA_ARGS__)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __SPA_HOOK_H__ */
|
||||
|
|
@ -67,6 +67,12 @@ static inline void spa_list_remove(struct spa_list *elem)
|
|||
#define spa_list_last(item, type, member) \
|
||||
SPA_CONTAINER_OF((head)->prev, type, member)
|
||||
|
||||
#define spa_list_append(list, item) \
|
||||
spa_list_insert((list)->prev, item);
|
||||
|
||||
#define spa_list_prepend(list, item) \
|
||||
spa_list_insert(list, item);
|
||||
|
||||
#define spa_list_for_each_next(pos, head, curr, member) \
|
||||
for (pos = SPA_CONTAINER_OF((curr)->next, __typeof__(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ struct spa_loop_utils;
|
|||
|
||||
#include <spa/defs.h>
|
||||
#include <spa/list.h>
|
||||
#include <spa/hook.h>
|
||||
|
||||
enum spa_io {
|
||||
SPA_IO_IN = (1 << 0),
|
||||
|
|
@ -77,11 +78,14 @@ struct spa_loop {
|
|||
#define SPA_VERSION_LOOP 0
|
||||
uint32_t version;
|
||||
|
||||
/** add a source to the loop */
|
||||
int (*add_source) (struct spa_loop *loop,
|
||||
struct spa_source *source);
|
||||
|
||||
/** update the source io mask */
|
||||
int (*update_source) (struct spa_source *source);
|
||||
|
||||
/** remove a source from the loop */
|
||||
void (*remove_source) (struct spa_source *source);
|
||||
|
||||
/** invoke a function in the context of this loop */
|
||||
|
|
@ -104,16 +108,12 @@ struct spa_loop {
|
|||
struct spa_loop_control_hooks {
|
||||
#define SPA_VERSION_LOOP_CONTROL_HOOKS 0
|
||||
uint32_t version;
|
||||
|
||||
struct spa_list link;
|
||||
|
||||
/** Executed right before waiting for events */
|
||||
void (*before) (const struct spa_loop_control_hooks *hooks);
|
||||
void (*before) (void *data);
|
||||
/** Executed right after waiting for events */
|
||||
void (*after) (const struct spa_loop_control_hooks *hooks);
|
||||
void (*after) (void *data);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* spa_loop_control:
|
||||
*
|
||||
|
|
@ -130,8 +130,10 @@ struct spa_loop_control {
|
|||
/** Add a hook
|
||||
* \param ctrl the control to change
|
||||
* \param hooks the hooks to add */
|
||||
void (*add_hooks) (struct spa_loop_control *ctrl,
|
||||
struct spa_loop_control_hooks *hooks);
|
||||
void (*add_hook) (struct spa_loop_control *ctrl,
|
||||
struct spa_hook *hook,
|
||||
const struct spa_loop_control_hooks *hooks,
|
||||
void *data);
|
||||
|
||||
void (*enter) (struct spa_loop_control *ctrl);
|
||||
void (*leave) (struct spa_loop_control *ctrl);
|
||||
|
|
@ -140,7 +142,7 @@ struct spa_loop_control {
|
|||
};
|
||||
|
||||
#define spa_loop_control_get_fd(l) (l)->get_fd(l)
|
||||
#define spa_loop_control_add_hooks(l,...) (l)->add_hooks((l),__VA_ARGS__)
|
||||
#define spa_loop_control_add_hook(l,...) (l)->add_hook((l),__VA_ARGS__)
|
||||
#define spa_loop_control_enter(l) (l)->enter(l)
|
||||
#define spa_loop_control_iterate(l,...) (l)->iterate((l),__VA_ARGS__)
|
||||
#define spa_loop_control_leave(l) (l)->leave(l)
|
||||
|
|
@ -198,6 +200,9 @@ struct spa_loop_utils {
|
|||
int signal_number,
|
||||
spa_source_signal_func_t func, void *data);
|
||||
|
||||
/** destroy a source allocated with this interface. This function
|
||||
* should only be called when the loop is not running or from the
|
||||
* context of the running loop */
|
||||
void (*destroy_source) (struct spa_source *source);
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue