From f3993a6b9692b1e3815a1de7c688dd77e9c9347e Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Fri, 30 Oct 2020 14:49:52 +0000 Subject: [PATCH] trivial: Add GObject properties to FuVolume This will allow us to add other properties in the future. --- libfwupdplugin/fu-common.c | 5 +- libfwupdplugin/fu-volume-private.h | 3 +- libfwupdplugin/fu-volume.c | 89 +++++++++++++++++++++++------- 3 files changed, 75 insertions(+), 22 deletions(-) diff --git a/libfwupdplugin/fu-common.c b/libfwupdplugin/fu-common.c index 23a5b9566..4533565b2 100644 --- a/libfwupdplugin/fu-common.c +++ b/libfwupdplugin/fu-common.c @@ -2278,7 +2278,10 @@ fu_common_get_volumes_by_kind (const gchar *kind, GError **error) g_dbus_proxy_get_object_path (proxy_blk)); return NULL; } - g_ptr_array_add (volumes, fu_volume_new_from_proxy (proxy_fs)); + g_ptr_array_add (volumes, + g_object_new (FU_TYPE_VOLUME, + "proxy-filesystem", proxy_fs, + NULL)); } if (volumes->len == 0) { g_set_error (error, diff --git a/libfwupdplugin/fu-volume-private.h b/libfwupdplugin/fu-volume-private.h index 88d6f6699..d1c8f99c3 100644 --- a/libfwupdplugin/fu-volume-private.h +++ b/libfwupdplugin/fu-volume-private.h @@ -7,9 +7,8 @@ #pragma once -#include +#include #include "fu-volume.h" -FuVolume *fu_volume_new_from_proxy (GDBusProxy *proxy); FuVolume *fu_volume_new_from_mount_path (const gchar *mount_path); diff --git a/libfwupdplugin/fu-volume.c b/libfwupdplugin/fu-volume.c index 0ce53c511..097875667 100644 --- a/libfwupdplugin/fu-volume.c +++ b/libfwupdplugin/fu-volume.c @@ -23,10 +23,17 @@ struct _FuVolume { GObject parent_instance; - GDBusProxy *proxy; + GDBusProxy *proxy_fs; gchar *mount_path; /* only when mounted ourselves */ }; +enum { + PROP_0, + PROP_MOUNT_PATH, + PROP_PROXY_FILESYSTEM, + PROP_LAST +}; + G_DEFINE_TYPE (FuVolume, fu_volume, G_TYPE_OBJECT) static void @@ -34,16 +41,68 @@ fu_volume_finalize (GObject *obj) { FuVolume *self = FU_VOLUME (obj); g_free (self->mount_path); - if (self->proxy != NULL) - g_object_unref (self->proxy); + if (self->proxy_fs != NULL) + g_object_unref (self->proxy_fs); G_OBJECT_CLASS (fu_volume_parent_class)->finalize (obj); } +static void +fu_volume_get_property (GObject *object, guint prop_id, + GValue *value, GParamSpec *pspec) +{ + FuVolume *self = FU_VOLUME (object); + switch (prop_id) { + case PROP_MOUNT_PATH: + g_value_set_string (value, self->mount_path); + break; + case PROP_PROXY_FILESYSTEM: + g_value_set_object (value, self->proxy_fs); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +fu_volume_set_property (GObject *object, guint prop_id, + const GValue *value, GParamSpec *pspec) +{ + FuVolume *self = FU_VOLUME (object); + switch (prop_id) { + case PROP_MOUNT_PATH: + self->mount_path = g_value_dup_string (value); + break; + case PROP_PROXY_FILESYSTEM: + self->proxy_fs = g_value_dup_object (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + static void fu_volume_class_init (FuVolumeClass *klass) { + GParamSpec *pspec; GObjectClass *object_class = G_OBJECT_CLASS (klass); + object_class->finalize = fu_volume_finalize; + object_class->get_property = fu_volume_get_property; + object_class->set_property = fu_volume_set_property; + + pspec = g_param_spec_object ("proxy-filesystem", NULL, NULL, G_TYPE_DBUS_PROXY, + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_READWRITE | + G_PARAM_STATIC_NAME); + g_object_class_install_property (object_class, PROP_PROXY_FILESYSTEM, pspec); + + pspec = g_param_spec_string ("mount-path", NULL, NULL, NULL, + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_READWRITE | + G_PARAM_STATIC_NAME); + g_object_class_install_property (object_class, PROP_MOUNT_PATH, pspec); } static void @@ -65,7 +124,7 @@ const gchar * fu_volume_get_id (FuVolume *self) { g_return_val_if_fail (FU_IS_VOLUME (self), NULL); - return g_dbus_proxy_get_object_path (self->proxy); + return g_dbus_proxy_get_object_path (self->proxy_fs); } /** @@ -92,7 +151,9 @@ fu_volume_get_mount_point (FuVolume *self) return g_strdup (self->mount_path); /* something else mounted it */ - val = g_dbus_proxy_get_cached_property (self->proxy, "MountPoints"); + if (self->proxy_fs == NULL) + return NULL; + val = g_dbus_proxy_get_cached_property (self->proxy_fs, "MountPoints"); if (val == NULL) return NULL; mountpoints = g_variant_get_bytestring_array (val, NULL); @@ -185,12 +246,12 @@ fu_volume_mount (FuVolume *self, GError **error) g_return_val_if_fail (FU_IS_VOLUME (self), FALSE); /* device from the self tests */ - if (self->proxy == NULL) + if (self->proxy_fs == NULL) return TRUE; g_debug ("mounting %s", fu_volume_get_id (self)); g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT); - val = g_dbus_proxy_call_sync (self->proxy, + val = g_dbus_proxy_call_sync (self->proxy_fs, "Mount", g_variant_new ("(a{sv})", &builder), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error); @@ -220,12 +281,12 @@ fu_volume_unmount (FuVolume *self, GError **error) g_return_val_if_fail (FU_IS_VOLUME (self), FALSE); /* device from the self tests */ - if (self->proxy == NULL) + if (self->proxy_fs == NULL) return TRUE; g_debug ("unmounting %s", fu_volume_get_id (self)); g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT); - val = g_dbus_proxy_call_sync (self->proxy, + val = g_dbus_proxy_call_sync (self->proxy_fs, "Unmount", g_variant_new ("(a{sv})", &builder), G_DBUS_CALL_FLAGS_NONE, @@ -261,16 +322,6 @@ fu_volume_locker (FuVolume *self, GError **error) error); } -/* private */ -FuVolume * -fu_volume_new_from_proxy (GDBusProxy *proxy) -{ - g_autoptr(FuVolume) self = g_object_new (FU_TYPE_VOLUME, NULL); - g_return_val_if_fail (proxy != NULL, NULL); - g_set_object (&self->proxy, proxy); - return g_steal_pointer (&self); -} - /* private */ FuVolume * fu_volume_new_from_mount_path (const gchar *mount_path)