From 9cbe39ab7c55bcad401de32716c5c8106f166291 Mon Sep 17 00:00:00 2001 From: Michal Ratajsky Date: Sat, 9 Jan 2016 20:25:33 +0100 Subject: Provide and use convenience functions to remove some copy-pasted code --- backends/pulse/pulse-backend.c | 61 +++++++----------------------------- backends/pulse/pulse-device-switch.c | 6 ++-- backends/pulse/pulse-device.c | 24 +++----------- backends/pulse/pulse-port-switch.c | 6 ++-- backends/pulse/pulse-sink.c | 24 +++----------- backends/pulse/pulse-source.c | 24 +++----------- 6 files changed, 28 insertions(+), 117 deletions(-) (limited to 'backends/pulse') diff --git a/backends/pulse/pulse-backend.c b/backends/pulse/pulse-backend.c index 88926be..71f6fa0 100644 --- a/backends/pulse/pulse-backend.c +++ b/backends/pulse/pulse-backend.c @@ -205,10 +205,6 @@ static void remove_source_output (PulseBackend PulseSource *source, guint index); -static void free_list_devices (PulseBackend *pulse); -static void free_list_streams (PulseBackend *pulse); -static void free_list_ext_streams (PulseBackend *pulse); - static gboolean compare_stream_names (gpointer key, gpointer value, gpointer user_data); @@ -469,9 +465,9 @@ pulse_backend_close (MateMixerBackend *backend) g_clear_object (&pulse->priv->connection); } - free_list_devices (pulse); - free_list_streams (pulse); - free_list_ext_streams (pulse); + _mate_mixer_clear_object_list (&pulse->priv->devices_list); + _mate_mixer_clear_object_list (&pulse->priv->streams_list); + _mate_mixer_clear_object_list (&pulse->priv->ext_streams_list); g_hash_table_remove_all (pulse->priv->devices); g_hash_table_remove_all (pulse->priv->sinks); @@ -776,7 +772,7 @@ on_connection_card_info (PulseConnection *connection, GUINT_TO_POINTER (info->index), device); - free_list_devices (pulse); + _mate_mixer_clear_object_list (&pulse->priv->devices_list); g_signal_emit_by_name (G_OBJECT (pulse), "device-added", MATE_MIXER_DEVICE (device)); @@ -798,7 +794,7 @@ on_connection_card_removed (PulseConnection *connection, g_object_ref (device); g_hash_table_remove (pulse->priv->devices, GUINT_TO_POINTER (index)); - free_list_devices (pulse); + _mate_mixer_clear_object_list (&pulse->priv->devices_list); g_signal_emit_by_name (G_OBJECT (pulse), "device-removed", MATE_MIXER_DEVICE (device)); @@ -826,7 +822,7 @@ on_connection_sink_info (PulseConnection *connection, GUINT_TO_POINTER (info->index), stream); - free_list_streams (pulse); + _mate_mixer_clear_object_list (&pulse->priv->streams_list); if (device != NULL) { pulse_device_add_stream (device, stream); @@ -859,7 +855,7 @@ on_connection_sink_removed (PulseConnection *connection, g_object_ref (stream); g_hash_table_remove (pulse->priv->sinks, GUINT_TO_POINTER (idx)); - free_list_streams (pulse); + _mate_mixer_clear_object_list (&pulse->priv->streams_list); device = pulse_stream_get_device (stream); if (device != NULL) { @@ -963,7 +959,7 @@ on_connection_source_info (PulseConnection *connection, GUINT_TO_POINTER (info->index), stream); - free_list_streams (pulse); + _mate_mixer_clear_object_list (&pulse->priv->streams_list); if (device != NULL) { pulse_device_add_stream (device, stream); @@ -994,9 +990,9 @@ on_connection_source_removed (PulseConnection *connection, return; g_object_ref (stream); - g_hash_table_remove (pulse->priv->sources, GUINT_TO_POINTER (idx)); - free_list_streams (pulse); + + _mate_mixer_clear_object_list (&pulse->priv->streams_list); device = pulse_stream_get_device (stream); if (device != NULL) { @@ -1105,7 +1101,7 @@ on_connection_ext_stream_info (PulseConnection *connection, g_strdup (info->name), ext); - free_list_ext_streams (pulse); + _mate_mixer_clear_object_list (&pulse->priv->ext_streams_list); g_signal_emit_by_name (G_OBJECT (pulse), "stored-control-added", @@ -1146,7 +1142,7 @@ on_connection_ext_stream_loaded (PulseConnection *connection, PulseBackend *puls g_object_ref (G_OBJECT (ext)); g_hash_table_iter_remove (&iter); - free_list_ext_streams (pulse); + _mate_mixer_clear_object_list (&pulse->priv->ext_streams_list); g_signal_emit_by_name (G_OBJECT (pulse), "stored-control-removed", MATE_MIXER_STORED_CONTROL (ext)); @@ -1228,39 +1224,6 @@ remove_source_output (PulseBackend *pulse, PulseSource *source, guint index) g_hash_table_remove (pulse->priv->source_output_map, GUINT_TO_POINTER (index)); } -static void -free_list_devices (PulseBackend *pulse) -{ - if (pulse->priv->devices_list == NULL) - return; - - g_list_free_full (pulse->priv->devices_list, g_object_unref); - - pulse->priv->devices_list = NULL; -} - -static void -free_list_streams (PulseBackend *pulse) -{ - if (pulse->priv->streams_list == NULL) - return; - - g_list_free_full (pulse->priv->streams_list, g_object_unref); - - pulse->priv->streams_list = NULL; -} - -static void -free_list_ext_streams (PulseBackend *pulse) -{ - if (pulse->priv->ext_streams_list == NULL) - return; - - g_list_free_full (pulse->priv->ext_streams_list, g_object_unref); - - pulse->priv->ext_streams_list = NULL; -} - static gboolean compare_stream_names (gpointer key, gpointer value, gpointer user_data) { diff --git a/backends/pulse/pulse-device-switch.c b/backends/pulse/pulse-device-switch.c index 4bd32ce..e8ba092 100644 --- a/backends/pulse/pulse-device-switch.c +++ b/backends/pulse/pulse-device-switch.c @@ -79,10 +79,8 @@ pulse_device_switch_dispose (GObject *object) swtch = PULSE_DEVICE_SWITCH (object); - if (swtch->priv->profiles != NULL) { - g_list_free_full (swtch->priv->profiles, g_object_unref); - swtch->priv->profiles = NULL; - } + _mate_mixer_clear_object_list (&swtch->priv->profiles); + G_OBJECT_CLASS (pulse_device_switch_parent_class)->dispose (object); } diff --git a/backends/pulse/pulse-device.c b/backends/pulse/pulse-device.c index c65f304..8735071 100644 --- a/backends/pulse/pulse-device.c +++ b/backends/pulse/pulse-device.c @@ -78,8 +78,6 @@ static const GList * pulse_device_list_switches (MateMixerDevice *mmd); static void pulse_device_load (PulseDevice *device, const pa_card_info *info); -static void free_list_streams (PulseDevice *device); - static void pulse_device_class_init (PulseDeviceClass *klass) { @@ -198,13 +196,10 @@ pulse_device_dispose (GObject *object) g_clear_object (&device->priv->connection); g_clear_object (&device->priv->pswitch); + g_clear_pointer (&device->priv->pswitch_list, g_list_free); - free_list_streams (device); + _mate_mixer_clear_object_list (&device->priv->streams_list); - if (device->priv->pswitch_list != NULL) { - g_list_free (device->priv->pswitch_list); - device->priv->pswitch_list = NULL; - } G_OBJECT_CLASS (pulse_device_parent_class)->dispose (object); } @@ -284,7 +279,7 @@ pulse_device_add_stream (PulseDevice *device, PulseStream *stream) g_strdup (name), g_object_ref (stream)); - free_list_streams (device); + _mate_mixer_clear_object_list (&device->priv->streams_list); g_signal_emit_by_name (G_OBJECT (device), "stream-added", @@ -304,7 +299,7 @@ pulse_device_remove_stream (PulseDevice *device, PulseStream *stream) g_object_ref (stream); g_hash_table_remove (device->priv->streams, name); - free_list_streams (device); + _mate_mixer_clear_object_list (&device->priv->streams_list); g_signal_emit_by_name (G_OBJECT (device), "stream-removed", MATE_MIXER_STREAM (stream)); @@ -428,14 +423,3 @@ pulse_device_load (PulseDevice *device, const pa_card_info *info) g_object_unref (profile); } } - -static void -free_list_streams (PulseDevice *device) -{ - if (device->priv->streams_list == NULL) - return; - - g_list_free_full (device->priv->streams_list, g_object_unref); - - device->priv->streams_list = NULL; -} diff --git a/backends/pulse/pulse-port-switch.c b/backends/pulse/pulse-port-switch.c index 1f4ce67..c024d03 100644 --- a/backends/pulse/pulse-port-switch.c +++ b/backends/pulse/pulse-port-switch.c @@ -79,10 +79,8 @@ pulse_port_switch_dispose (GObject *object) swtch = PULSE_PORT_SWITCH (object); - if (swtch->priv->ports != NULL) { - g_list_free_full (swtch->priv->ports, g_object_unref); - swtch->priv->ports = NULL; - } + _mate_mixer_clear_object_list (&swtch->priv->ports); + G_OBJECT_CLASS (pulse_port_switch_parent_class)->dispose (object); } diff --git a/backends/pulse/pulse-sink.c b/backends/pulse/pulse-sink.c index 9edf185..c698d02 100644 --- a/backends/pulse/pulse-sink.c +++ b/backends/pulse/pulse-sink.c @@ -54,8 +54,6 @@ G_DEFINE_TYPE (PulseSink, pulse_sink, PULSE_TYPE_STREAM); static const GList *pulse_sink_list_controls (MateMixerStream *mms); static const GList *pulse_sink_list_switches (MateMixerStream *mms); -static void free_list_controls (PulseSink *sink); - static void pulse_sink_class_init (PulseSinkClass *klass) { @@ -99,13 +97,10 @@ pulse_sink_dispose (GObject *object) g_clear_object (&sink->priv->control); g_clear_object (&sink->priv->pswitch); + g_clear_pointer (&sink->priv->pswitch_list, g_list_free); - free_list_controls (sink); + _mate_mixer_clear_object_list (&sink->priv->inputs_list); - if (sink->priv->pswitch_list != NULL) { - g_list_free (sink->priv->pswitch_list); - sink->priv->pswitch_list = NULL; - } G_OBJECT_CLASS (pulse_sink_parent_class)->dispose (object); } @@ -207,7 +202,7 @@ pulse_sink_add_input (PulseSink *sink, const pa_sink_input_info *info) GUINT_TO_POINTER (info->index), input); - free_list_controls (sink); + _mate_mixer_clear_object_list (&sink->priv->inputs_list); g_signal_emit_by_name (G_OBJECT (sink), "control-added", @@ -233,7 +228,7 @@ pulse_sink_remove_input (PulseSink *sink, guint32 index) g_object_ref (input); g_hash_table_remove (sink->priv->inputs, GUINT_TO_POINTER (index)); - free_list_controls (sink); + _mate_mixer_clear_object_list (&sink->priv->inputs_list); g_signal_emit_by_name (G_OBJECT (sink), "control-removed", MATE_MIXER_STREAM_CONTROL (input)); @@ -292,14 +287,3 @@ pulse_sink_list_switches (MateMixerStream *mms) return PULSE_SINK (mms)->priv->pswitch_list; } - -static void -free_list_controls (PulseSink *sink) -{ - if (sink->priv->inputs_list == NULL) - return; - - g_list_free_full (sink->priv->inputs_list, g_object_unref); - - sink->priv->inputs_list = NULL; -} diff --git a/backends/pulse/pulse-source.c b/backends/pulse/pulse-source.c index 6393743..1c4e01a 100644 --- a/backends/pulse/pulse-source.c +++ b/backends/pulse/pulse-source.c @@ -53,8 +53,6 @@ G_DEFINE_TYPE (PulseSource, pulse_source, PULSE_TYPE_STREAM); static const GList *pulse_source_list_controls (MateMixerStream *mms); static const GList *pulse_source_list_switches (MateMixerStream *mms); -static void free_list_controls (PulseSource *source); - static void pulse_source_class_init (PulseSourceClass *klass) { @@ -96,13 +94,10 @@ pulse_source_dispose (GObject *object) g_clear_object (&source->priv->control); g_clear_object (&source->priv->pswitch); + g_clear_pointer (&source->priv->pswitch_list, g_list_free); - free_list_controls (source); + _mate_mixer_clear_object_list (&source->priv->outputs_list); - if (source->priv->pswitch_list != NULL) { - g_list_free (source->priv->pswitch_list); - source->priv->pswitch_list = NULL; - } G_OBJECT_CLASS (pulse_source_parent_class)->dispose (object); } @@ -203,7 +198,7 @@ pulse_source_add_output (PulseSource *source, const pa_source_output_info *info) GUINT_TO_POINTER (info->index), output); - free_list_controls (source); + _mate_mixer_clear_object_list (&source->priv->outputs_list); g_signal_emit_by_name (G_OBJECT (source), "control-added", @@ -229,7 +224,7 @@ pulse_source_remove_output (PulseSource *source, guint32 index) g_object_ref (output); g_hash_table_remove (source->priv->outputs, GUINT_TO_POINTER (index)); - free_list_controls (source); + _mate_mixer_clear_object_list (&source->priv->outputs_list); g_signal_emit_by_name (G_OBJECT (source), "control-removed", MATE_MIXER_STREAM_CONTROL (output)); @@ -279,14 +274,3 @@ pulse_source_list_switches (MateMixerStream *mms) return PULSE_SOURCE (mms)->priv->pswitch_list; } - -static void -free_list_controls (PulseSource *source) -{ - if (source->priv->outputs_list == NULL) - return; - - g_list_free_full (source->priv->outputs_list, g_object_unref); - - source->priv->outputs_list = NULL; -} -- cgit v1.2.1