mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-20 06:59:58 -05:00
Improve async handling
Don't use special callback in node to receive the results. Instead, use a generic result callback to receive the result. This makes things a bit more symetric and generic again because then you can choose how to match the result to the request and you have a generic way to handle both the sync and async case. We can then also remove the wait method. This also makes the remote interface and spa interface to objects very similar. Make a helper object to receive and dispatch results. Use this in the helper for enum_params. Make device use the same result callbacks.
This commit is contained in:
parent
98463b689b
commit
d2c18c7b1a
64 changed files with 1298 additions and 1141 deletions
|
|
@ -43,8 +43,6 @@ extern "C" {
|
|||
#define SPA_RESULT_ASYNC_SEQ(res) ((res) & SPA_ASYNC_SEQ_MASK)
|
||||
#define SPA_RESULT_RETURN_ASYNC(seq) (SPA_ASYNC_BIT | SPA_RESULT_ASYNC_SEQ(seq))
|
||||
|
||||
typedef int (*spa_result_func_t) (void *data, uint32_t count, const void *result);
|
||||
|
||||
struct spa_pending;
|
||||
|
||||
typedef int (*spa_pending_func_t) (struct spa_pending *pending, const void *result);
|
||||
|
|
@ -52,11 +50,49 @@ typedef int (*spa_pending_func_t) (struct spa_pending *pending, const void *resu
|
|||
struct spa_pending {
|
||||
struct spa_list link; /**< link used internally */
|
||||
int seq; /**< sequence number of pending result */
|
||||
int res; /**< result code of operation */
|
||||
int res; /**< result code of operation, valid in callback */
|
||||
spa_pending_func_t func; /**< callback function */
|
||||
void *data; /**< extra user data */
|
||||
};
|
||||
|
||||
static inline void spa_pending_remove(struct spa_pending *pending)
|
||||
{
|
||||
spa_list_remove(&pending->link);
|
||||
}
|
||||
|
||||
struct spa_pending_queue {
|
||||
struct spa_list pending;
|
||||
int seq;
|
||||
};
|
||||
|
||||
static inline void spa_pending_queue_init(struct spa_pending_queue *queue)
|
||||
{
|
||||
spa_list_init(&queue->pending);
|
||||
}
|
||||
|
||||
static inline void spa_pending_queue_add(struct spa_pending_queue *queue,
|
||||
int seq, struct spa_pending *pending, spa_pending_func_t func, void *data)
|
||||
{
|
||||
pending->seq = seq;
|
||||
pending->func = func;
|
||||
pending->data = data;
|
||||
spa_list_append(&queue->pending, &pending->link);
|
||||
}
|
||||
|
||||
static inline int spa_pending_queue_complete(struct spa_pending_queue *queue,
|
||||
int seq, int res, const void *result)
|
||||
{
|
||||
struct spa_pending *p, *t;
|
||||
spa_list_for_each_safe(p, t, &queue->pending, link) {
|
||||
if (p->seq == seq) {
|
||||
p->res = res;
|
||||
spa_pending_remove(p);
|
||||
p->func(p, result);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue