libmm-glib,call: use helper macros to manage the monitored properties

This commit is contained in:
Aleksander Morgado
2021-07-01 22:42:45 +02:00
parent 19b3a55230
commit 132fc268b8

View File

@@ -40,9 +40,7 @@ struct _MMCallPrivate {
/* Common mutex to sync access */
GMutex mutex;
/* Audio Format */
guint audio_format_id;
MMCallAudioFormat *audio_format;
PROPERTY_OBJECT_DECLARE (audio_format, MMCallAudioFormat)
};
/*****************************************************************************/
@@ -263,68 +261,6 @@ mm_call_dup_audio_port (MMCall *self)
/*****************************************************************************/
static void
audio_format_updated (MMCall *self,
GParamSpec *pspec)
{
g_mutex_lock (&self->priv->mutex);
{
GVariant *dictionary;
g_clear_object (&self->priv->audio_format);
/* TODO: update existing object instead of re-creating? */
dictionary = mm_gdbus_call_get_audio_format (MM_GDBUS_CALL (self));
if (dictionary) {
GError *error = NULL;
self->priv->audio_format = mm_call_audio_format_new_from_dictionary (dictionary, &error);
if (error) {
g_warning ("Invalid audio format update received: %s", error->message);
g_error_free (error);
}
}
}
g_mutex_unlock (&self->priv->mutex);
}
static void
ensure_internal_audio_format (MMCall *self,
MMCallAudioFormat **dup)
{
g_mutex_lock (&self->priv->mutex);
{
/* If this is the first time ever asking for the object, setup the
* update listener and the initial object, if any. */
if (!self->priv->audio_format_id) {
GVariant *dictionary;
dictionary = mm_gdbus_call_dup_audio_format (MM_GDBUS_CALL (self));
if (dictionary) {
GError *error = NULL;
self->priv->audio_format = mm_call_audio_format_new_from_dictionary (dictionary, &error);
if (error) {
g_warning ("Invalid initial audio format: %s", error->message);
g_error_free (error);
}
g_variant_unref (dictionary);
}
/* No need to clear this signal connection when freeing self */
self->priv->audio_format_id =
g_signal_connect (self,
"notify::audio-format",
G_CALLBACK (audio_format_updated),
NULL);
}
if (dup && self->priv->audio_format)
*dup = g_object_ref (self->priv->audio_format);
}
g_mutex_unlock (&self->priv->mutex);
}
/**
* mm_call_get_audio_format:
* @self: A #MMCall.
@@ -342,16 +278,6 @@ ensure_internal_audio_format (MMCall *self,
*
* Since: 1.10
*/
MMCallAudioFormat *
mm_call_get_audio_format (MMCall *self)
{
MMCallAudioFormat *format = NULL;
g_return_val_if_fail (MM_IS_CALL (self), NULL);
ensure_internal_audio_format (self, &format);
return format;
}
/**
* mm_call_peek_audio_format:
@@ -370,14 +296,11 @@ mm_call_get_audio_format (MMCall *self)
*
* Since: 1.10
*/
MMCallAudioFormat *
mm_call_peek_audio_format (MMCall *self)
{
g_return_val_if_fail (MM_IS_CALL (self), NULL);
ensure_internal_audio_format (self, NULL);
return self->priv->audio_format;
}
PROPERTY_OBJECT_DEFINE_FAILABLE (audio_format,
Call, call, CALL,
MMCallAudioFormat,
mm_call_audio_format_new_from_dictionary)
/*****************************************************************************/
@@ -1017,6 +940,8 @@ mm_call_init (MMCall *self)
{
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, MM_TYPE_CALL, MMCallPrivate);
g_mutex_init (&self->priv->mutex);
PROPERTY_INITIALIZE (audio_format, "audio-format")
}
static void
@@ -1026,7 +951,7 @@ finalize (GObject *object)
g_mutex_clear (&self->priv->mutex);
g_clear_object (&self->priv->audio_format);
PROPERTY_OBJECT_FINALIZE (audio_format)
G_OBJECT_CLASS (mm_call_parent_class)->finalize (object);
}