[pulseaudio-commits] 6 commits - src/modules src/pulsecore

David Henningsson diwic at kemper.freedesktop.org
Fri Apr 10 00:27:07 PDT 2015


 src/modules/alsa/module-alsa-card.c           |   26 +------
 src/modules/module-card-restore.c             |   29 +-------
 src/modules/module-device-restore.c           |   43 ++----------
 src/modules/module-filter-apply.c             |   52 ++-------------
 src/modules/module-filter-heuristics.c        |   22 +-----
 src/modules/module-stream-restore.c           |   40 ++---------
 src/modules/module-suspend-on-idle.c          |   89 ++++----------------------
 src/modules/module-switch-on-connect.c        |   12 ---
 src/modules/module-switch-on-port-available.c |   44 ++----------
 src/pulsecore/module.c                        |   16 ++++
 src/pulsecore/module.h                        |    4 +
 11 files changed, 88 insertions(+), 289 deletions(-)

New commits:
commit 37a783473728aaa6bcec72e6cfb02767d3de722e
Author: David Henningsson <david.henningsson at canonical.com>
Date:   Fri Mar 27 11:20:16 2015 +0100

    module-switch-*: use pa_module_hook_connect
    
    Refactoring, no functional change.
    
    Signed-off-by: David Henningsson <david.henningsson at canonical.com>

diff --git a/src/modules/module-switch-on-connect.c b/src/modules/module-switch-on-connect.c
index 540afd4..c844add 100644
--- a/src/modules/module-switch-on-connect.c
+++ b/src/modules/module-switch-on-connect.c
@@ -49,9 +49,6 @@ static const char* const valid_modargs[] = {
 };
 
 struct userdata {
-    pa_hook_slot
-        *sink_put_slot,
-        *source_put_slot;
     bool only_from_unavailable;
 };
 
@@ -183,8 +180,8 @@ int pa__init(pa_module*m) {
     m->userdata = u = pa_xnew0(struct userdata, 1);
 
     /* A little bit later than module-rescue-streams... */
-    u->sink_put_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_PUT], PA_HOOK_LATE+30, (pa_hook_cb_t) sink_put_hook_callback, u);
-    u->source_put_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_PUT], PA_HOOK_LATE+20, (pa_hook_cb_t) source_put_hook_callback, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_PUT], PA_HOOK_LATE+30, (pa_hook_cb_t) sink_put_hook_callback, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_PUT], PA_HOOK_LATE+20, (pa_hook_cb_t) source_put_hook_callback, u);
 
     if (pa_modargs_get_value_boolean(ma, "only_from_unavailable", &u->only_from_unavailable) < 0) {
 	pa_log("Failed to get a boolean value for only_from_unavailable.");
@@ -211,10 +208,5 @@ void pa__done(pa_module*m) {
     if (!(u = m->userdata))
         return;
 
-    if (u->sink_put_slot)
-        pa_hook_slot_free(u->sink_put_slot);
-    if (u->source_put_slot)
-        pa_hook_slot_free(u->source_put_slot);
-
     pa_xfree(u);
 }
diff --git a/src/modules/module-switch-on-port-available.c b/src/modules/module-switch-on-port-available.c
index 5a6b401..eb8f2d7 100644
--- a/src/modules/module-switch-on-port-available.c
+++ b/src/modules/module-switch-on-port-available.c
@@ -28,12 +28,6 @@
 
 #include "module-switch-on-port-available-symdef.h"
 
-struct userdata {
-     pa_hook_slot *available_slot;
-     pa_hook_slot *sink_new_slot;
-     pa_hook_slot *source_new_slot;
-};
-
 static bool profile_good_for_output(pa_card_profile *profile) {
     pa_sink *sink;
     uint32_t idx;
@@ -246,7 +240,7 @@ static pa_device_port *new_sink_source(pa_hashmap *ports, const char *name) {
     return p;
 }
 
-static pa_hook_result_t sink_new_hook_callback(pa_core *c, pa_sink_new_data *new_data, struct userdata *u) {
+static pa_hook_result_t sink_new_hook_callback(pa_core *c, pa_sink_new_data *new_data, void *u) {
 
     pa_device_port *p = new_sink_source(new_data->ports, new_data->active_port);
 
@@ -257,7 +251,7 @@ static pa_hook_result_t sink_new_hook_callback(pa_core *c, pa_sink_new_data *new
     return PA_HOOK_OK;
 }
 
-static pa_hook_result_t source_new_hook_callback(pa_core *c, pa_source_new_data *new_data, struct userdata *u) {
+static pa_hook_result_t source_new_hook_callback(pa_core *c, pa_source_new_data *new_data, void *u) {
 
     pa_device_port *p = new_sink_source(new_data->ports, new_data->active_port);
 
@@ -269,39 +263,17 @@ static pa_hook_result_t source_new_hook_callback(pa_core *c, pa_source_new_data
 }
 
 int pa__init(pa_module*m) {
-    struct userdata *u;
-
     pa_assert(m);
 
-    m->userdata = u = pa_xnew(struct userdata, 1);
-
     /* Make sure we are after module-device-restore, so we can overwrite that suggestion if necessary */
-    u->sink_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_NEW],
-                                       PA_HOOK_NORMAL, (pa_hook_cb_t) sink_new_hook_callback, u);
-    u->source_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_NEW],
-                                         PA_HOOK_NORMAL, (pa_hook_cb_t) source_new_hook_callback, u);
-    u->available_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_PORT_AVAILABLE_CHANGED],
-                                        PA_HOOK_LATE, (pa_hook_cb_t) port_available_hook_callback, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_NEW],
+                           PA_HOOK_NORMAL, (pa_hook_cb_t) sink_new_hook_callback, NULL);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_NEW],
+                           PA_HOOK_NORMAL, (pa_hook_cb_t) source_new_hook_callback, NULL);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_PORT_AVAILABLE_CHANGED],
+                           PA_HOOK_LATE, (pa_hook_cb_t) port_available_hook_callback, NULL);
 
     handle_all_unavailable(m->core);
 
     return 0;
 }
