summaryrefslogtreecommitdiff
path: root/backends/alsa/alsa-switch.c
diff options
context:
space:
mode:
authorMichal Ratajsky <[email protected]>2014-08-18 20:49:17 +0200
committerMichal Ratajsky <[email protected]>2014-08-18 20:49:17 +0200
commit5f20ab328add9442082277a57c23273a3a2125ed (patch)
treefb458ba63f25db35de6b5a9c9acf0f967020107f /backends/alsa/alsa-switch.c
parent94d24482d8b1013947c0e2dac7330180b6ae02f6 (diff)
downloadlibmatemixer-5f20ab328add9442082277a57c23273a3a2125ed.tar.bz2
libmatemixer-5f20ab328add9442082277a57c23273a3a2125ed.tar.xz
Global update
Diffstat (limited to 'backends/alsa/alsa-switch.c')
-rw-r--r--backends/alsa/alsa-switch.c47
1 files changed, 39 insertions, 8 deletions
diff --git a/backends/alsa/alsa-switch.c b/backends/alsa/alsa-switch.c
index 15151ae..6a0f1f4 100644
--- a/backends/alsa/alsa-switch.c
+++ b/backends/alsa/alsa-switch.c
@@ -37,6 +37,7 @@ static void alsa_element_interface_init (AlsaElementInterface *iface);
static void alsa_switch_class_init (AlsaSwitchClass *klass);
static void alsa_switch_init (AlsaSwitch *swtch);
+static void alsa_switch_dispose (GObject *object);
G_DEFINE_TYPE_WITH_CODE (AlsaSwitch, alsa_switch,
MATE_MIXER_TYPE_SWITCH,
@@ -46,7 +47,7 @@ G_DEFINE_TYPE_WITH_CODE (AlsaSwitch, alsa_switch,
static gboolean alsa_switch_set_active_option (MateMixerSwitch *mms,
MateMixerSwitchOption *mmso);
-static GList * alsa_switch_list_options (MateMixerSwitch *mms);
+static const GList * alsa_switch_list_options (MateMixerSwitch *mms);
static snd_mixer_elem_t * alsa_switch_get_snd_element (AlsaElement *element);
static void alsa_switch_set_snd_element (AlsaElement *element,
@@ -64,8 +65,12 @@ alsa_element_interface_init (AlsaElementInterface *iface)
static void
alsa_switch_class_init (AlsaSwitchClass *klass)
{
+ GObjectClass *object_class;
MateMixerSwitchClass *switch_class;
+ object_class = G_OBJECT_CLASS (klass);
+ object_class->dispose = alsa_switch_dispose;
+
switch_class = MATE_MIXER_SWITCH_CLASS (klass);
switch_class->set_active_option = alsa_switch_set_active_option;
switch_class->list_options = alsa_switch_list_options;
@@ -74,6 +79,21 @@ alsa_switch_class_init (AlsaSwitchClass *klass)
}
static void
+alsa_switch_dispose (GObject *object)
+{
+ AlsaSwitch *swtch;
+
+ swtch = ALSA_SWITCH (object);
+
+ if (swtch->priv->options != NULL) {
+ g_list_free_full (swtch->priv->options, g_object_unref);
+ swtch->priv->options = NULL;
+ }
+
+ G_OBJECT_CLASS (alsa_switch_parent_class)->dispose (object);
+}
+
+static void
alsa_switch_init (AlsaSwitch *swtch)
{
swtch->priv = G_TYPE_INSTANCE_GET_PRIVATE (swtch,
@@ -82,13 +102,17 @@ alsa_switch_init (AlsaSwitch *swtch)
}
AlsaSwitch *
-alsa_switch_new (const gchar *name, const gchar *label, GList *options)
+alsa_switch_new (const gchar *name,
+ const gchar *label,
+ MateMixerSwitchRole role,
+ GList *options)
{
AlsaSwitch *swtch;
swtch = g_object_new (ALSA_TYPE_SWITCH,
"name", name,
"label", label,
+ "role", role,
NULL);
/* Takes ownership of options */
@@ -109,6 +133,9 @@ alsa_switch_set_active_option (MateMixerSwitch *mms, MateMixerSwitchOption *mmso
swtch = ALSA_SWITCH (mms);
+ if G_UNLIKELY (swtch->priv->element == NULL)
+ return FALSE;
+
/* The channel mask is created when reading the active option the first
* time, so a successful load must be done before changing the option */
if G_UNLIKELY (swtch->priv->channel_mask == 0) {
@@ -136,12 +163,12 @@ alsa_switch_set_active_option (MateMixerSwitch *mms, MateMixerSwitchOption *mmso
return set_item;
}
-static GList *
-alsa_switch_list_options (MateMixerSwitch *swtch)
+static const GList *
+alsa_switch_list_options (MateMixerSwitch *mms)
{
- g_return_val_if_fail (ALSA_IS_SWITCH (swtch), NULL);
+ g_return_val_if_fail (ALSA_IS_SWITCH (mms), NULL);
- return ALSA_SWITCH (swtch)->priv->options;
+ return ALSA_SWITCH (mms)->priv->options;
}
static snd_mixer_elem_t *
@@ -156,7 +183,6 @@ static void
alsa_switch_set_snd_element (AlsaElement *element, snd_mixer_elem_t *el)
{
g_return_if_fail (ALSA_IS_SWITCH (element));
- g_return_if_fail (el != NULL);
ALSA_SWITCH (element)->priv->element = el;
}
@@ -170,8 +196,13 @@ alsa_switch_load (AlsaElement *element)
gint ret;
snd_mixer_selem_channel_id_t c;
+ g_return_val_if_fail (ALSA_IS_SWITCH (element), FALSE);
+
swtch = ALSA_SWITCH (element);
+ if G_UNLIKELY (swtch->priv->element == NULL)
+ return FALSE;
+
/* When reading the first time we try all the channels, otherwise only the
* ones which returned success before */
if (swtch->priv->channel_mask == 0) {
@@ -220,7 +251,7 @@ alsa_switch_load (AlsaElement *element)
}
g_warning ("Unknown active option of switch %s: %d",
- snd_mixer_selem_get_name (swtch->priv->element),
+ mate_mixer_switch_get_name (MATE_MIXER_SWITCH (swtch)),
item);
return FALSE;