trivial: Add GObject properties to FuVolume

This will allow us to add other properties in the future.
This commit is contained in:
Richard Hughes 2020-10-30 14:49:52 +00:00
parent 43417b2a95
commit f3993a6b96
3 changed files with 75 additions and 22 deletions

View File

@ -2278,7 +2278,10 @@ fu_common_get_volumes_by_kind (const gchar *kind, GError **error)
g_dbus_proxy_get_object_path (proxy_blk)); g_dbus_proxy_get_object_path (proxy_blk));
return NULL; 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) { if (volumes->len == 0) {
g_set_error (error, g_set_error (error,

View File

@ -7,9 +7,8 @@
#pragma once #pragma once
#include <glib-object.h> #include <gio/gio.h>
#include "fu-volume.h" #include "fu-volume.h"
FuVolume *fu_volume_new_from_proxy (GDBusProxy *proxy);
FuVolume *fu_volume_new_from_mount_path (const gchar *mount_path); FuVolume *fu_volume_new_from_mount_path (const gchar *mount_path);

View File

@ -23,10 +23,17 @@
struct _FuVolume { struct _FuVolume {
GObject parent_instance; GObject parent_instance;
GDBusProxy *proxy; GDBusProxy *proxy_fs;
gchar *mount_path; /* only when mounted ourselves */ 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) G_DEFINE_TYPE (FuVolume, fu_volume, G_TYPE_OBJECT)
static void static void
@ -34,16 +41,68 @@ fu_volume_finalize (GObject *obj)
{ {
FuVolume *self = FU_VOLUME (obj); FuVolume *self = FU_VOLUME (obj);
g_free (self->mount_path); g_free (self->mount_path);
if (self->proxy != NULL) if (self->proxy_fs != NULL)
g_object_unref (self->proxy); g_object_unref (self->proxy_fs);
G_OBJECT_CLASS (fu_volume_parent_class)->finalize (obj); 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 static void
fu_volume_class_init (FuVolumeClass *klass) fu_volume_class_init (FuVolumeClass *klass)
{ {
GParamSpec *pspec;
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = fu_volume_finalize; 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 static void
@ -65,7 +124,7 @@ const gchar *
fu_volume_get_id (FuVolume *self) fu_volume_get_id (FuVolume *self)
{ {
g_return_val_if_fail (FU_IS_VOLUME (self), NULL); 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); return g_strdup (self->mount_path);
/* something else mounted it */ /* 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) if (val == NULL)
return NULL; return NULL;
mountpoints = g_variant_get_bytestring_array (val, 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); g_return_val_if_fail (FU_IS_VOLUME (self), FALSE);
/* device from the self tests */ /* device from the self tests */
if (self->proxy == NULL) if (self->proxy_fs == NULL)
return TRUE; return TRUE;
g_debug ("mounting %s", fu_volume_get_id (self)); g_debug ("mounting %s", fu_volume_get_id (self));
g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT); 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), "Mount", g_variant_new ("(a{sv})", &builder),
G_DBUS_CALL_FLAGS_NONE, G_DBUS_CALL_FLAGS_NONE,
-1, NULL, error); -1, NULL, error);
@ -220,12 +281,12 @@ fu_volume_unmount (FuVolume *self, GError **error)
g_return_val_if_fail (FU_IS_VOLUME (self), FALSE); g_return_val_if_fail (FU_IS_VOLUME (self), FALSE);
/* device from the self tests */ /* device from the self tests */
if (self->proxy == NULL) if (self->proxy_fs == NULL)
return TRUE; return TRUE;
g_debug ("unmounting %s", fu_volume_get_id (self)); g_debug ("unmounting %s", fu_volume_get_id (self));
g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT); 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", "Unmount",
g_variant_new ("(a{sv})", &builder), g_variant_new ("(a{sv})", &builder),
G_DBUS_CALL_FLAGS_NONE, G_DBUS_CALL_FLAGS_NONE,
@ -261,16 +322,6 @@ fu_volume_locker (FuVolume *self, GError **error)
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 */ /* private */
FuVolume * FuVolume *
fu_volume_new_from_mount_path (const gchar *mount_path) fu_volume_new_from_mount_path (const gchar *mount_path)