diff options
author | Michal Ratajsky <[email protected]> | 2016-01-09 20:25:33 +0100 |
---|---|---|
committer | raveit65 <[email protected]> | 2017-02-21 11:55:59 +0100 |
commit | 9cbe39ab7c55bcad401de32716c5c8106f166291 (patch) | |
tree | 42fb4f92923890f6c3070e95f5ff0ba88358da46 /backends/alsa | |
parent | d1deea43570dfd5bd32b7040f89cf3c971df3b9a (diff) | |
download | libmatemixer-9cbe39ab7c55bcad401de32716c5c8106f166291.tar.bz2 libmatemixer-9cbe39ab7c55bcad401de32716c5c8106f166291.tar.xz |
Provide and use convenience functions to remove some copy-pasted code
Diffstat (limited to 'backends/alsa')
-rw-r--r-- | backends/alsa/alsa-backend.c | 15 | ||||
-rw-r--r-- | backends/alsa/alsa-device.c | 28 | ||||
-rw-r--r-- | backends/alsa/alsa-stream.c | 11 | ||||
-rw-r--r-- | backends/alsa/alsa-switch.c | 5 |
4 files changed, 15 insertions, 44 deletions
diff --git a/backends/alsa/alsa-backend.c b/backends/alsa/alsa-backend.c index 3d62380..fb045ec 100644 --- a/backends/alsa/alsa-backend.c +++ b/backends/alsa/alsa-backend.c @@ -219,12 +219,8 @@ alsa_backend_close (MateMixerBackend *backend) g_source_destroy (alsa->priv->timeout_source); - if (alsa->priv->devices != NULL) { - g_list_free_full (alsa->priv->devices, g_object_unref); - alsa->priv->devices = NULL; - } - - free_stream_list (alsa); + _mate_mixer_clear_object_list (&alsa->priv->devices); + _mate_mixer_clear_object_list (&alsa->priv->streams); g_clear_object (&alsa->priv->default_device); g_hash_table_remove_all (alsa->priv->devices_ids); @@ -605,12 +601,7 @@ set_default_device (AlsaBackend *alsa, AlsaDevice *device) static void free_stream_list (AlsaBackend *alsa) { - if (alsa->priv->streams == NULL) - return; - - g_list_free_full (alsa->priv->streams, g_object_unref); - - alsa->priv->streams = NULL; + _mate_mixer_clear_object_list (&alsa->priv->streams); } static gint diff --git a/backends/alsa/alsa-device.c b/backends/alsa/alsa-device.c index 2064f79..c18d143 100644 --- a/backends/alsa/alsa-device.c +++ b/backends/alsa/alsa-device.c @@ -22,7 +22,9 @@ #include <glib/gi18n.h> #include <glib-object.h> #include <alsa/asoundlib.h> + #include <libmatemixer/matemixer.h> +#include <libmatemixer/matemixer-private.h> #include "alsa-compat.h" #include "alsa-constants.h" @@ -155,8 +157,6 @@ static void get_switch_info (snd_mixer_elem_t static void close_mixer (AlsaDevice *device); -static void free_stream_list (AlsaDevice *device); - static void alsa_device_class_init (AlsaDeviceClass *klass) { @@ -208,7 +208,7 @@ alsa_device_dispose (GObject *object) g_clear_object (&device->priv->input); g_clear_object (&device->priv->output); - free_stream_list (device); + _mate_mixer_clear_object_list (&device->priv->streams); G_OBJECT_CLASS (alsa_device_parent_class)->dispose (object); } @@ -339,7 +339,7 @@ alsa_device_close (AlsaDevice *device) /* Make each stream remove its controls and switches */ if (alsa_stream_has_controls_or_switches (device->priv->input) == TRUE) { alsa_stream_remove_all (device->priv->input); - free_stream_list (device); + _mate_mixer_clear_object_list (&device->priv->streams); g_signal_emit_by_name (G_OBJECT (device), "stream-removed", @@ -348,7 +348,7 @@ alsa_device_close (AlsaDevice *device) if (alsa_stream_has_controls_or_switches (device->priv->output) == TRUE) { alsa_stream_remove_all (device->priv->output); - free_stream_list (device); + _mate_mixer_clear_object_list (&device->priv->streams); g_signal_emit_by_name (G_OBJECT (device), "stream-removed", @@ -475,7 +475,7 @@ add_element (AlsaDevice *device, AlsaStream *stream, AlsaElement *element) } if (add_stream == TRUE) { - free_stream_list (device); + _mate_mixer_clear_object_list (&device->priv->streams); /* Pretend the stream has just been created now that we have added * the first control */ @@ -755,7 +755,7 @@ remove_elements_by_name (AlsaDevice *device, const gchar *name) if (alsa_stream_remove_elements (device->priv->input, name) == TRUE) { /* Removing last stream element "removes" the stream */ if (alsa_stream_has_controls_or_switches (device->priv->input) == FALSE) { - free_stream_list (device); + _mate_mixer_clear_object_list (&device->priv->streams); g_signal_emit_by_name (G_OBJECT (device), "stream-removed", MATE_MIXER_STREAM (device->priv->input)); @@ -765,7 +765,7 @@ remove_elements_by_name (AlsaDevice *device, const gchar *name) if (alsa_stream_remove_elements (device->priv->output, name) == TRUE) { /* Removing last stream element "removes" the stream */ if (alsa_stream_has_controls_or_switches (device->priv->output) == FALSE) { - free_stream_list (device); + _mate_mixer_clear_object_list (&device->priv->streams); g_signal_emit_by_name (G_OBJECT (device), "stream-removed", MATE_MIXER_STREAM (device->priv->output)); @@ -1122,15 +1122,3 @@ close_mixer (AlsaDevice *device) device->priv->handle = NULL; snd_mixer_close (handle); } - -static void -free_stream_list (AlsaDevice *device) -{ - /* This function is called each time the stream list changes */ - if (device->priv->streams == NULL) - return; - - g_list_free_full (device->priv->streams, g_object_unref); - - device->priv->streams = NULL; -} diff --git a/backends/alsa/alsa-stream.c b/backends/alsa/alsa-stream.c index 7e9c89f..9c642fb 100644 --- a/backends/alsa/alsa-stream.c +++ b/backends/alsa/alsa-stream.c @@ -17,6 +17,7 @@ #include <glib.h> #include <glib-object.h> + #include <libmatemixer/matemixer.h> #include <libmatemixer/matemixer-private.h> @@ -78,14 +79,8 @@ alsa_stream_dispose (GObject *object) stream = ALSA_STREAM (object); - if (stream->priv->controls != NULL) { - g_list_free_full (stream->priv->controls, g_object_unref); - stream->priv->controls = NULL; - } - if (stream->priv->switches != NULL) { - g_list_free_full (stream->priv->switches, g_object_unref); - stream->priv->switches = NULL; - } + _mate_mixer_clear_object_list (&stream->priv->controls); + _mate_mixer_clear_object_list (&stream->priv->switches); G_OBJECT_CLASS (alsa_stream_parent_class)->dispose (object); } diff --git a/backends/alsa/alsa-switch.c b/backends/alsa/alsa-switch.c index c2a95ca..7ea9e71 100644 --- a/backends/alsa/alsa-switch.c +++ b/backends/alsa/alsa-switch.c @@ -86,10 +86,7 @@ alsa_switch_dispose (GObject *object) swtch = ALSA_SWITCH (object); - if (swtch->priv->options != NULL) { - g_list_free_full (swtch->priv->options, g_object_unref); - swtch->priv->options = NULL; - } + _mate_mixer_clear_object_list (&swtch->priv->options); G_OBJECT_CLASS (alsa_switch_parent_class)->dispose (object); } |