-
-void pa__done(pa_module*m) {
-    struct userdata *u;
-
-    pa_assert(m);
-
-    if (!(u = m->userdata))
-        return;
-
-    if (u->available_slot)
-        pa_hook_slot_free(u->available_slot);
-    if (u->sink_new_slot)
-        pa_hook_slot_free(u->sink_new_slot);
-    if (u->source_new_slot)
-        pa_hook_slot_free(u->source_new_slot);
-
-    pa_xfree(u);
-}

commit 10d9d8af5f0e24f6fbdfcf088ec04eb3f6e5c589
Author: David Henningsson <david.henningsson at canonical.com>
Date:   Fri Mar 27 11:20:15 2015 +0100

    module-filter-*: use pa_module_hook_connect
    
    Refactoring, no functional change.
    
    Signed-off-by: David Henningsson <david.henningsson at canonical.com>

diff --git a/src/modules/module-filter-apply.c b/src/modules/module-filter-apply.c
index c7c7367..5a927a3 100644
--- a/src/modules/module-filter-apply.c
+++ b/src/modules/module-filter-apply.c
@@ -65,17 +65,6 @@ struct filter {
 struct userdata {
     pa_core *core;
     pa_hashmap *filters;
-    pa_hook_slot
-        *sink_input_put_slot,
-        *sink_input_move_finish_slot,
-        *sink_input_proplist_slot,
-        *sink_input_unlink_slot,
-        *sink_unlink_slot,
-        *source_output_put_slot,
-        *source_output_move_finish_slot,
-        *source_output_proplist_slot,
-        *source_output_unlink_slot,
-        *source_unlink_slot;
     bool autoclean;
     pa_time_event *housekeeping_time_event;
 };
@@ -681,16 +670,16 @@ int pa__init(pa_module *m) {
 
     u->filters = pa_hashmap_new(filter_hash, filter_compare);
 
-    u->sink_input_put_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_PUT], PA_HOOK_LATE, (pa_hook_cb_t) sink_input_put_cb, u);
-    u->sink_input_move_finish_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_MOVE_FINISH], PA_HOOK_LATE, (pa_hook_cb_t) sink_input_move_finish_cb, u);
-    u->sink_input_proplist_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_PROPLIST_CHANGED], PA_HOOK_LATE, (pa_hook_cb_t) sink_input_proplist_cb, u);
-    u->sink_input_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_UNLINK], PA_HOOK_LATE, (pa_hook_cb_t) sink_input_unlink_cb, u);
-    u->sink_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_UNLINK], PA_HOOK_LATE-1, (pa_hook_cb_t) sink_unlink_cb, u);
-    u->source_output_put_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_PUT], PA_HOOK_LATE, (pa_hook_cb_t) source_output_put_cb, u);
-    u->source_output_move_finish_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_MOVE_FINISH], PA_HOOK_LATE, (pa_hook_cb_t) source_output_move_finish_cb, u);
-    u->source_output_proplist_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_PROPLIST_CHANGED], PA_HOOK_LATE, (pa_hook_cb_t) source_output_proplist_cb, u);
-    u->source_output_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_UNLINK], PA_HOOK_LATE, (pa_hook_cb_t) source_output_unlink_cb, u);
-    u->source_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_UNLINK], PA_HOOK_LATE-1, (pa_hook_cb_t) source_unlink_cb, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_INPUT_PUT], PA_HOOK_LATE, (pa_hook_cb_t) sink_input_put_cb, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_INPUT_MOVE_FINISH], PA_HOOK_LATE, (pa_hook_cb_t) sink_input_move_finish_cb, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_INPUT_PROPLIST_CHANGED], PA_HOOK_LATE, (pa_hook_cb_t) sink_input_proplist_cb, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_INPUT_UNLINK], PA_HOOK_LATE, (pa_hook_cb_t) sink_input_unlink_cb, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_UNLINK], PA_HOOK_LATE-1, (pa_hook_cb_t) sink_unlink_cb, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_PUT], PA_HOOK_LATE, (pa_hook_cb_t) source_output_put_cb, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_MOVE_FINISH], PA_HOOK_LATE, (pa_hook_cb_t) source_output_move_finish_cb, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_PROPLIST_CHANGED], PA_HOOK_LATE, (pa_hook_cb_t) source_output_proplist_cb, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_UNLINK], PA_HOOK_LATE, (pa_hook_cb_t) source_output_unlink_cb, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_UNLINK], PA_HOOK_LATE-1, (pa_hook_cb_t) source_unlink_cb, u);
 
     pa_modargs_free(ma);
 
@@ -713,27 +702,6 @@ void pa__done(pa_module *m) {
     if (!(u = m->userdata))
         return;
 
-    if (u->sink_input_put_slot)
-        pa_hook_slot_free(u->sink_input_put_slot);
-    if (u->sink_input_move_finish_slot)
-        pa_hook_slot_free(u->sink_input_move_finish_slot);
-    if (u->sink_input_proplist_slot)
-        pa_hook_slot_free(u->sink_input_proplist_slot);
-    if (u->sink_input_unlink_slot)
-        pa_hook_slot_free(u->sink_input_unlink_slot);
-    if (u->sink_unlink_slot)
-        pa_hook_slot_free(u->sink_unlink_slot);
-    if (u->source_output_put_slot)
-        pa_hook_slot_free(u->source_output_put_slot);
-    if (u->source_output_move_finish_slot)
-        pa_hook_slot_free(u->source_output_move_finish_slot);
-    if (u->source_output_proplist_slot)
-        pa_hook_slot_free(u->source_output_proplist_slot);
-    if (u->source_output_unlink_slot)
-        pa_hook_slot_free(u->source_output_unlink_slot);
-    if (u->source_unlink_slot)
-        pa_hook_slot_free(u->source_unlink_slot);
-
     if (u->housekeeping_time_event)
         u->core->mainloop->time_free(u->housekeeping_time_event);
 
diff --git a/src/modules/module-filter-heuristics.c b/src/modules/module-filter-heuristics.c
index 1b1aae1..423e873 100644
--- a/src/modules/module-filter-heuristics.c
+++ b/src/modules/module-filter-heuristics.c
@@ -46,11 +46,6 @@ static const char* const valid_modargs[] = {
 
 struct userdata {
     pa_core *core;
-    pa_hook_slot
-        *sink_input_put_slot,
-        *sink_input_move_finish_slot,
-        *source_output_put_slot,
-        *source_output_move_finish_slot;
 };
 
 static pa_hook_result_t process(struct userdata *u, pa_object *o, bool is_sink_input) {
@@ -147,10 +142,10 @@ int pa__init(pa_module *m) {
 
     u->core = m->core;
 
-    u->sink_input_put_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_PUT], PA_HOOK_LATE-1, (pa_hook_cb_t) sink_input_put_cb, u);
-    u->sink_input_move_finish_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_MOVE_FINISH], PA_HOOK_LATE-1, (pa_hook_cb_t) sink_input_move_finish_cb, u);
-    u->source_output_put_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_PUT], PA_HOOK_LATE-1, (pa_hook_cb_t) source_output_put_cb, u);
-    u->source_output_move_finish_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_MOVE_FINISH], PA_HOOK_LATE-1, (pa_hook_cb_t) source_output_move_finish_cb, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_INPUT_PUT], PA_HOOK_LATE-1, (pa_hook_cb_t) sink_input_put_cb, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_INPUT_MOVE_FINISH], PA_HOOK_LATE-1, (pa_hook_cb_t) sink_input_move_finish_cb, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_PUT], PA_HOOK_LATE-1, (pa_hook_cb_t) source_output_put_cb, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_MOVE_FINISH], PA_HOOK_LATE-1, (pa_hook_cb_t) source_output_move_finish_cb, u);
 
     pa_modargs_free(ma);
 
@@ -174,15 +169,6 @@ void pa__done(pa_module *m) {
     if (!(u = m->userdata))
         return;
 
-    if (u->sink_input_put_slot)
-        pa_hook_slot_free(u->sink_input_put_slot);
-    if (u->sink_input_move_finish_slot)
-        pa_hook_slot_free(u->sink_input_move_finish_slot);
-    if (u->source_output_put_slot)
-        pa_hook_slot_free(u->source_output_put_slot);
-    if (u->source_output_move_finish_slot)
-        pa_hook_slot_free(u->source_output_move_finish_slot);
-
     pa_xfree(u);
 
 }

commit 6eae0d4bf47258f3095fde13ebe179dbdc4cbcda
Author: David Henningsson <david.henningsson at canonical.com>
Date:   Fri Mar 27 11:20:14 2015 +0100

    module-alsa-card: use pa_module_hook_connect
    
    Refactoring, no functional change.
    
    Signed-off-by: David Henningsson <david.henningsson at canonical.com>

diff --git a/src/modules/alsa/module-alsa-card.c b/src/modules/alsa/module-alsa-card.c
index a7fec04..382e40d 100644
--- a/src/modules/alsa/module-alsa-card.c
+++ b/src/modules/alsa/module-alsa-card.c
@@ -122,12 +122,6 @@ struct userdata {
     bool use_ucm;
     pa_alsa_ucm_config ucm;
 
-    /* hooks for modifier action */
-    pa_hook_slot
-        *sink_input_put_hook_slot,
-        *source_output_put_hook_slot,
-        *sink_input_unlink_hook_slot,
-        *source_output_unlink_hook_slot;
 };
 
 struct profile_data {
@@ -677,16 +671,16 @@ int pa__init(pa_module *m) {
 
         /* hook start of sink input/source output to enable modifiers */
         /* A little bit later than module-role-cork */
-        u->sink_input_put_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_PUT], PA_HOOK_LATE+10,
+        pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_INPUT_PUT], PA_HOOK_LATE+10,
                 (pa_hook_cb_t) sink_input_put_hook_callback, u);
