[PATCH 4/5] Assume that the ports hashmap of cards is always non-NULL.

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

 



The hashmap is created in pa_card_new_data_init().
---
 src/modules/module-switch-on-port-available.c |    5 +---
 src/pulsecore/cli-text.c                      |    4 ++-
 src/pulsecore/protocol-native.c               |   37 ++++++++++++-------------
 3 files changed, 21 insertions(+), 25 deletions(-)

diff --git a/src/modules/module-switch-on-port-available.c b/src/modules/module-switch-on-port-available.c
index 4c3d4af..1da612d 100644
--- a/src/modules/module-switch-on-port-available.c
+++ b/src/modules/module-switch-on-port-available.c
@@ -142,7 +142,7 @@ static pa_hook_result_t port_available_hook_callback(pa_core *c, pa_device_port
     pa_log_debug("finding port %s", port->name);
 
     PA_IDXSET_FOREACH(card, c->cards, state)
-        if (card->ports && port == pa_hashmap_get(card->ports, port->name))
+        if (port == pa_hashmap_get(card->ports, port->name))
             break;
 
     if (!card) {
@@ -211,9 +211,6 @@ static void handle_all_unavailable(pa_core *core) {
         pa_device_port *port;
         void *state2;
 
-        if (!card->ports)
-            continue;
-
         PA_HASHMAP_FOREACH(port, card->ports, state2) {
             if (port->available == PA_PORT_AVAILABLE_NO)
                 port_available_hook_callback(core, port, NULL);
diff --git a/src/pulsecore/cli-text.c b/src/pulsecore/cli-text.c
index 78003ce..366bf42 100644
--- a/src/pulsecore/cli-text.c
+++ b/src/pulsecore/cli-text.c
@@ -120,7 +120,9 @@ static void append_port_list(pa_strbuf *s, pa_hashmap *ports)
     pa_device_port *p;
     void *state;
 
-    if (!ports)
+    pa_assert(ports);
+
+    if (pa_hashmap_isempty(ports))
         return;
 
     pa_strbuf_puts(s, "\tports:\n");
diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c
index bdd79aa..4c93484 100644
--- a/src/pulsecore/protocol-native.c
+++ b/src/pulsecore/protocol-native.c
@@ -3230,6 +3230,8 @@ static void client_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_c
 static void card_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_card *card) {
     void *state = NULL;
     pa_card_profile *p;
+    pa_device_port *port;
+    pa_proplist *proplist;
 
     pa_assert(t);
     pa_assert(card);
@@ -3255,31 +3257,26 @@ static void card_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_car
     if (c->version < 26)
         return;
 
-    if (card->ports) {
-        pa_device_port* port;
-        pa_proplist* proplist = pa_proplist_new(); /* For now - push an empty proplist */
-
-        pa_tagstruct_putu32(t, pa_hashmap_size(card->ports));
+    proplist = pa_proplist_new(); /* For now - push an empty proplist */
+    pa_tagstruct_putu32(t, pa_hashmap_size(card->ports));
 
-        PA_HASHMAP_FOREACH(port, card->ports, state) {
-            void *state2;
+    PA_HASHMAP_FOREACH(port, card->ports, state) {
+        void *state2;
 
-            pa_tagstruct_puts(t, port->name);
-            pa_tagstruct_puts(t, port->description);
-            pa_tagstruct_putu32(t, port->priority);
-            pa_tagstruct_putu32(t, port->available);
-            pa_tagstruct_putu8(t, /* FIXME: port->direction */ (port->is_input ? PA_DIRECTION_INPUT : 0) | (port->is_output ? PA_DIRECTION_OUTPUT : 0));
-            pa_tagstruct_put_proplist(t, proplist);
+        pa_tagstruct_puts(t, port->name);
+        pa_tagstruct_puts(t, port->description);
+        pa_tagstruct_putu32(t, port->priority);
+        pa_tagstruct_putu32(t, port->available);
+        pa_tagstruct_putu8(t, /* FIXME: port->direction */ (port->is_input ? PA_DIRECTION_INPUT : 0) | (port->is_output ? PA_DIRECTION_OUTPUT : 0));
+        pa_tagstruct_put_proplist(t, proplist);
 
-            pa_tagstruct_putu32(t, pa_hashmap_size(port->profiles));
+        pa_tagstruct_putu32(t, pa_hashmap_size(port->profiles));
 
-            PA_HASHMAP_FOREACH(p, port->profiles, state2)
-                pa_tagstruct_puts(t, p->name);
-        }
+        PA_HASHMAP_FOREACH(p, port->profiles, state2)
+            pa_tagstruct_puts(t, p->name);
+    }
 
-        pa_proplist_free(proplist);
-    } else
-        pa_tagstruct_putu32(t, 0);
+    pa_proplist_free(proplist);
 }
 
 static void module_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_module *module) {
-- 
1.7.10



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

  Powered by Linux