dbusiface-device: Save one level of identation by returning early.
authorTanu Kaskinen <tanuk@iki.fi>
Mon, 17 Aug 2009 13:55:08 +0000 (16:55 +0300)
committerTanu Kaskinen <tanuk@iki.fi>
Mon, 17 Aug 2009 13:55:08 +0000 (16:55 +0300)
src/modules/dbus/iface-device.c

index 2e5940c..8dc0b2c 100644 (file)
@@ -1075,126 +1075,129 @@ static void handle_source_get_all(DBusConnection *conn, DBusMessage *msg, void *
 
 static void subscription_cb(pa_core *c, pa_subscription_event_type_t t, uint32_t idx, void *userdata) {
     pa_dbusiface_device *d = userdata;
+    DBusMessage *signal = NULL;
+    const pa_cvolume *new_volume = NULL;
+    pa_bool_t new_muted = FALSE;
+    pa_sink_state_t new_sink_state = 0;
+    pa_source_state_t new_source_state = 0;
+    pa_device_port *new_active_port = NULL;
+    pa_proplist *new_proplist = NULL;
+    unsigned i = 0;
 
     pa_assert(c);
     pa_assert(d);
 
-    if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_CHANGE) {
-        DBusMessage *signal = NULL;
-        const pa_cvolume *new_volume = NULL;
-        pa_bool_t new_muted = FALSE;
-        pa_sink_state_t new_sink_state = 0;
-        pa_source_state_t new_source_state = 0;
-        pa_device_port *new_active_port = NULL;
-        pa_proplist *new_proplist = NULL;
-        unsigned i = 0;
-
-        pa_assert(((d->type == DEVICE_TYPE_SINK)
-                    && ((t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) == PA_SUBSCRIPTION_EVENT_SINK))
-                  || ((d->type == DEVICE_TYPE_SOURCE)
-                       && ((t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) == PA_SUBSCRIPTION_EVENT_SOURCE)));
-
-        new_volume = (d->type == DEVICE_TYPE_SINK)
-                     ? pa_sink_get_volume(d->sink, FALSE, FALSE)
-                     : pa_source_get_volume(d->source, FALSE);
-
-        if (!pa_cvolume_equal(&d->volume, new_volume)) {
-            dbus_uint32_t volume[PA_CHANNELS_MAX];
-            dbus_uint32_t *volume_ptr = volume;
-
-            d->volume = *new_volume;
-
-            for (i = 0; i < d->volume.channels; ++i)
-                volume[i] = d->volume.values[i];
-
-            pa_assert_se(signal = dbus_message_new_signal(d->path,
-                                                          PA_DBUSIFACE_DEVICE_INTERFACE,
-                                                          signals[SIGNAL_VOLUME_UPDATED].name));
-            pa_assert_se(dbus_message_append_args(signal,
-                                                  DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &volume_ptr, d->volume.channels,
-                                                  DBUS_TYPE_INVALID));
-
-            pa_dbus_protocol_send_signal(d->dbus_protocol, signal);
-            dbus_message_unref(signal);
-            signal = NULL;
-        }
+    if ((d->type == DEVICE_TYPE_SINK && idx != d->sink->index) || (d->type == DEVICE_TYPE_SOURCE && idx != d->source->index))
+        return;
 
-        new_muted = (d->type == DEVICE_TYPE_SINK) ? pa_sink_get_mute(d->sink, FALSE) : pa_source_get_mute(d->source, FALSE);
+    if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) != PA_SUBSCRIPTION_EVENT_CHANGE)
+        return;
 
-        if (d->is_muted != new_muted) {
-            d->is_muted = new_muted;
+    pa_assert(((d->type == DEVICE_TYPE_SINK)
+                && ((t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) == PA_SUBSCRIPTION_EVENT_SINK))
+              || ((d->type == DEVICE_TYPE_SOURCE)
+                   && ((t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) == PA_SUBSCRIPTION_EVENT_SOURCE)));
 
-            pa_assert_se(signal = dbus_message_new_signal(d->path,
-                                                          PA_DBUSIFACE_DEVICE_INTERFACE,
-                                                          signals[SIGNAL_MUTE_UPDATED].name));
-            pa_assert_se(dbus_message_append_args(signal, DBUS_TYPE_BOOLEAN, &d->is_muted, DBUS_TYPE_INVALID));
+    new_volume = (d->type == DEVICE_TYPE_SINK)
+                 ? pa_sink_get_volume(d->sink, FALSE, FALSE)
+                 : pa_source_get_volume(d->source, FALSE);
 
-            pa_dbus_protocol_send_signal(d->dbus_protocol, signal);
-            dbus_message_unref(signal);
-            signal = NULL;
-        }
+    if (!pa_cvolume_equal(&d->volume, new_volume)) {
+        dbus_uint32_t volume[PA_CHANNELS_MAX];
+        dbus_uint32_t *volume_ptr = volume;
 
-        if (d->type == DEVICE_TYPE_SINK)
-            new_sink_state = pa_sink_get_state(d->sink);
-        else
-            new_source_state = pa_source_get_state(d->source);
+        d->volume = *new_volume;
 
-        if ((d->type == DEVICE_TYPE_SINK && d->sink_state != new_sink_state)
-            || (d->type == DEVICE_TYPE_SOURCE && d->source_state != new_source_state)) {
-            dbus_uint32_t state = 0;
+        for (i = 0; i < d->volume.channels; ++i)
+            volume[i] = d->volume.values[i];
 
-            if (d->type == DEVICE_TYPE_SINK)
-                d->sink_state = new_sink_state;
-            else
-                d->source_state = new_source_state;
+        pa_assert_se(signal = dbus_message_new_signal(d->path,
+                                                      PA_DBUSIFACE_DEVICE_INTERFACE,
+                                                      signals[SIGNAL_VOLUME_UPDATED].name));
+        pa_assert_se(dbus_message_append_args(signal,
+                                              DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &volume_ptr, d->volume.channels,
+                                              DBUS_TYPE_INVALID));
 
-            state = (d->type == DEVICE_TYPE_SINK) ? d->sink_state : d->source_state;
+        pa_dbus_protocol_send_signal(d->dbus_protocol, signal);
+        dbus_message_unref(signal);
+        signal = NULL;
+    }
 
-            pa_assert_se(signal = dbus_message_new_signal(d->path,
-                                                          PA_DBUSIFACE_DEVICE_INTERFACE,
-                                                          signals[SIGNAL_STATE_UPDATED].name));
-            pa_assert_se(dbus_message_append_args(signal, DBUS_TYPE_UINT32, &state, DBUS_TYPE_INVALID));
+    new_muted = (d->type == DEVICE_TYPE_SINK) ? pa_sink_get_mute(d->sink, FALSE) : pa_source_get_mute(d->source, FALSE);
 
-            pa_dbus_protocol_send_signal(d->dbus_protocol, signal);
-            dbus_message_unref(signal);
-            signal = NULL;
-        }
+    if (d->is_muted != new_muted) {
+        d->is_muted = new_muted;
 
-        new_active_port = (d->type == DEVICE_TYPE_SINK) ? d->sink->active_port : d->source->active_port;
+        pa_assert_se(signal = dbus_message_new_signal(d->path,
+                                                      PA_DBUSIFACE_DEVICE_INTERFACE,
+                                                      signals[SIGNAL_MUTE_UPDATED].name));
+        pa_assert_se(dbus_message_append_args(signal, DBUS_TYPE_BOOLEAN, &d->is_muted, DBUS_TYPE_INVALID));
 
-        if (d->active_port != new_active_port) {
-            const char *object_path = NULL;
+        pa_dbus_protocol_send_signal(d->dbus_protocol, signal);
+        dbus_message_unref(signal);
+        signal = NULL;
+    }
 
-            d->active_port = new_active_port;
-            object_path = pa_dbusiface_device_port_get_path(pa_hashmap_get(d->ports, d->active_port->name));
+    if (d->type == DEVICE_TYPE_SINK)
+        new_sink_state = pa_sink_get_state(d->sink);
+    else
+        new_source_state = pa_source_get_state(d->source);
 
-            pa_assert_se(signal = dbus_message_new_signal(d->path,
-                                                          PA_DBUSIFACE_DEVICE_INTERFACE,
-                                                          signals[SIGNAL_ACTIVE_PORT_UPDATED].name));
-            pa_assert_se(dbus_message_append_args(signal, DBUS_TYPE_OBJECT_PATH, &object_path, DBUS_TYPE_INVALID));
+    if ((d->type == DEVICE_TYPE_SINK && d->sink_state != new_sink_state)
+        || (d->type == DEVICE_TYPE_SOURCE && d->source_state != new_source_state)) {
+        dbus_uint32_t state = 0;
 
-            pa_dbus_protocol_send_signal(d->dbus_protocol, signal);
-            dbus_message_unref(signal);
-            signal = NULL;
-        }
+        if (d->type == DEVICE_TYPE_SINK)
+            d->sink_state = new_sink_state;
+        else
+            d->source_state = new_source_state;
 
-        new_proplist = (d->type == DEVICE_TYPE_SINK) ? d->sink->proplist : d->source->proplist;
+        state = (d->type == DEVICE_TYPE_SINK) ? d->sink_state : d->source_state;
 
-        if (!pa_proplist_equal(d->proplist, new_proplist)) {
-            DBusMessageIter msg_iter;
+        pa_assert_se(signal = dbus_message_new_signal(d->path,
+                                                      PA_DBUSIFACE_DEVICE_INTERFACE,
+                                                      signals[SIGNAL_STATE_UPDATED].name));
+        pa_assert_se(dbus_message_append_args(signal, DBUS_TYPE_UINT32, &state, DBUS_TYPE_INVALID));
 
-            pa_proplist_update(d->proplist, PA_UPDATE_SET, new_proplist);
+        pa_dbus_protocol_send_signal(d->dbus_protocol, signal);
+        dbus_message_unref(signal);
+        signal = NULL;
+    }
 
-            pa_assert_se(signal = dbus_message_new_signal(d->path,
-                                                          PA_DBUSIFACE_DEVICE_INTERFACE,
-                                                          signals[SIGNAL_PROPERTY_LIST_UPDATED].name));
-            dbus_message_iter_init_append(signal, &msg_iter);
-            pa_dbus_append_proplist(&msg_iter, d->proplist);
+    new_active_port = (d->type == DEVICE_TYPE_SINK) ? d->sink->active_port : d->source->active_port;
 
-            pa_dbus_protocol_send_signal(d->dbus_protocol, signal);
-            dbus_message_unref(signal);
-            signal = NULL;
-        }
+    if (d->active_port != new_active_port) {
+        const char *object_path = NULL;
+
+        d->active_port = new_active_port;
+        object_path = pa_dbusiface_device_port_get_path(pa_hashmap_get(d->ports, d->active_port->name));
+
+        pa_assert_se(signal = dbus_message_new_signal(d->path,
+                                                      PA_DBUSIFACE_DEVICE_INTERFACE,
+                                                      signals[SIGNAL_ACTIVE_PORT_UPDATED].name));
+        pa_assert_se(dbus_message_append_args(signal, DBUS_TYPE_OBJECT_PATH, &object_path, DBUS_TYPE_INVALID));
+
+        pa_dbus_protocol_send_signal(d->dbus_protocol, signal);
+        dbus_message_unref(signal);
+        signal = NULL;
+    }
+
+    new_proplist = (d->type == DEVICE_TYPE_SINK) ? d->sink->proplist : d->source->proplist;
+
+    if (!pa_proplist_equal(d->proplist, new_proplist)) {
+        DBusMessageIter msg_iter;
+
+        pa_proplist_update(d->proplist, PA_UPDATE_SET, new_proplist);
+
+        pa_assert_se(signal = dbus_message_new_signal(d->path,
+                                                      PA_DBUSIFACE_DEVICE_INTERFACE,
+                                                      signals[SIGNAL_PROPERTY_LIST_UPDATED].name));
+        dbus_message_iter_init_append(signal, &msg_iter);
+        pa_dbus_append_proplist(&msg_iter, d->proplist);
+
+        pa_dbus_protocol_send_signal(d->dbus_protocol, signal);
+        dbus_message_unref(signal);
+        signal = NULL;
     }
 }