-        u->source_output_put_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_PUT], PA_HOOK_LATE+10,
+        pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_PUT], PA_HOOK_LATE+10,
                 (pa_hook_cb_t) source_output_put_hook_callback, u);
 
         /* hook end of sink input/source output to disable modifiers */
         /* A little bit later than module-role-cork */
-        u->sink_input_unlink_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_UNLINK], PA_HOOK_LATE+10,
+        pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_INPUT_UNLINK], PA_HOOK_LATE+10,
                 (pa_hook_cb_t) sink_input_unlink_hook_callback, u);
-        u->source_output_unlink_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_UNLINK], PA_HOOK_LATE+10,
+        pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_UNLINK], PA_HOOK_LATE+10,
                 (pa_hook_cb_t) source_output_unlink_hook_callback, u);
     }
     else {
@@ -820,18 +814,6 @@ void pa__done(pa_module*m) {
     if (!(u = m->userdata))
         goto finish;
 
-    if (u->sink_input_put_hook_slot)
-        pa_hook_slot_free(u->sink_input_put_hook_slot);
-
-    if (u->sink_input_unlink_hook_slot)
-        pa_hook_slot_free(u->sink_input_unlink_hook_slot);
-
-    if (u->source_output_put_hook_slot)
-        pa_hook_slot_free(u->source_output_put_hook_slot);
-
-    if (u->source_output_unlink_hook_slot)
-        pa_hook_slot_free(u->source_output_unlink_hook_slot);
-
     if (u->mixer_fdl)
         pa_alsa_fdlist_free(u->mixer_fdl);
     if (u->mixer_handle)

commit a5ea14248739dda6b0bd75c957415cfff3068aec
Author: David Henningsson <david.henningsson at canonical.com>
Date:   Fri Mar 27 11:20:13 2015 +0100

    module-suspend-on-idle: use pa_module_hook_connect
    
    Refactoring, no functional change.
    
    Signed-off-by: David Henningsson <david.henningsson at canonical.com>

diff --git a/src/modules/module-suspend-on-idle.c b/src/modules/module-suspend-on-idle.c
index 0a27a70..f7620db 100644
--- a/src/modules/module-suspend-on-idle.c
+++ b/src/modules/module-suspend-on-idle.c
@@ -49,25 +49,6 @@ struct userdata {
     pa_core *core;
     pa_usec_t timeout;
     pa_hashmap *device_infos;
-    pa_hook_slot
-        *sink_new_slot,
-        *source_new_slot,
-        *sink_unlink_slot,
-        *source_unlink_slot,
-        *sink_state_changed_slot,
-        *source_state_changed_slot;
-
-    pa_hook_slot
-        *sink_input_new_slot,
-        *source_output_new_slot,
-        *sink_input_unlink_slot,
-        *source_output_unlink_slot,
-        *sink_input_move_start_slot,
-        *source_output_move_start_slot,
-        *sink_input_move_finish_slot,
-        *source_output_move_finish_slot,
-        *sink_input_state_changed_slot,
-        *source_output_state_changed_slot;
 };
 
 struct device_info {
@@ -464,23 +445,23 @@ int pa__init(pa_module*m) {
     PA_IDXSET_FOREACH(source, m->core->sources, idx)
         device_new_hook_cb(m->core, PA_OBJECT(source), u);
 
-    u->sink_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_PUT], PA_HOOK_NORMAL, (pa_hook_cb_t) device_new_hook_cb, u);
-    u->source_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_PUT], PA_HOOK_NORMAL, (pa_hook_cb_t) device_new_hook_cb, u);
-    u->sink_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_UNLINK_POST], PA_HOOK_NORMAL, (pa_hook_cb_t) device_unlink_hook_cb, u);
-    u->source_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_UNLINK_POST], PA_HOOK_NORMAL, (pa_hook_cb_t) device_unlink_hook_cb, u);
-    u->sink_state_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_STATE_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) device_state_changed_hook_cb, u);
-    u->source_state_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_STATE_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) device_state_changed_hook_cb, u);
-
-    u->sink_input_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_FIXATE], PA_HOOK_NORMAL, (pa_hook_cb_t) sink_input_fixate_hook_cb, u);
-    u->source_output_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_FIXATE], PA_HOOK_NORMAL, (pa_hook_cb_t) source_output_fixate_hook_cb, u);
-    u->sink_input_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_UNLINK_POST], PA_HOOK_NORMAL, (pa_hook_cb_t) sink_input_unlink_hook_cb, u);
-    u->source_output_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_UNLINK_POST], PA_HOOK_NORMAL, (pa_hook_cb_t) source_output_unlink_hook_cb, u);
-    u->sink_input_move_start_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_MOVE_START], PA_HOOK_NORMAL, (pa_hook_cb_t) sink_input_move_start_hook_cb, u);
-    u->source_output_move_start_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_MOVE_START], PA_HOOK_NORMAL, (pa_hook_cb_t) source_output_move_start_hook_cb, u);
-    u->sink_input_move_finish_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_MOVE_FINISH], PA_HOOK_NORMAL, (pa_hook_cb_t) sink_input_move_finish_hook_cb, u);
-    u->source_output_move_finish_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_MOVE_FINISH], PA_HOOK_NORMAL, (pa_hook_cb_t) source_output_move_finish_hook_cb, u);
-    u->sink_input_state_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_STATE_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) sink_input_state_changed_hook_cb, u);
-    u->source_output_state_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_STATE_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) source_output_state_changed_hook_cb, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_PUT], PA_HOOK_NORMAL, (pa_hook_cb_t) device_new_hook_cb, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_PUT], PA_HOOK_NORMAL, (pa_hook_cb_t) device_new_hook_cb, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_UNLINK_POST], PA_HOOK_NORMAL, (pa_hook_cb_t) device_unlink_hook_cb, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_UNLINK_POST], PA_HOOK_NORMAL, (pa_hook_cb_t) device_unlink_hook_cb, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_STATE_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) device_state_changed_hook_cb, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_STATE_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) device_state_changed_hook_cb, u);
+
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_INPUT_FIXATE], PA_HOOK_NORMAL, (pa_hook_cb_t) sink_input_fixate_hook_cb, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_FIXATE], PA_HOOK_NORMAL, (pa_hook_cb_t) source_output_fixate_hook_cb, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_INPUT_UNLINK_POST], PA_HOOK_NORMAL, (pa_hook_cb_t) sink_input_unlink_hook_cb, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_UNLINK_POST], PA_HOOK_NORMAL, (pa_hook_cb_t) source_output_unlink_hook_cb, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_INPUT_MOVE_START], PA_HOOK_NORMAL, (pa_hook_cb_t) sink_input_move_start_hook_cb, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_MOVE_START], PA_HOOK_NORMAL, (pa_hook_cb_t) source_output_move_start_hook_cb, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_INPUT_MOVE_FINISH], PA_HOOK_NORMAL, (pa_hook_cb_t) sink_input_move_finish_hook_cb, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_MOVE_FINISH], PA_HOOK_NORMAL, (pa_hook_cb_t) source_output_move_finish_hook_cb, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_INPUT_STATE_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) sink_input_state_changed_hook_cb, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_STATE_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) source_output_state_changed_hook_cb, u);
 
     pa_modargs_free(ma);
     return 0;
