mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-12 13:30:10 -05:00
pulse: Add pa_operation_set_state_callback() API
[The original commit message didn't have any explanation why this change is made, so I'll add that information here myself. --Tanu Kaskinen] This change is from the developers of a Haskell binding[1]. According to them, this change isn't strictly necessary, but their code gets significantly cleaner if they can register an operation callback that is called when the operation is cancelled due to the context getting disconnected. [1] https://github.com/favonia/pulse
This commit is contained in:
parent
b1e47df72c
commit
a255c29344
4 changed files with 30 additions and 0 deletions
|
|
@ -26,6 +26,7 @@
|
|||
#include <pulse/xmalloc.h>
|
||||
#include <pulsecore/macro.h>
|
||||
#include <pulsecore/flist.h>
|
||||
#include <pulse/fork-detect.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "operation.h"
|
||||
|
|
@ -91,6 +92,8 @@ static void operation_unlink(pa_operation *o) {
|
|||
o->stream = NULL;
|
||||
o->callback = NULL;
|
||||
o->userdata = NULL;
|
||||
o->state_callback = NULL;
|
||||
o->state_userdata = NULL;
|
||||
}
|
||||
|
||||
static void operation_set_state(pa_operation *o, pa_operation_state_t st) {
|
||||
|
|
@ -104,6 +107,9 @@ static void operation_set_state(pa_operation *o, pa_operation_state_t st) {
|
|||
|
||||
o->state = st;
|
||||
|
||||
if (o->state_callback)
|
||||
o->state_callback(o, o->state_userdata);
|
||||
|
||||
if ((o->state == PA_OPERATION_DONE) || (o->state == PA_OPERATION_CANCELED))
|
||||
operation_unlink(o);
|
||||
|
||||
|
|
@ -130,3 +136,17 @@ pa_operation_state_t pa_operation_get_state(pa_operation *o) {
|
|||
|
||||
return o->state;
|
||||
}
|
||||
|
||||
void pa_operation_set_state_callback(pa_operation *o, pa_operation_notify_cb_t cb, void *userdata) {
|
||||
pa_assert(o);
|
||||
pa_assert(PA_REFCNT_VALUE(o) >= 1);
|
||||
|
||||
if (pa_detect_fork())
|
||||
return;
|
||||
|
||||
if (o->state == PA_OPERATION_DONE || o->state == PA_OPERATION_CANCELED)
|
||||
return;
|
||||
|
||||
o->state_callback = cb;
|
||||
o->state_userdata = userdata;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue