[pulseaudio-commits] src/map-file src/pulse

Tanu Kaskinen tanuk at kemper.freedesktop.org
Sat Jan 12 08:28:42 PST 2013


 src/map-file          |    1 +
 src/pulse/internal.h  |    2 ++
 src/pulse/operation.c |   20 ++++++++++++++++++++
 src/pulse/operation.h |    7 +++++++
 4 files changed, 30 insertions(+)

New commits:
commit a255c293446a0bdbfea3bb4b2abbedaf7ad023e9
Author: Paul Meng <mno2.csie at gmail.com>
Date:   Mon Jan 7 21:41:26 2013 +0800

    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

diff --git a/src/map-file b/src/map-file
index a20314c..91d61c2 100644
--- a/src/map-file
+++ b/src/map-file
@@ -220,6 +220,7 @@ pa_msleep;
 pa_operation_cancel;
 pa_operation_get_state;
 pa_operation_ref;
+pa_operation_set_state_callback;
 pa_operation_unref;
 pa_parse_sample_format;
 pa_path_get_filename;
diff --git a/src/pulse/internal.h b/src/pulse/internal.h
index c5bdcb1..833653d 100644
--- a/src/pulse/internal.h
+++ b/src/pulse/internal.h
@@ -234,6 +234,8 @@ struct pa_operation {
     pa_operation_state_t state;
     void *userdata;
     pa_operation_cb_t callback;
+    void *state_userdata;
+    pa_operation_notify_cb_t state_callback;
 
     void *private; /* some operations might need this */
 };
diff --git a/src/pulse/operation.c b/src/pulse/operation.c
index fe160a3..8fdbea7 100644
--- a/src/pulse/operation.c
+++ b/src/pulse/operation.c
@@ -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;
+}
diff --git a/src/pulse/operation.h b/src/pulse/operation.h
index b6b5691..4d5aa2b 100644
--- a/src/pulse/operation.h
+++ b/src/pulse/operation.h
@@ -34,6 +34,9 @@ PA_C_DECL_BEGIN
 /** An asynchronous operation object */
 typedef struct pa_operation pa_operation;
 
+/** A callback for operation state changes */
+typedef void (*pa_operation_notify_cb_t) (pa_operation *o, void *userdata);
+
 /** Increase the reference count by one */
 pa_operation *pa_operation_ref(pa_operation *o);
 
@@ -50,6 +53,10 @@ void pa_operation_cancel(pa_operation *o);
 /** Return the current status of the operation */
 pa_operation_state_t pa_operation_get_state(pa_operation *o);
 
+/** Set the callback function that is called when the operation
+ * is canceled due to disconnection. \since 4.0 */
+void pa_operation_set_state_callback(pa_operation *o, pa_operation_notify_cb_t cb, void *userdata);
+
 PA_C_DECL_END
 
 #endif



More information about the pulseaudio-commits mailing list