@@ -503,42 +484,6 @@ void pa__done(pa_module*m) {
 
     u = m->userdata;
 
-    if (u->sink_new_slot)
-        pa_hook_slot_free(u->sink_new_slot);
-    if (u->sink_unlink_slot)
-        pa_hook_slot_free(u->sink_unlink_slot);
-    if (u->sink_state_changed_slot)
-        pa_hook_slot_free(u->sink_state_changed_slot);
-
-    if (u->source_new_slot)
-        pa_hook_slot_free(u->source_new_slot);
-    if (u->source_unlink_slot)
-        pa_hook_slot_free(u->source_unlink_slot);
-    if (u->source_state_changed_slot)
-        pa_hook_slot_free(u->source_state_changed_slot);
-
-    if (u->sink_input_new_slot)
-        pa_hook_slot_free(u->sink_input_new_slot);
-    if (u->sink_input_unlink_slot)
-        pa_hook_slot_free(u->sink_input_unlink_slot);
-    if (u->sink_input_move_start_slot)
-        pa_hook_slot_free(u->sink_input_move_start_slot);
-    if (u->sink_input_move_finish_slot)
-        pa_hook_slot_free(u->sink_input_move_finish_slot);
-    if (u->sink_input_state_changed_slot)
-        pa_hook_slot_free(u->sink_input_state_changed_slot);
-
-    if (u->source_output_new_slot)
-        pa_hook_slot_free(u->source_output_new_slot);
-    if (u->source_output_unlink_slot)
-        pa_hook_slot_free(u->source_output_unlink_slot);
-    if (u->source_output_move_start_slot)
-        pa_hook_slot_free(u->source_output_move_start_slot);
-    if (u->source_output_move_finish_slot)
-        pa_hook_slot_free(u->source_output_move_finish_slot);
-    if (u->source_output_state_changed_slot)
-        pa_hook_slot_free(u->source_output_state_changed_slot);
-
     pa_hashmap_free(u->device_infos);
 
     pa_xfree(u);

commit 619def0c73df673911d8b5fcb39e1039096b7726
Author: David Henningsson <david.henningsson at canonical.com>
Date:   Fri Mar 27 11:20:12 2015 +0100

    module-*-restore: use pa_module_hook_connect
    
    Refactoring, no functional change.
    
    Signed-off-by: David Henningsson <david.henningsson at canonical.com>

diff --git a/src/modules/module-card-restore.c b/src/modules/module-card-restore.c
index f5577db..5c55cec 100644
--- a/src/modules/module-card-restore.c
+++ b/src/modules/module-card-restore.c
@@ -60,15 +60,8 @@ static const char* const valid_modargs[] = {
 struct userdata {
     pa_core *core;
     pa_module *module;
-    pa_hook_slot *card_new_hook_slot;
-    pa_hook_slot *card_put_hook_slot;
-    pa_hook_slot *card_profile_changed_hook_slot;
-    pa_hook_slot *card_profile_added_hook_slot;
-    pa_hook_slot *profile_available_changed_hook_slot;
-    pa_hook_slot *port_offset_hook_slot;
     pa_time_event *save_time_event;
     pa_database *database;
-    bool hooks_connected;
 };
 
 #define ENTRY_VERSION 2
@@ -536,14 +529,13 @@ int pa__init(pa_module*m) {
     u->core = m->core;
     u->module = m;
 
-    u->card_new_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CARD_NEW], PA_HOOK_EARLY, (pa_hook_cb_t) card_new_hook_callback, u);
-    u->card_put_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CARD_PUT], PA_HOOK_NORMAL, (pa_hook_cb_t) card_put_hook_callback, u);
-    u->card_profile_changed_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CARD_PROFILE_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) card_profile_changed_callback, u);
-    u->card_profile_added_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CARD_PROFILE_ADDED], PA_HOOK_NORMAL, (pa_hook_cb_t) card_profile_added_callback, u);
-    u->profile_available_changed_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CARD_PROFILE_AVAILABLE_CHANGED],
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_CARD_NEW], PA_HOOK_EARLY, (pa_hook_cb_t) card_new_hook_callback, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_CARD_PUT], PA_HOOK_NORMAL, (pa_hook_cb_t) card_put_hook_callback, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_CARD_PROFILE_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) card_profile_changed_callback, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_CARD_PROFILE_ADDED], PA_HOOK_NORMAL, (pa_hook_cb_t) card_profile_added_callback, u);
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_CARD_PROFILE_AVAILABLE_CHANGED],
                                                              PA_HOOK_NORMAL, profile_available_changed_callback, u);
