libmm-glib,modem-firmware: use helper macros to manage the monitored properties
This commit is contained in:
@@ -44,8 +44,7 @@ struct _MMModemFirmwarePrivate {
|
||||
/* Common mutex to sync access */
|
||||
GMutex mutex;
|
||||
|
||||
guint update_settings_id;
|
||||
MMFirmwareUpdateSettings *update_settings;
|
||||
PROPERTY_OBJECT_DECLARE (update_settings, MMFirmwareUpdateSettings)
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -96,66 +95,6 @@ mm_modem_firmware_dup_path (MMModemFirmware *self)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
update_settings_updated (MMModemFirmware *self,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
g_mutex_lock (&self->priv->mutex);
|
||||
{
|
||||
GVariant *variant;
|
||||
|
||||
g_clear_object (&self->priv->update_settings);
|
||||
variant = mm_gdbus_modem_firmware_get_update_settings (MM_GDBUS_MODEM_FIRMWARE (self));
|
||||
if (variant) {
|
||||
GError *error = NULL;
|
||||
|
||||
self->priv->update_settings = mm_firmware_update_settings_new_from_variant (variant, &error);
|
||||
if (error) {
|
||||
g_warning ("Invalid update settings received: %s", error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
}
|
||||
}
|
||||
g_mutex_unlock (&self->priv->mutex);
|
||||
}
|
||||
|
||||
static void
|
||||
ensure_internal_update_settings (MMModemFirmware *self,
|
||||
MMFirmwareUpdateSettings **dupl)
|
||||
{
|
||||
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->update_settings_id) {
|
||||
GVariant *variant;
|
||||
|
||||
variant = mm_gdbus_modem_firmware_dup_update_settings (MM_GDBUS_MODEM_FIRMWARE (self));
|
||||
if (variant) {
|
||||
GError *error = NULL;
|
||||
|
||||
self->priv->update_settings = mm_firmware_update_settings_new_from_variant (variant, &error);
|
||||
if (error) {
|
||||
g_warning ("Invalid initial update settings: %s", error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
g_variant_unref (variant);
|
||||
}
|
||||
|
||||
/* No need to clear this signal connection when freeing self */
|
||||
self->priv->update_settings_id =
|
||||
g_signal_connect (self,
|
||||
"notify::update-settings",
|
||||
G_CALLBACK (update_settings_updated),
|
||||
NULL);
|
||||
}
|
||||
|
||||
if (dupl && self->priv->update_settings)
|
||||
*dupl = g_object_ref (self->priv->update_settings);
|
||||
}
|
||||
g_mutex_unlock (&self->priv->mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
* mm_modem_firmware_get_update_settings:
|
||||
* @self: A #MMModemFirmware.
|
||||
@@ -173,16 +112,6 @@ ensure_internal_update_settings (MMModemFirmware *self,
|
||||
*
|
||||
* Since: 1.10
|
||||
*/
|
||||
MMFirmwareUpdateSettings *
|
||||
mm_modem_firmware_get_update_settings (MMModemFirmware *self)
|
||||
{
|
||||
MMFirmwareUpdateSettings *update_settings = NULL;
|
||||
|
||||
g_return_val_if_fail (MM_IS_MODEM_FIRMWARE (self), NULL);
|
||||
|
||||
ensure_internal_update_settings (self, &update_settings);
|
||||
return update_settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* mm_modem_firmware_peek_update_settings:
|
||||
@@ -201,14 +130,11 @@ mm_modem_firmware_get_update_settings (MMModemFirmware *self)
|
||||
*
|
||||
* Since: 1.10
|
||||
*/
|
||||
MMFirmwareUpdateSettings *
|
||||
mm_modem_firmware_peek_update_settings (MMModemFirmware *self)
|
||||
{
|
||||
g_return_val_if_fail (MM_IS_MODEM_FIRMWARE (self), NULL);
|
||||
|
||||
ensure_internal_update_settings (self, NULL);
|
||||
return self->priv->update_settings;
|
||||
}
|
||||
PROPERTY_OBJECT_DEFINE_FAILABLE (update_settings,
|
||||
ModemFirmware, modem_firmware, MODEM_FIRMWARE,
|
||||
MMFirmwareUpdateSettings,
|
||||
mm_firmware_update_settings_new_from_variant)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
@@ -536,6 +462,8 @@ mm_modem_firmware_init (MMModemFirmware *self)
|
||||
{
|
||||
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, MM_TYPE_MODEM_FIRMWARE, MMModemFirmwarePrivate);
|
||||
g_mutex_init (&self->priv->mutex);
|
||||
|
||||
PROPERTY_INITIALIZE (update_settings, "update-settings")
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -545,7 +473,7 @@ finalize (GObject *object)
|
||||
|
||||
g_mutex_clear (&self->priv->mutex);
|
||||
|
||||
g_clear_object (&self->priv->update_settings);
|
||||
PROPERTY_OBJECT_FINALIZE (update_settings)
|
||||
|
||||
G_OBJECT_CLASS (mm_modem_firmware_parent_class)->finalize (object);
|
||||
}
|
||||
|
Reference in New Issue
Block a user