diff options
-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 | ||||
-rw-r--r-- | backends/oss/oss-backend.c | 20 | ||||
-rw-r--r-- | backends/oss/oss-device.c | 3 | ||||
-rw-r--r-- | backends/oss/oss-stream-control.c | 6 | ||||
-rw-r--r-- | backends/oss/oss-stream.c | 15 | ||||
-rw-r--r-- | backends/oss/oss-switch.c | 11 | ||||
-rw-r--r-- | backends/pulse/pulse-backend.c | 61 | ||||
-rw-r--r-- | backends/pulse/pulse-device-switch.c | 6 | ||||
-rw-r--r-- | backends/pulse/pulse-device.c | 24 | ||||
-rw-r--r-- | backends/pulse/pulse-port-switch.c | 6 | ||||
-rw-r--r-- | backends/pulse/pulse-sink.c | 24 | ||||
-rw-r--r-- | backends/pulse/pulse-source.c | 24 | ||||
-rw-r--r-- | libmatemixer/matemixer-private.h | 13 | ||||
-rw-r--r-- | libmatemixer/matemixer-stream-toggle.c | 6 | ||||
-rw-r--r-- | libmatemixer/matemixer.c | 40 |
18 files changed, 107 insertions, 211 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); } diff --git a/backends/oss/oss-backend.c b/backends/oss/oss-backend.c index 5795e7c..bf5af37 100644 --- a/backends/oss/oss-backend.c +++ b/backends/oss/oss-backend.c @@ -267,12 +267,8 @@ oss_backend_close (MateMixerBackend *backend) if (oss->priv->timeout_source_default != NULL) g_source_destroy (oss->priv->timeout_source_default); - if (oss->priv->devices != NULL) { - g_list_free_full (oss->priv->devices, g_object_unref); - oss->priv->devices = NULL; - } - - free_stream_list (oss); + _mate_mixer_clear_object_list (&oss->priv->devices); + _mate_mixer_clear_object_list (&oss->priv->streams); g_clear_object (&oss->priv->default_device); g_hash_table_remove_all (oss->priv->devices_paths); @@ -388,7 +384,7 @@ read_device (OssBackend *oss, const gchar *path) * device's polling facility should handle this by itself. */ if (g_hash_table_contains (oss->priv->devices_paths, path) == TRUE) { - close (fd); + g_close (fd, NULL); return TRUE; } @@ -398,8 +394,7 @@ read_device (OssBackend *oss, const gchar *path) device = oss_device_new (bname, label, path, fd); g_free (bname); g_free (label); - - close (fd); + g_close (fd, NULL); if G_LIKELY (device != NULL) { if (oss_device_open (device) == TRUE) { @@ -717,12 +712,7 @@ set_default_device_index (OssBackend *oss, guint index, gboolean fallback) static void free_stream_list (OssBackend *oss) { - if (oss->priv->streams == NULL) - return; - - g_list_free_full (oss->priv->streams, g_object_unref); - - oss->priv->streams = NULL; + _mate_mixer_clear_object_list (&oss->priv->streams); } static gint diff --git a/backends/oss/oss-device.c b/backends/oss/oss-device.c index 582c837..d11555d 100644 --- a/backends/oss/oss-device.c +++ b/backends/oss/oss-device.c @@ -368,8 +368,7 @@ oss_device_close (OssDevice *device) if (device->priv->poll_tag_restore != 0) g_source_remove (device->priv->poll_tag_restore); - close (device->priv->fd); - device->priv->fd = -1; + _mate_mixer_clear_fd (&device->priv->fd); g_signal_emit (G_OBJECT (device), signals[CLOSED], 0); } diff --git a/backends/oss/oss-stream-control.c b/backends/oss/oss-stream-control.c index bcb73fe..f826f62 100644 --- a/backends/oss/oss-stream-control.c +++ b/backends/oss/oss-stream-control.c @@ -206,11 +206,7 @@ oss_stream_control_close (OssStreamControl *control) { g_return_if_fail (OSS_IS_STREAM_CONTROL (control)); - if (control->priv->fd == -1) - return; - - close (control->priv->fd); - control->priv->fd = -1; + _mate_mixer_clear_fd (&control->priv->fd); } static guint diff --git a/backends/oss/oss-stream.c b/backends/oss/oss-stream.c index 7727dad..63c8481 100644 --- a/backends/oss/oss-stream.c +++ b/backends/oss/oss-stream.c @@ -18,6 +18,7 @@ #include <glib.h> #include <glib/gi18n.h> #include <glib-object.h> + #include <libmatemixer/matemixer.h> #include <libmatemixer/matemixer-private.h> @@ -75,14 +76,8 @@ oss_stream_dispose (GObject *object) stream = OSS_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_clear_object (&stream->priv->swtch); @@ -250,9 +245,7 @@ oss_stream_remove_all (OssStream *stream) if (stream->priv->swtch != NULL) { oss_switch_close (stream->priv->swtch); - - g_list_free_full (stream->priv->switches, g_object_unref); - stream->priv->switches = NULL; + _mate_mixer_clear_object_list (&stream->priv->switches); g_signal_emit_by_name (G_OBJECT (stream), "switch-removed", diff --git a/backends/oss/oss-switch.c b/backends/oss/oss-switch.c index 87ffb90..5ce3012 100644 --- a/backends/oss/oss-switch.c +++ b/backends/oss/oss-switch.c @@ -78,10 +78,7 @@ oss_switch_dispose (GObject *object) swtch = OSS_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 (oss_switch_parent_class)->dispose (object); } @@ -206,11 +203,7 @@ oss_switch_close (OssSwitch *swtch) { g_return_if_fail (OSS_IS_SWITCH (swtch)); - if (swtch->priv->fd == -1) - return; - - close (swtch->priv->fd); - swtch->priv->fd = -1; + _mate_mixer_clear_fd (&swtch->priv->fd); } static gboolean 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; -} diff --git a/libmatemixer/matemixer-private.h b/libmatemixer/matemixer-private.h index 37c430d..8976de8 100644 --- a/libmatemixer/matemixer-private.h +++ b/libmatemixer/matemixer-private.h @@ -32,6 +32,12 @@ G_BEGIN_DECLS +const GList *_mate_mixer_list_modules (void); + +/* ======================================================================= + * Convenience macros and functions to be used from modules + * ======================================================================= + */ #define MATE_MIXER_IS_LEFT_CHANNEL(c) \ ((c) == MATE_MIXER_CHANNEL_FRONT_LEFT || \ (c) == MATE_MIXER_CHANNEL_BACK_LEFT || \ @@ -106,10 +112,11 @@ G_BEGIN_DECLS #define MATE_MIXER_CHANNEL_MASK_HAS_FRONT(m) ((m) & MATE_MIXER_CHANNEL_MASK_FRONT) #define MATE_MIXER_CHANNEL_MASK_HAS_BACK(m) ((m) & MATE_MIXER_CHANNEL_MASK_BACK) -const GList *_mate_mixer_list_modules (void); +guint32 _mate_mixer_create_channel_mask (MateMixerChannelPosition *positions, + guint n) G_GNUC_PURE; -guint32 _mate_mixer_create_channel_mask (MateMixerChannelPosition *positions, - guint n) G_GNUC_PURE; +void _mate_mixer_clear_fd (gint *fd); +void _mate_mixer_clear_object_list (GList **list); G_END_DECLS diff --git a/libmatemixer/matemixer-stream-toggle.c b/libmatemixer/matemixer-stream-toggle.c index 70c829e..12582cb 100644 --- a/libmatemixer/matemixer-stream-toggle.c +++ b/libmatemixer/matemixer-stream-toggle.c @@ -199,13 +199,9 @@ mate_mixer_stream_toggle_dispose (GObject *object) toggle = MATE_MIXER_STREAM_TOGGLE (object); - if (toggle->priv->options != NULL) { - g_list_free (toggle->priv->options); - toggle->priv->options = NULL; - } - g_clear_object (&toggle->priv->on); g_clear_object (&toggle->priv->off); + g_clear_pointer (&toggle->priv->options, g_list_free); G_OBJECT_CLASS (mate_mixer_stream_toggle_parent_class)->dispose (object); } diff --git a/libmatemixer/matemixer.c b/libmatemixer/matemixer.c index 1c09c7b..826c43b 100644 --- a/libmatemixer/matemixer.c +++ b/libmatemixer/matemixer.c @@ -18,6 +18,7 @@ #include "config.h" #include <glib.h> +#include <glib/gstdio.h> #include <glib-object.h> #include <gmodule.h> @@ -141,6 +142,45 @@ _mate_mixer_create_channel_mask (MateMixerChannelPosition *positions, guint n) return mask; } +/** + * _mate_mixer_clear_fd: + * @fd: a pointer to a file descriptor + * + * Closes the file descriptor if it is open and sets the pointer to -1. + */ +void +_mate_mixer_clear_fd (gint *fd) +{ + g_return_if_fail (fd != NULL); + + if (*fd == -1) + return; + + g_close (*fd, NULL); + + *fd = -1; +} + +/** + * _mate_mixer_clear_object_list: + * @list: a pointer to a GList * + * + * Calls g_object_unref() on each item of the list, frees the list and + * sets the pointer to %NULL. + */ +void +_mate_mixer_clear_object_list (GList **list) +{ + g_return_if_fail (list != NULL); + + if (*list == NULL) + return; + + g_list_free_full (*list, g_object_unref); + + *list = NULL; +} + static void load_modules (void) { |