-    u->port_offset_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_PORT_LATENCY_OFFSET_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) port_offset_change_callback, u);
-    u->hooks_connected = true;
+    pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_PORT_LATENCY_OFFSET_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) port_offset_change_callback, u);
 
     if (!(fname = pa_state_path("card-database", true)))
         goto fail;
@@ -577,15 +569,6 @@ void pa__done(pa_module*m) {
     if (!(u = m->userdata))
         return;
 
-    if (u->hooks_connected) {
-        pa_hook_slot_free(u->card_new_hook_slot);
-        pa_hook_slot_free(u->card_put_hook_slot);
-        pa_hook_slot_free(u->card_profile_changed_hook_slot);
-        pa_hook_slot_free(u->card_profile_added_hook_slot);
-        pa_hook_slot_free(u->profile_available_changed_hook_slot);
-        pa_hook_slot_free(u->port_offset_hook_slot);
-    }
-
     if (u->save_time_event)
         u->core->mainloop->time_free(u->save_time_event);
 
diff --git a/src/modules/module-device-restore.c b/src/modules/module-device-restore.c
index f515de7..8d7b34b 100644
--- a/src/modules/module-device-restore.c
+++ b/src/modules/module-device-restore.c
@@ -78,15 +78,6 @@ struct userdata {
     pa_core *core;
     pa_module *module;
     pa_subscription *subscription;
-    pa_hook_slot
-        *sink_new_hook_slot,
-        *sink_fixate_hook_slot,
-        *sink_port_hook_slot,
-        *sink_put_hook_slot,
-        *source_new_hook_slot,
-        *source_fixate_hook_slot,
-        *source_port_hook_slot,
-        *connection_unlink_hook_slot;
     pa_time_event *save_time_event;
     pa_database *database;
 
@@ -1243,25 +1234,25 @@ int pa__init(pa_module*m) {
     u->protocol = pa_native_protocol_get(m->core);
     pa_native_protocol_install_ext(u->protocol, m, extension_cb);
 
-    u->connection_unlink_hook_slot = pa_hook_connect(&pa_native_protocol_hooks(u->protocol)[PA_NATIVE_HOOK_CONNECTION_UNLINK], PA_HOOK_NORMAL, (pa_hook_cb_t) connection_unlink_hook_cb, u);
+    pa_module_hook_connect(m, &pa_native_protocol_hooks(u->protocol)[PA_NATIVE_HOOK_CONNECTION_UNLINK], PA_HOOK_NORMAL, (pa_hook_cb_t) connection_unlink_hook_cb, u);
 
     u->subscription = pa_subscription_new(m->core, PA_SUBSCRIPTION_MASK_SINK|PA_SUBSCRIPTION_MASK_SOURCE, subscribe_callback, u);
 
     if (restore_port) {
-        u->sink_new_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_NEW], PA_HOOK_EARLY, (pa_hook_cb_t) sink_new_hook_callback, u);
-        u->source_new_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_NEW], PA_HOOK_EARLY, (pa_hook_cb_t) source_new_hook_callback, u);
+        pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_NEW], PA_HOOK_EARLY, (pa_hook_cb_t) sink_new_hook_callback, u);
+        pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_NEW], PA_HOOK_EARLY, (pa_hook_cb_t) source_new_hook_callback, u);
     }
 
     if (restore_muted || restore_volume) {
-        u->sink_fixate_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_FIXATE], PA_HOOK_EARLY, (pa_hook_cb_t) sink_fixate_hook_callback, u);
-        u->source_fixate_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_FIXATE], PA_HOOK_EARLY, (pa_hook_cb_t) source_fixate_hook_callback, u);
+        pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_FIXATE], PA_HOOK_EARLY, (pa_hook_cb_t) sink_fixate_hook_callback, u);
+        pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_FIXATE], PA_HOOK_EARLY, (pa_hook_cb_t) source_fixate_hook_callback, u);
 
