[PATCH 6/6] module-switch-*: use pa_module_hook_connect

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Refactoring, no functional change.

Signed-off-by: David Henningsson <david.henningsson at canonical.com>
---
 src/modules/module-switch-on-connect.c        | 12 ++------
 src/modules/module-switch-on-port-available.c | 44 +++++----------------------
 2 files changed, 10 insertions(+), 46 deletions(-)

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);
-}
-- 
1.9.1



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux