[pulseaudio-commits] r1235 - in /trunk/src: pulsecore/hook-list.c pulsecore/hook-list.h tests/hook-list-test.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Sun Aug 13 09:13:37 PDT 2006


Author: lennart
Date: Sun Aug 13 18:13:36 2006
New Revision: 1235

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=1235&root=pulseaudio&view=rev
Log:
rework hook list stuff once again: change the callback prototype to recieve three data pointers: one to the data for the hook, once for the slot and once for the call

Modified:
    trunk/src/pulsecore/hook-list.c
    trunk/src/pulsecore/hook-list.h
    trunk/src/tests/hook-list-test.c

Modified: trunk/src/pulsecore/hook-list.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/hook-list.c?rev=1235&root=pulseaudio&r1=1234&r2=1235&view=diff
==============================================================================
--- trunk/src/pulsecore/hook-list.c (original)
+++ trunk/src/pulsecore/hook-list.c Sun Aug 13 18:13:36 2006
@@ -21,12 +21,13 @@
 
 #include <pulsecore/hook-list.h>
 
-void pa_hook_init(pa_hook *hook) {
+void pa_hook_init(pa_hook *hook, void *data) {
     assert(hook);
 
     PA_LLIST_HEAD_INIT(pa_hook_slots, hook->slots);
     hook->last = NULL;
     hook->n_dead = hook->firing = 0;
+    hook->data = data;
 }
 
 static void slot_free(pa_hook *hook, pa_hook_slot *slot) {
@@ -48,10 +49,10 @@
     while (hook->slots)
         slot_free(hook, hook->slots);
     
-    pa_hook_init(hook);
+    pa_hook_init(hook, NULL);
 }
 
-pa_hook_slot* pa_hook_connect(pa_hook *hook, pa_hook_cb_t cb, void *userdata) {
+pa_hook_slot* pa_hook_connect(pa_hook *hook, pa_hook_cb_t cb, void *data) {
     pa_hook_slot *slot;
     
     assert(cb);
@@ -60,7 +61,7 @@
     slot->hook = hook;
     slot->dead = 0;
     slot->callback = cb;
-    slot->userdata = userdata;
+    slot->data = data;
     
     PA_LLIST_INSERT_AFTER(pa_hook_slot, hook->slots, hook->last, slot);
     hook->last = slot;
@@ -91,7 +92,7 @@
         if (slot->dead)
             continue;
         
-        if ((result = slot->callback(data, slot->userdata)) != PA_HOOK_OK)
+        if ((result = slot->callback(hook->data, data, slot->data)) != PA_HOOK_OK)
             break;
     }
     

Modified: trunk/src/pulsecore/hook-list.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/hook-list.h?rev=1235&root=pulseaudio&r1=1234&r2=1235&view=diff
==============================================================================
--- trunk/src/pulsecore/hook-list.h (original)
+++ trunk/src/pulsecore/hook-list.h Sun Aug 13 18:13:36 2006
@@ -35,13 +35,16 @@
     PA_HOOK_CANCEL = -1
 } pa_hook_result_t;
 
-typedef pa_hook_result_t (*pa_hook_cb_t)(void *data, void *userdata);
+typedef pa_hook_result_t (*pa_hook_cb_t)(
+        void *hook_data,
+        void *call_data,
+        void *slot_data);
 
 struct pa_hook_slot {
     int dead;
     pa_hook *hook;
     pa_hook_cb_t callback;
-    void *userdata;
+    void *data;
     PA_LLIST_FIELDS(pa_hook_slot);
 };
 
@@ -49,12 +52,14 @@
     PA_LLIST_HEAD(pa_hook_slot, slots);
     pa_hook_slot *last;
     int firing, n_dead;
+
+    void *data;
 };
 
-void pa_hook_init(pa_hook *hook);
+void pa_hook_init(pa_hook *hook, void *data);
 void pa_hook_free(pa_hook *hook);
 
-pa_hook_slot* pa_hook_connect(pa_hook *hook, pa_hook_cb_t, void *userdata);
+pa_hook_slot* pa_hook_connect(pa_hook *hook, pa_hook_cb_t, void *data);
 void pa_hook_slot_free(pa_hook_slot *slot);
 
 pa_hook_result_t pa_hook_fire(pa_hook *hook, void *data);

Modified: trunk/src/tests/hook-list-test.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/tests/hook-list-test.c?rev=1235&root=pulseaudio&r1=1234&r2=1235&view=diff
==============================================================================
--- trunk/src/tests/hook-list-test.c (original)
+++ trunk/src/tests/hook-list-test.c Sun Aug 13 18:13:36 2006
@@ -3,13 +3,13 @@
 #include <pulsecore/hook-list.h>
 #include <pulsecore/log.h>
 
-static pa_hook_result_t func1(const char*a, void *userdata) {
-    pa_log("#1 arg=%s userdata=%s", a, (char*) userdata);
+static pa_hook_result_t func1(const char*hook_data, const char*call_data, const char*slot_data) {
+    pa_log("(func1) hook=%s call=%s slot=%s", hook_data, call_data, slot_data);
     return PA_HOOK_OK;
 }
 
-static pa_hook_result_t func2(const char*a, void *userdata) {
-    pa_log("#2 arg=%s userdata=%s", a, (char*) userdata);
+static pa_hook_result_t func2(const char*hook_data, const char*call_data, const char*slot_data) {
+    pa_log("(func2) hook=%s call=%s slot=%s", hook_data, call_data, slot_data);
     return PA_HOOK_OK;
 }
 
@@ -17,15 +17,18 @@
     pa_hook hook;
     pa_hook_slot *slot;
 
-    pa_hook_init(&hook);
+    pa_hook_init(&hook, (void*) "hook");
 
-    pa_hook_connect(&hook, (pa_hook_cb_t) func1, (void*) "1-1");
-    slot = pa_hook_connect(&hook, (pa_hook_cb_t) func2, (void*) "2-1");
-    pa_hook_connect(&hook, (pa_hook_cb_t) func1, (void*) "1-2");
+    pa_hook_connect(&hook, (pa_hook_cb_t) func1, (void*) "slot1");
+    slot = pa_hook_connect(&hook, (pa_hook_cb_t) func2, (void*) "slot2");
+    pa_hook_connect(&hook, (pa_hook_cb_t) func1, (void*) "slot3");
     
-    pa_hook_fire(&hook, (void*) "arg2");
+    pa_hook_fire(&hook, (void*) "call1");
 
     pa_hook_slot_free(slot);
+
+    pa_hook_fire(&hook, (void*) "call2");
+
     pa_hook_free(&hook);
     
     return 0;




More information about the pulseaudio-commits mailing list