-        u->sink_port_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_PORT_CHANGED], PA_HOOK_EARLY, (pa_hook_cb_t) sink_port_hook_callback, u);
-        u->source_port_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_PORT_CHANGED], PA_HOOK_EARLY, (pa_hook_cb_t) source_port_hook_callback, u);
+        pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_PORT_CHANGED], PA_HOOK_EARLY, (pa_hook_cb_t) sink_port_hook_callback, u);
+        pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_PORT_CHANGED], PA_HOOK_EARLY, (pa_hook_cb_t) source_port_hook_callback, u);
     }
 
     if (restore_formats)
-        u->sink_put_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_PUT], PA_HOOK_EARLY, (pa_hook_cb_t) sink_put_hook_callback, u);
+        pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_PUT], PA_HOOK_EARLY, (pa_hook_cb_t) sink_put_hook_callback, u);
 
     if (!(fname = pa_state_path("device-volumes", true)))
         goto fail;
@@ -1304,24 +1295,6 @@ void pa__done(pa_module*m) {
     if (u->subscription)
         pa_subscription_free(u->subscription);
 
-    if (u->sink_fixate_hook_slot)
-        pa_hook_slot_free(u->sink_fixate_hook_slot);
-    if (u->source_fixate_hook_slot)
-        pa_hook_slot_free(u->source_fixate_hook_slot);
-    if (u->sink_new_hook_slot)
-        pa_hook_slot_free(u->sink_new_hook_slot);
-    if (u->source_new_hook_slot)
-        pa_hook_slot_free(u->source_new_hook_slot);
-    if (u->sink_port_hook_slot)
-        pa_hook_slot_free(u->sink_port_hook_slot);
-    if (u->source_port_hook_slot)
-        pa_hook_slot_free(u->source_port_hook_slot);
-    if (u->sink_put_hook_slot)
-        pa_hook_slot_free(u->sink_put_hook_slot);
-
-    if (u->connection_unlink_hook_slot)
-        pa_hook_slot_free(u->connection_unlink_hook_slot);
-
     if (u->save_time_event) {
         u->core->mainloop->time_free(u->save_time_event);
         pa_database_sync(u->database);
diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c
index 397b58f..ac51ff3 100644
--- a/src/modules/module-stream-restore.c
+++ b/src/modules/module-stream-restore.c
@@ -2397,31 +2397,31 @@ int pa__init(pa_module*m) {
     u->protocol = pa_native_protocol_get(m->core);
     pa_native_protocol_install_ext(u->protocol, m, extension_cb);
 
-    u->connection_unlink_hook_slot = pa_hook_connect(&pa_native_protocol_hooks(u->protocol)[PA_NATIVE_HOOK_CONNECTION_UNLINK], PA_HOOK_NORMAL, (pa_hook_cb_t) connection_unlink_hook_cb, u);
+    pa_module_hook_connect(m, &pa_native_protocol_hooks(u->protocol)[PA_NATIVE_HOOK_CONNECTION_UNLINK], PA_HOOK_NORMAL, (pa_hook_cb_t) connection_unlink_hook_cb, u);
 
     u->subscription = pa_subscription_new(m->core, PA_SUBSCRIPTION_MASK_SINK_INPUT|PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT, subscribe_callback, u);
 
     if (restore_device) {
         /* A little bit earlier than module-intended-roles ... */
-        u->sink_input_new_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_NEW], PA_HOOK_EARLY, (pa_hook_cb_t) sink_input_new_hook_callback, u);
-        u->source_output_new_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_NEW], PA_HOOK_EARLY, (pa_hook_cb_t) source_output_new_hook_callback, u);
+        pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_INPUT_NEW], PA_HOOK_EARLY, (pa_hook_cb_t) sink_input_new_hook_callback, u);
+        pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_NEW], PA_HOOK_EARLY, (pa_hook_cb_t) source_output_new_hook_callback, u);
     }
 
     if (restore_device && on_hotplug) {
         /* A little bit earlier than module-intended-roles ... */
-        u->sink_put_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_PUT], PA_HOOK_LATE, (pa_hook_cb_t) sink_put_hook_callback, u);
-        u->source_put_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_PUT], PA_HOOK_LATE, (pa_hook_cb_t) source_put_hook_callback, u);
+        pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_PUT], PA_HOOK_LATE, (pa_hook_cb_t) sink_put_hook_callback, u);
+        pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_PUT], PA_HOOK_LATE, (pa_hook_cb_t) source_put_hook_callback, u);
     }
 
     if (restore_device && on_rescue) {
         /* A little bit earlier than module-intended-roles, module-rescue-streams, ... */
-        u->sink_unlink_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_UNLINK], PA_HOOK_LATE, (pa_hook_cb_t) sink_unlink_hook_callback, u);
-        u->source_unlink_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_UNLINK], PA_HOOK_LATE, (pa_hook_cb_t) source_unlink_hook_callback, u);
+        pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_UNLINK], PA_HOOK_LATE, (pa_hook_cb_t) sink_unlink_hook_callback, u);
+        pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_UNLINK], PA_HOOK_LATE, (pa_hook_cb_t) source_unlink_hook_callback, u);
     }
 
     if (restore_volume || restore_muted) {
-        u->sink_input_fixate_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_FIXATE], PA_HOOK_EARLY, (pa_hook_cb_t) sink_input_fixate_hook_callback, u);
-        u->source_output_fixate_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_FIXATE], PA_HOOK_EARLY, (pa_hook_cb_t) source_output_fixate_hook_callback, u);
+        pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_INPUT_FIXATE], PA_HOOK_EARLY, (pa_hook_cb_t) sink_input_fixate_hook_callback, u);
+        pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_FIXATE], PA_HOOK_EARLY, (pa_hook_cb_t) source_output_fixate_hook_callback, u);
     }
 
     if (!(fname = pa_state_path("stream-volumes", true)))
