Commit ca2eb215 authored by Niels De Graef's avatar Niels De Graef 😁
Browse files

Improve GObject properties gunk a bit

Keep track of the `GParamSpec`s of the properties. This allows us to use
`g_object_notify_by_pspec()`, which is a bit more performant than
`g_object_notify()`(as it doesn't need to take a global lock to lookup
the property name). It also prevents accidental typos in the property
name at compile time.

Also always add `G_PARAM_STATIC_STRINGS`, to prevent some unnecessary
string duplications of property name, blurb and description.
parent f31e92bf
Pipeline #272262 failed with stage
in 2 minutes and 29 seconds
......@@ -61,7 +61,9 @@ enum
PROP_ICON_NAME,
PROP_PROFILE,
PROP_HUMAN_PROFILE,
N_PROPS
};
static GParamSpec *obj_props[N_PROPS] = { NULL, };
static void gvc_mixer_card_finalize (GObject *object);
......@@ -117,7 +119,7 @@ gvc_mixer_card_set_name (GvcMixerCard *card,
g_free (card->priv->name);
card->priv->name = g_strdup (name);
g_object_notify (G_OBJECT (card), "name");
g_object_notify_by_pspec (G_OBJECT (card), obj_props[PROP_NAME]);
return TRUE;
}
......@@ -137,7 +139,7 @@ gvc_mixer_card_set_icon_name (GvcMixerCard *card,
g_free (card->priv->icon_name);
card->priv->icon_name = g_strdup (icon_name);
g_object_notify (G_OBJECT (card), "icon-name");
g_object_notify_by_pspec (G_OBJECT (card), obj_props[PROP_ICON_NAME]);
return TRUE;
}
......@@ -191,7 +193,7 @@ gvc_mixer_card_set_profile (GvcMixerCard *card,
}
}
g_object_notify (G_OBJECT (card), "profile");
g_object_notify_by_pspec (G_OBJECT (card), obj_props[PROP_PROFILE]);
return TRUE;
}
......@@ -468,54 +470,42 @@ gvc_mixer_card_class_init (GvcMixerCardClass *klass)
gobject_class->set_property = gvc_mixer_card_set_property;
gobject_class->get_property = gvc_mixer_card_get_property;
g_object_class_install_property (gobject_class,
PROP_INDEX,
g_param_spec_ulong ("index",
"Index",
"The index for this card",
0, G_MAXULONG, 0,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (gobject_class,
PROP_ID,
g_param_spec_ulong ("id",
"id",
"The id for this card",
0, G_MAXULONG, 0,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (gobject_class,
PROP_PA_CONTEXT,
g_param_spec_pointer ("pa-context",
"PulseAudio context",
"The PulseAudio context for this card",
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (gobject_class,
PROP_NAME,
g_param_spec_string ("name",
"Name",
"Name to display for this card",
NULL,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
g_object_class_install_property (gobject_class,
PROP_ICON_NAME,
g_param_spec_string ("icon-name",
"Icon Name",
"Name of icon to display for this card",
NULL,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
g_object_class_install_property (gobject_class,
PROP_PROFILE,
g_param_spec_string ("profile",
"Profile",
"Name of current profile for this card",
NULL,
G_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_HUMAN_PROFILE,
g_param_spec_string ("human-profile",
"Profile (Human readable)",
"Name of current profile for this card in human readable form",
NULL,
G_PARAM_READABLE));
obj_props[PROP_INDEX] = g_param_spec_ulong ("index",
"Index",
"The index for this card",
0, G_MAXULONG, 0,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY|G_PARAM_STATIC_STRINGS);
obj_props[PROP_ID] = g_param_spec_ulong ("id",
"id",
"The id for this card",
0, G_MAXULONG, 0,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY|G_PARAM_STATIC_STRINGS);
obj_props[PROP_PA_CONTEXT] = g_param_spec_pointer ("pa-context",
"PulseAudio context",
"The PulseAudio context for this card",
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY|G_PARAM_STATIC_STRINGS);
obj_props[PROP_NAME] = g_param_spec_string ("name",
"Name",
"Name to display for this card",
NULL,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
obj_props[PROP_ICON_NAME] = g_param_spec_string ("icon-name",
"Icon Name",
"Name of icon to display for this card",
NULL,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
obj_props[PROP_PROFILE] = g_param_spec_string ("profile",
"Profile",
"Name of current profile for this card",
NULL,
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
obj_props[PROP_HUMAN_PROFILE] = g_param_spec_string ("human-profile",
"Profile (Human readable)",
"Name of current profile for this card in human readable form",
NULL,
G_PARAM_READABLE|G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (gobject_class, N_PROPS, obj_props);
}
static void
......
......@@ -54,8 +54,10 @@
enum {
PROP_0,
PROP_NAME
PROP_NAME,
N_PROPS
};
static GParamSpec *obj_props[N_PROPS] = { NULL, };
struct GvcMixerControlPrivate
{
......@@ -3627,7 +3629,7 @@ gvc_mixer_control_set_property (GObject *object,
case PROP_NAME:
g_free (self->priv->name);
self->priv->name = g_value_dup_string (value);
g_object_notify (G_OBJECT (self), "name");
g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_NAME]);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
......@@ -3683,13 +3685,12 @@ gvc_mixer_control_class_init (GvcMixerControlClass *klass)
object_class->set_property = gvc_mixer_control_set_property;
object_class->get_property = gvc_mixer_control_get_property;
g_object_class_install_property (object_class,
PROP_NAME,
g_param_spec_string ("name",
"Name",
"Name to display for this mixer control",
NULL,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
obj_props[PROP_NAME] = g_param_spec_string ("name",
"Name",
"Name to display for this mixer control",
NULL,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY|G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPS, obj_props);
signals [STATE_CHANGED] =
g_signal_new ("state-changed",
......
......@@ -42,8 +42,10 @@ struct GvcMixerEventRolePrivate
enum
{
PROP_0,
PROP_DEVICE
PROP_DEVICE,
N_PROPS
};
static GParamSpec *obj_props[N_PROPS] = { NULL, };
static void gvc_mixer_event_role_finalize (GObject *object);
......@@ -115,7 +117,7 @@ gvc_mixer_event_role_set_device (GvcMixerEventRole *role,
g_free (role->priv->device);
role->priv->device = g_strdup (device);
g_object_notify (G_OBJECT (role), "device");
g_object_notify_by_pspec (G_OBJECT (role), obj_props[PROP_DEVICE]);
return TRUE;
}
......@@ -169,13 +171,12 @@ gvc_mixer_event_role_class_init (GvcMixerEventRoleClass *klass)
stream_class->push_volume = gvc_mixer_event_role_push_volume;
stream_class->change_is_muted = gvc_mixer_event_role_change_is_muted;
g_object_class_install_property (object_class,
PROP_DEVICE,
g_param_spec_string ("device",
"Device",
"Device",
NULL,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
obj_props[PROP_DEVICE] = g_param_spec_string ("device",
"Device",
"Device",
NULL,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPS, obj_props);
}
static void
......
This diff is collapsed.
......@@ -55,7 +55,9 @@ enum
PROP_UI_DEVICE_TYPE,
PROP_PORT_AVAILABLE,
PROP_ICON_NAME,
N_PROPS
};
static GParamSpec *obj_props[N_PROPS] = { NULL, };
static void gvc_mixer_ui_device_finalize (GObject *object);
......@@ -224,7 +226,6 @@ static void
gvc_mixer_ui_device_class_init (GvcMixerUIDeviceClass *klass)
{
GObjectClass* object_class = G_OBJECT_CLASS (klass);
GParamSpec *pspec;
object_class->constructor = gvc_mixer_ui_device_constructor;
object_class->dispose = gvc_mixer_ui_device_dispose;
......@@ -232,62 +233,64 @@ gvc_mixer_ui_device_class_init (GvcMixerUIDeviceClass *klass)
object_class->set_property = gvc_mixer_ui_device_set_property;
object_class->get_property = gvc_mixer_ui_device_get_property;
pspec = g_param_spec_string ("description",
obj_props[PROP_DESC_LINE_1] =
g_param_spec_string ("description",
"Description construct prop",
"Set first line description",
"no-name-set",
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_DESC_LINE_1, pspec);
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
pspec = g_param_spec_string ("origin",
obj_props[PROP_DESC_LINE_2] =
g_param_spec_string ("origin",
"origin construct prop",
"Set second line description name",
"no-name-set",
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_DESC_LINE_2, pspec);
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
pspec = g_param_spec_pointer ("card",
obj_props[PROP_CARD] =
g_param_spec_pointer ("card",
"Card from pulse",
"Set/Get card",
G_PARAM_READWRITE);
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
g_object_class_install_property (object_class, PROP_CARD, pspec);
pspec = g_param_spec_string ("port-name",
obj_props[PROP_PORT_NAME] =
g_param_spec_string ("port-name",
"port-name construct prop",
"Set port-name",
NULL,
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_PORT_NAME, pspec);
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
pspec = g_param_spec_uint ("stream-id",
obj_props[PROP_STREAM_ID] =
g_param_spec_uint ("stream-id",
"stream id assigned by gvc-stream",
"Set/Get stream id",
0,
G_MAXUINT,
GVC_MIXER_UI_DEVICE_INVALID,
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_STREAM_ID, pspec);
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
pspec = g_param_spec_uint ("type",
obj_props[PROP_UI_DEVICE_TYPE] =
g_param_spec_uint ("type",
"ui-device type",
"determine whether its an input and output",
0, 1, 0, G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_UI_DEVICE_TYPE, pspec);
0, 1, 0,
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
pspec = g_param_spec_boolean ("port-available",
obj_props[PROP_PORT_AVAILABLE] =
g_param_spec_boolean ("port-available",
"available",
"determine whether this port is available",
FALSE,
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_PORT_AVAILABLE, pspec);
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
pspec = g_param_spec_string ("icon-name",
obj_props[PROP_ICON_NAME] =
g_param_spec_string ("icon-name",
"Icon Name",
"Name of icon to display for this card",
NULL,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT);
g_object_class_install_property (object_class, PROP_ICON_NAME, pspec);
G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPS, obj_props);
}
/* Removes the part of the string that starts with skip_prefix
......@@ -650,7 +653,7 @@ gvc_mixer_ui_device_set_icon_name (GvcMixerUIDevice *device,
g_free (device->priv->icon_name);
device->priv->icon_name = g_strdup (icon_name);
g_object_notify (G_OBJECT (device), "icon-name");
g_object_notify_by_pspec (G_OBJECT (device), obj_props[PROP_ICON_NAME]);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment