mixer-stream: 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.
This commit is contained in:
Niels De Graef 2022-05-29 13:45:38 +02:00 committed by Bastien Nocera
parent f6d6fe577f
commit ed28e761d5

View File

@ -83,7 +83,9 @@ enum
PROP_CARD_INDEX, PROP_CARD_INDEX,
PROP_PORT, PROP_PORT,
PROP_STATE, PROP_STATE,
N_PROPS
}; };
static GParamSpec *obj_props[N_PROPS] = { NULL, };
static void gvc_mixer_stream_finalize (GObject *object); static void gvc_mixer_stream_finalize (GObject *object);
@ -198,7 +200,7 @@ gvc_mixer_stream_set_volume (GvcMixerStream *stream,
if (!pa_cvolume_equal(gvc_channel_map_get_cvolume(stream->priv->channel_map), &cv)) { if (!pa_cvolume_equal(gvc_channel_map_get_cvolume(stream->priv->channel_map), &cv)) {
gvc_channel_map_volume_changed(stream->priv->channel_map, &cv, FALSE); gvc_channel_map_volume_changed(stream->priv->channel_map, &cv, FALSE);
g_object_notify (G_OBJECT (stream), "volume"); g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_VOLUME]);
return TRUE; return TRUE;
} }
@ -218,7 +220,7 @@ gvc_mixer_stream_set_decibel (GvcMixerStream *stream,
if (!pa_cvolume_equal(gvc_channel_map_get_cvolume(stream->priv->channel_map), &cv)) { if (!pa_cvolume_equal(gvc_channel_map_get_cvolume(stream->priv->channel_map), &cv)) {
gvc_channel_map_volume_changed(stream->priv->channel_map, &cv, FALSE); gvc_channel_map_volume_changed(stream->priv->channel_map, &cv, FALSE);
g_object_notify (G_OBJECT (stream), "volume"); g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_VOLUME]);
} }
return TRUE; return TRUE;
@ -246,7 +248,7 @@ gvc_mixer_stream_set_is_muted (GvcMixerStream *stream,
if (is_muted != stream->priv->is_muted) { if (is_muted != stream->priv->is_muted) {
stream->priv->is_muted = is_muted; stream->priv->is_muted = is_muted;
g_object_notify (G_OBJECT (stream), "is-muted"); g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_IS_MUTED]);
} }
return TRUE; return TRUE;
@ -260,7 +262,7 @@ gvc_mixer_stream_set_can_decibel (GvcMixerStream *stream,
if (can_decibel != stream->priv->can_decibel) { if (can_decibel != stream->priv->can_decibel) {
stream->priv->can_decibel = can_decibel; stream->priv->can_decibel = can_decibel;
g_object_notify (G_OBJECT (stream), "can-decibel"); g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_CAN_DECIBEL]);
} }
return TRUE; return TRUE;
@ -288,7 +290,7 @@ gvc_mixer_stream_set_name (GvcMixerStream *stream,
g_free (stream->priv->name); g_free (stream->priv->name);
stream->priv->name = g_strdup (name); stream->priv->name = g_strdup (name);
g_object_notify (G_OBJECT (stream), "name"); g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_NAME]);
return TRUE; return TRUE;
} }
@ -301,7 +303,7 @@ gvc_mixer_stream_set_description (GvcMixerStream *stream,
g_free (stream->priv->description); g_free (stream->priv->description);
stream->priv->description = g_strdup (description); stream->priv->description = g_strdup (description);
g_object_notify (G_OBJECT (stream), "description"); g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_DESCRIPTION]);
return TRUE; return TRUE;
} }
@ -321,7 +323,7 @@ gvc_mixer_stream_set_is_event_stream (GvcMixerStream *stream,
g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE); g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE);
stream->priv->is_event_stream = is_event_stream; stream->priv->is_event_stream = is_event_stream;
g_object_notify (G_OBJECT (stream), "is-event-stream"); g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_IS_EVENT_STREAM]);
return TRUE; return TRUE;
} }
@ -341,7 +343,7 @@ gvc_mixer_stream_set_is_virtual (GvcMixerStream *stream,
g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE); g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE);
stream->priv->is_virtual = is_virtual; stream->priv->is_virtual = is_virtual;
g_object_notify (G_OBJECT (stream), "is-virtual"); g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_IS_VIRTUAL]);
return TRUE; return TRUE;
} }
@ -361,7 +363,7 @@ gvc_mixer_stream_set_application_id (GvcMixerStream *stream,
g_free (stream->priv->application_id); g_free (stream->priv->application_id);
stream->priv->application_id = g_strdup (application_id); stream->priv->application_id = g_strdup (application_id);
g_object_notify (G_OBJECT (stream), "application-id"); g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_APPLICATION_ID]);
return TRUE; return TRUE;
} }
@ -374,7 +376,7 @@ on_channel_map_volume_changed (GvcChannelMap *channel_map,
if (set == TRUE) if (set == TRUE)
gvc_mixer_stream_push_volume (stream); gvc_mixer_stream_push_volume (stream);
g_object_notify (G_OBJECT (stream), "volume"); g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_VOLUME]);
} }
static gboolean static gboolean
@ -402,7 +404,7 @@ gvc_mixer_stream_set_channel_map (GvcMixerStream *stream,
G_CALLBACK (on_channel_map_volume_changed), G_CALLBACK (on_channel_map_volume_changed),
stream); stream);
g_object_notify (G_OBJECT (stream), "channel-map"); g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_CHANNEL_MAP]);
} }
return TRUE; return TRUE;
@ -452,7 +454,7 @@ gvc_mixer_stream_set_icon_name (GvcMixerStream *stream,
g_free (stream->priv->icon_name); g_free (stream->priv->icon_name);
stream->priv->icon_name = g_strdup (icon_name); stream->priv->icon_name = g_strdup (icon_name);
g_object_notify (G_OBJECT (stream), "icon-name"); g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_ICON_NAME]);
return TRUE; return TRUE;
} }
@ -465,7 +467,7 @@ gvc_mixer_stream_set_form_factor (GvcMixerStream *stream,
g_free (stream->priv->form_factor); g_free (stream->priv->form_factor);
stream->priv->form_factor = g_strdup (form_factor); stream->priv->form_factor = g_strdup (form_factor);
g_object_notify (G_OBJECT (stream), "form-factor"); g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_FORM_FACTOR]);
return TRUE; return TRUE;
} }
@ -478,7 +480,7 @@ gvc_mixer_stream_set_sysfs_path (GvcMixerStream *stream,
g_free (stream->priv->sysfs_path); g_free (stream->priv->sysfs_path);
stream->priv->sysfs_path = g_strdup (sysfs_path); stream->priv->sysfs_path = g_strdup (sysfs_path);
g_object_notify (G_OBJECT (stream), "sysfs-path"); g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_SYSFS_PATH]);
return TRUE; return TRUE;
} }
@ -558,7 +560,7 @@ gvc_mixer_stream_set_port (GvcMixerStream *stream,
} }
} }
g_object_notify (G_OBJECT (stream), "port"); g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_PORT]);
return TRUE; return TRUE;
} }
@ -591,7 +593,7 @@ gvc_mixer_stream_set_state (GvcMixerStream *stream,
if (stream->priv->state != state) { if (stream->priv->state != state) {
stream->priv->state = state; stream->priv->state = state;
g_object_notify (G_OBJECT (stream), "state"); g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_STATE]);
} }
return TRUE; return TRUE;
@ -645,7 +647,7 @@ gvc_mixer_stream_set_card_index (GvcMixerStream *stream,
g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE); g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE);
stream->priv->card_index = card_index; stream->priv->card_index = card_index;
g_object_notify (G_OBJECT (stream), "card-index"); g_object_notify_by_pspec (G_OBJECT (stream), obj_props[PROP_CARD_INDEX]);
return TRUE; return TRUE;
} }
@ -897,140 +899,103 @@ gvc_mixer_stream_class_init (GvcMixerStreamClass *klass)
klass->change_port = gvc_mixer_stream_real_change_port; klass->change_port = gvc_mixer_stream_real_change_port;
klass->change_is_muted = gvc_mixer_stream_real_change_is_muted; klass->change_is_muted = gvc_mixer_stream_real_change_is_muted;
g_object_class_install_property (gobject_class, obj_props[PROP_INDEX] = g_param_spec_ulong ("index",
PROP_INDEX,
g_param_spec_ulong ("index",
"Index", "Index",
"The index for this stream", "The index for this stream",
0, G_MAXULONG, 0, 0, G_MAXULONG, 0,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY)); G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY|G_PARAM_STATIC_STRINGS);
g_object_class_install_property (gobject_class, obj_props[PROP_ID] = g_param_spec_ulong ("id",
PROP_ID,
g_param_spec_ulong ("id",
"id", "id",
"The id for this stream", "The id for this stream",
0, G_MAXULONG, 0, 0, G_MAXULONG, 0,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY)); G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY|G_PARAM_STATIC_STRINGS);
g_object_class_install_property (gobject_class, obj_props[PROP_CHANNEL_MAP] = g_param_spec_object ("channel-map",
PROP_CHANNEL_MAP,
g_param_spec_object ("channel-map",
"channel map", "channel map",
"The channel map for this stream", "The channel map for this stream",
GVC_TYPE_CHANNEL_MAP, GVC_TYPE_CHANNEL_MAP,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
g_object_class_install_property (gobject_class, obj_props[PROP_PA_CONTEXT] = g_param_spec_pointer ("pa-context",
PROP_PA_CONTEXT,
g_param_spec_pointer ("pa-context",
"PulseAudio context", "PulseAudio context",
"The PulseAudio context for this stream", "The PulseAudio context for this stream",
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY)); G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY|G_PARAM_STATIC_STRINGS);
g_object_class_install_property (gobject_class, obj_props[PROP_VOLUME] = g_param_spec_ulong ("volume",
PROP_VOLUME,
g_param_spec_ulong ("volume",
"Volume", "Volume",
"The volume for this stream", "The volume for this stream",
0, G_MAXULONG, 0, 0, G_MAXULONG, 0,
G_PARAM_READWRITE)); G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
g_object_class_install_property (gobject_class, obj_props[PROP_DECIBEL] = g_param_spec_double ("decibel",
PROP_DECIBEL,
g_param_spec_double ("decibel",
"Decibel", "Decibel",
"The decibel level for this stream", "The decibel level for this stream",
-G_MAXDOUBLE, G_MAXDOUBLE, 0, -G_MAXDOUBLE, G_MAXDOUBLE, 0,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
obj_props[PROP_NAME] = g_param_spec_string ("name",
g_object_class_install_property (gobject_class,
PROP_NAME,
g_param_spec_string ("name",
"Name", "Name",
"Name to display for this stream", "Name to display for this stream",
NULL, NULL,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
g_object_class_install_property (gobject_class, obj_props[PROP_DESCRIPTION] = g_param_spec_string ("description",
PROP_DESCRIPTION,
g_param_spec_string ("description",
"Description", "Description",
"Description to display for this stream", "Description to display for this stream",
NULL, NULL,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
g_object_class_install_property (gobject_class, obj_props[PROP_APPLICATION_ID] = g_param_spec_string ("application-id",
PROP_APPLICATION_ID,
g_param_spec_string ("application-id",
"Application identifier", "Application identifier",
"Application identifier for this stream", "Application identifier for this stream",
NULL, NULL,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
g_object_class_install_property (gobject_class, obj_props[PROP_ICON_NAME] = g_param_spec_string ("icon-name",
PROP_ICON_NAME,
g_param_spec_string ("icon-name",
"Icon Name", "Icon Name",
"Name of icon to display for this stream", "Name of icon to display for this stream",
NULL, NULL,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
g_object_class_install_property (gobject_class, obj_props[PROP_FORM_FACTOR] = g_param_spec_string ("form-factor",
PROP_FORM_FACTOR,
g_param_spec_string ("form-factor",
"Form Factor", "Form Factor",
"Device form factor for this stream, as reported by PulseAudio", "Device form factor for this stream, as reported by PulseAudio",
NULL, NULL,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
g_object_class_install_property (gobject_class, obj_props[PROP_SYSFS_PATH] = g_param_spec_string ("sysfs-path",
PROP_SYSFS_PATH,
g_param_spec_string ("sysfs-path",
"Sysfs path", "Sysfs path",
"Sysfs path for the device associated with this stream", "Sysfs path for the device associated with this stream",
NULL, NULL,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
g_object_class_install_property (gobject_class, obj_props[PROP_IS_MUTED] = g_param_spec_boolean ("is-muted",
PROP_IS_MUTED,
g_param_spec_boolean ("is-muted",
"is muted", "is muted",
"Whether stream is muted", "Whether stream is muted",
FALSE, FALSE,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
g_object_class_install_property (gobject_class, obj_props[PROP_CAN_DECIBEL] = g_param_spec_boolean ("can-decibel",
PROP_CAN_DECIBEL,
g_param_spec_boolean ("can-decibel",
"can decibel", "can decibel",
"Whether stream volume can be converted to decibel units", "Whether stream volume can be converted to decibel units",
FALSE, FALSE,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
g_object_class_install_property (gobject_class, obj_props[PROP_IS_EVENT_STREAM] = g_param_spec_boolean ("is-event-stream",
PROP_IS_EVENT_STREAM,
g_param_spec_boolean ("is-event-stream",
"is event stream", "is event stream",
"Whether stream's role is to play an event", "Whether stream's role is to play an event",
FALSE, FALSE,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
g_object_class_install_property (gobject_class, obj_props[PROP_IS_VIRTUAL] = g_param_spec_boolean ("is-virtual",
PROP_IS_VIRTUAL,
g_param_spec_boolean ("is-virtual",
"is virtual stream", "is virtual stream",
"Whether the stream is virtual", "Whether the stream is virtual",
FALSE, FALSE,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
g_object_class_install_property (gobject_class, obj_props[PROP_PORT] = g_param_spec_string ("port",
PROP_PORT,
g_param_spec_string ("port",
"Port", "Port",
"The name of the current port for this stream", "The name of the current port for this stream",
NULL, NULL,
G_PARAM_READWRITE)); G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
g_object_class_install_property (gobject_class, obj_props[PROP_STATE] = g_param_spec_enum ("state",
PROP_STATE,
g_param_spec_enum ("state",
"State", "State",
"The current state of this stream", "The current state of this stream",
GVC_TYPE_MIXER_STREAM_STATE, GVC_TYPE_MIXER_STREAM_STATE,
GVC_STREAM_STATE_INVALID, GVC_STREAM_STATE_INVALID,
G_PARAM_READWRITE)); G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
g_object_class_install_property (gobject_class, obj_props[PROP_CARD_INDEX] = g_param_spec_long ("card-index",
PROP_CARD_INDEX,
g_param_spec_long ("card-index",
"Card index", "Card index",
"The index of the card for this stream", "The index of the card for this stream",
PA_INVALID_INDEX, G_MAXLONG, PA_INVALID_INDEX, PA_INVALID_INDEX, G_MAXLONG, PA_INVALID_INDEX,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (gobject_class, N_PROPS, obj_props);
} }
static void static void