@@ -2508,28 +2508,6 @@ void pa__done(pa_module*m) {
     if (u->subscription)
         pa_subscription_free(u->subscription);
 
-    if (u->sink_input_new_hook_slot)
-        pa_hook_slot_free(u->sink_input_new_hook_slot);
-    if (u->sink_input_fixate_hook_slot)
-        pa_hook_slot_free(u->sink_input_fixate_hook_slot);
-    if (u->source_output_new_hook_slot)
-        pa_hook_slot_free(u->source_output_new_hook_slot);
-    if (u->source_output_fixate_hook_slot)
-        pa_hook_slot_free(u->source_output_fixate_hook_slot);
-
-    if (u->sink_put_hook_slot)
-        pa_hook_slot_free(u->sink_put_hook_slot);
-    if (u->source_put_hook_slot)
-        pa_hook_slot_free(u->source_put_hook_slot);
-
-    if (u->sink_unlink_hook_slot)
-        pa_hook_slot_free(u->sink_unlink_hook_slot);
-    if (u->source_unlink_hook_slot)
-        pa_hook_slot_free(u->source_unlink_hook_slot);
-
-    if (u->connection_unlink_hook_slot)
-        pa_hook_slot_free(u->connection_unlink_hook_slot);
-
     if (u->save_time_event)
         u->core->mainloop->time_free(u->save_time_event);
 

commit 127e8a151933ceb45c79b5c8ac143dcea7fe031c
Author: David Henningsson <david.henningsson at canonical.com>
Date:   Fri Mar 27 11:20:11 2015 +0100

    module: Add hook dynarray
    
    This small helper will simplify code in many modules.
    The hooks added through pa_module_hook_connect will be freed just
    before pa__done is called (so trying to add hooks during pa__done
    will result in assertion failure).
    
    Signed-off-by: David Henningsson <david.henningsson at canonical.com>

diff --git a/src/pulsecore/module.c b/src/pulsecore/module.c
index 1081ad3..256d4de 100644
--- a/src/pulsecore/module.c
+++ b/src/pulsecore/module.c
@@ -100,6 +100,13 @@ bool pa_module_exists(const char *name) {
     return false;
 }
 
+void pa_module_hook_connect(pa_module *m, pa_hook *hook, pa_hook_priority_t prio, pa_hook_cb_t cb, void *data) {
+    pa_assert(m);
+    pa_assert(hook);
+    pa_assert(m->hooks);
+    pa_dynarray_append(m->hooks, pa_hook_connect(hook, prio, cb, data));
+}
+
 pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) {
     pa_module *m = NULL;
     bool (*load_once)(void);
@@ -117,6 +124,7 @@ pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) {
     m->argument = pa_xstrdup(argument);
     m->load_once = false;
     m->proplist = pa_proplist_new();
+    m->hooks = pa_dynarray_new((pa_free_cb_t) pa_hook_slot_free);
     m->index = PA_IDXSET_INVALID;
 
     if (!(m->dl = lt_dlopenext(name))) {
@@ -200,6 +208,9 @@ fail:
         if (m->index != PA_IDXSET_INVALID)
             pa_idxset_remove_by_index(c->modules, m->index);
 
+        if (m->hooks)
+            pa_dynarray_free(m->hooks);
+
         if (m->proplist)
             pa_proplist_free(m->proplist);
 
@@ -221,6 +232,11 @@ static void pa_module_free(pa_module *m) {
 
     pa_log_info("Unloading \"%s\" (index: #%u).", m->name, m->index);
 
+    if (m->hooks) {
+       pa_dynarray_free(m->hooks);
+       m->hooks = NULL;
+    }
+
     if (m->done)
         m->done(m);
 
diff --git a/src/pulsecore/module.h b/src/pulsecore/module.h
index 96a6315..3889156 100644
--- a/src/pulsecore/module.h
+++ b/src/pulsecore/module.h
@@ -26,6 +26,7 @@
 typedef struct pa_module pa_module;
 
 #include <pulse/proplist.h>
+#include <pulsecore/dynarray.h>
 
 #include <pulsecore/core.h>
 
@@ -46,6 +47,7 @@ struct pa_module {
     bool unload_requested:1;
 
     pa_proplist *proplist;
+    pa_dynarray *hooks;
 };
 
 bool pa_module_exists(const char *name);
@@ -64,6 +66,8 @@ int pa_module_get_n_used(pa_module*m);
 
 void pa_module_update_proplist(pa_module *m, pa_update_mode_t mode, pa_proplist *p);
 
+void pa_module_hook_connect(pa_module *m, pa_hook *hook, pa_hook_priority_t prio, pa_hook_cb_t cb, void *data);
+
 #define PA_MODULE_AUTHOR(s)                                     \
     const char *pa__get_author(void) { return s; }              \
     struct __stupid_useless_struct_to_allow_trailing_semicolon



More information about the pulseaudio-commits mailing list