On Thu, Mar 01, 2012 at 12:15:41AM +0200, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak(a)gnome.org>
Remove now redundant 'path' property from GVirDomainDevice subclasses.
These classes now have access to their configurations, from which they
can easily get the path (among other properties) internally.
---
libvirt-gobject/libvirt-gobject-domain-disk.c | 84 ++++---------------
libvirt-gobject/libvirt-gobject-domain-interface.c | 81 +++----------------
2 files changed, 32 insertions(+), 133 deletions(-)
diff --git a/libvirt-gobject/libvirt-gobject-domain-disk.c
b/libvirt-gobject/libvirt-gobject-domain-disk.c
index fb7672e..0a1493a 100644
--- a/libvirt-gobject/libvirt-gobject-domain-disk.c
+++ b/libvirt-gobject/libvirt-gobject-domain-disk.c
@@ -36,73 +36,25 @@
struct _GVirDomainDiskPrivate
{
- gchar *path;
+ gboolean unused;
};
G_DEFINE_TYPE(GVirDomainDisk, gvir_domain_disk, GVIR_TYPE_DOMAIN_DEVICE);
-enum {
- PROP_0,
- PROP_PATH,
-};
-
#define GVIR_DOMAIN_DISK_ERROR gvir_domain_disk_error_quark()
-
static GQuark
gvir_domain_disk_error_quark(void)
{
return g_quark_from_static_string("gvir-domain-disk");
}
-static void gvir_domain_disk_get_property(GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GVirDomainDisk *self = GVIR_DOMAIN_DISK(object);
- GVirDomainDiskPrivate *priv = self->priv;
-
- switch (prop_id) {
- case PROP_PATH:
- g_value_set_string(value, priv->path);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- }
-}
-
-
-static void gvir_domain_disk_set_property(GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GVirDomainDisk *self = GVIR_DOMAIN_DISK(object);
- GVirDomainDiskPrivate *priv = self->priv;
-
- switch (prop_id) {
- case PROP_PATH:
- g_free(priv->path);
- priv->path = g_value_dup_string(value);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- }
-}
-
-
static void gvir_domain_disk_finalize(GObject *object)
{
GVirDomainDisk *self = GVIR_DOMAIN_DISK(object);
- GVirDomainDiskPrivate *priv = self->priv;
g_debug("Finalize GVirDomainDisk=%p", self);
- g_free(priv->path);
-
G_OBJECT_CLASS(gvir_domain_disk_parent_class)->finalize(object);
}
@@ -111,19 +63,6 @@ static void gvir_domain_disk_class_init(GVirDomainDiskClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gvir_domain_disk_finalize;
- object_class->get_property = gvir_domain_disk_get_property;
- object_class->set_property = gvir_domain_disk_set_property;
-
- g_object_class_install_property(object_class,
- PROP_PATH,
- g_param_spec_string("path",
- "Path",
- "The disk path",
- NULL,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
-
g_type_class_add_private(klass, sizeof(GVirDomainDiskPrivate));
}
@@ -151,6 +90,15 @@ gvir_domain_disk_stats_free(GVirDomainDiskStats *stats)
G_DEFINE_BOXED_TYPE(GVirDomainDiskStats, gvir_domain_disk_stats,
gvir_domain_disk_stats_copy, gvir_domain_disk_stats_free)
+static gchar *gvir_domain_disk_get_path(GVirDomainDisk *self)
+{
+ GVirConfigDomainDevice *config;
+
+ config = gvir_domain_device_get_config(GVIR_DOMAIN_DEVICE(self));
missing g_object_unref(config);
+
+ return gvir_config_domain_disk_get_target_dev (GVIR_CONFIG_DOMAIN_DISK (config));
+}
+
/**
* gvir_domain_disk_get_stats:
* @self: the domain disk
@@ -166,15 +114,15 @@ GVirDomainDiskStats *gvir_domain_disk_get_stats(GVirDomainDisk
*self, GError **e
{
GVirDomainDiskStats *ret = NULL;
virDomainBlockStatsStruct stats;
- GVirDomainDiskPrivate *priv;
virDomainPtr handle;
+ gchar *path;
g_return_val_if_fail(GVIR_IS_DOMAIN_DISK(self), NULL);
- priv = self->priv;
handle = gvir_domain_device_get_domain_handle(GVIR_DOMAIN_DEVICE(self));
+ path = gvir_domain_disk_get_path (self);
- if (virDomainBlockStats(handle, priv->path, &stats, sizeof (stats)) < 0)
{
+ if (virDomainBlockStats(handle, path, &stats, sizeof (stats)) < 0) {
gvir_set_error_literal(err, GVIR_DOMAIN_DISK_ERROR,
0,
"Unable to get domain disk stats");
@@ -190,6 +138,7 @@ GVirDomainDiskStats *gvir_domain_disk_get_stats(GVirDomainDisk *self,
GError **e
end:
virDomainFree(handle);
+ g_free(path);
return ret;
}
@@ -211,13 +160,15 @@ gboolean gvir_domain_disk_resize(GVirDomainDisk *self,
{
gboolean ret = FALSE;
virDomainPtr handle;
+ gchar *path;
g_return_val_if_fail(GVIR_IS_DOMAIN_DISK(self), FALSE);
g_return_val_if_fail(err == NULL || *err != NULL, FALSE);
handle = gvir_domain_device_get_domain_handle(GVIR_DOMAIN_DEVICE(self));
+ path = gvir_domain_disk_get_path (self);
- if (virDomainBlockResize(handle, self->priv->path, size, flags) < 0) {
+ if (virDomainBlockResize(handle, path, size, flags) < 0) {
gvir_set_error_literal(err, GVIR_DOMAIN_DISK_ERROR,
0,
"Failed to resize domain disk");
@@ -228,5 +179,6 @@ gboolean gvir_domain_disk_resize(GVirDomainDisk *self,
end:
virDomainFree(handle);
+ g_free(path);
return ret;
}
diff --git a/libvirt-gobject/libvirt-gobject-domain-interface.c
b/libvirt-gobject/libvirt-gobject-domain-interface.c
index 0917e03..e220375 100644
--- a/libvirt-gobject/libvirt-gobject-domain-interface.c
+++ b/libvirt-gobject/libvirt-gobject-domain-interface.c
@@ -36,73 +36,25 @@
struct _GVirDomainInterfacePrivate
{
- gchar *path;
+ gboolean unused;
};
G_DEFINE_TYPE(GVirDomainInterface, gvir_domain_interface, GVIR_TYPE_DOMAIN_DEVICE);
-enum {
- PROP_0,
- PROP_PATH,
-};
-
#define GVIR_DOMAIN_INTERFACE_ERROR gvir_domain_interface_error_quark()
-
static GQuark
gvir_domain_interface_error_quark(void)
{
return g_quark_from_static_string("gvir-domain-interface");
}
-static void gvir_domain_interface_get_property(GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GVirDomainInterface *self = GVIR_DOMAIN_INTERFACE(object);
- GVirDomainInterfacePrivate *priv = self->priv;
-
- switch (prop_id) {
- case PROP_PATH:
- g_value_set_string(value, priv->path);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- }
-}
-
-
-static void gvir_domain_interface_set_property(GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GVirDomainInterface *self = GVIR_DOMAIN_INTERFACE(object);
- GVirDomainInterfacePrivate *priv = self->priv;
-
- switch (prop_id) {
- case PROP_PATH:
- g_free(priv->path);
- priv->path = g_value_dup_string(value);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- }
-}
-
-
static void gvir_domain_interface_finalize(GObject *object)
{
GVirDomainInterface *self = GVIR_DOMAIN_INTERFACE(object);
- GVirDomainInterfacePrivate *priv = self->priv;
g_debug("Finalize GVirDomainInterface=%p", self);
- g_free(priv->path);
-
G_OBJECT_CLASS(gvir_domain_interface_parent_class)->finalize(object);
}
@@ -111,19 +63,6 @@ static void gvir_domain_interface_class_init(GVirDomainInterfaceClass
*klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gvir_domain_interface_finalize;
- object_class->get_property = gvir_domain_interface_get_property;
- object_class->set_property = gvir_domain_interface_set_property;
-
- g_object_class_install_property(object_class,
- PROP_PATH,
- g_param_spec_string("path",
- "Path",
- "The interface path",
- NULL,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
-
g_type_class_add_private(klass, sizeof(GVirDomainInterfacePrivate));
}
@@ -140,17 +79,24 @@ gvir_domain_interface_stats_copy(GVirDomainInterfaceStats *stats)
return g_slice_dup(GVirDomainInterfaceStats, stats);
}
-
static void
gvir_domain_interface_stats_free(GVirDomainInterfaceStats *stats)
{
g_slice_free(GVirDomainInterfaceStats, stats);
}
-
G_DEFINE_BOXED_TYPE(GVirDomainInterfaceStats, gvir_domain_interface_stats,
gvir_domain_interface_stats_copy, gvir_domain_interface_stats_free)
+static gchar *gvir_domain_interface_get_path(GVirDomainInterface *self)
+{
+ GVirConfigDomainDevice *config;
+
+ config = gvir_domain_device_get_config(GVIR_DOMAIN_DEVICE(self));
Missing g_object_unref here too
+
+ return gvir_config_domain_interface_get_ifname (GVIR_CONFIG_DOMAIN_INTERFACE
(config));
+}
+
/**
* gvir_domain_interface_get_stats:
* @self: the domain interface
@@ -166,15 +112,15 @@ GVirDomainInterfaceStats
*gvir_domain_interface_get_stats(GVirDomainInterface *s
{
GVirDomainInterfaceStats *ret = NULL;
virDomainInterfaceStatsStruct stats;
- GVirDomainInterfacePrivate *priv;
virDomainPtr handle;
+ gchar *path;
g_return_val_if_fail(GVIR_IS_DOMAIN_INTERFACE(self), NULL);
- priv = self->priv;
handle = gvir_domain_device_get_domain_handle(GVIR_DOMAIN_DEVICE(self));
+ path = gvir_domain_interface_get_path (self);
- if (virDomainInterfaceStats(handle, priv->path, &stats, sizeof (stats)) <
0) {
+ if (virDomainInterfaceStats(handle, path, &stats, sizeof (stats)) < 0) {
gvir_set_error_literal(err, GVIR_DOMAIN_INTERFACE_ERROR,
0,
"Unable to get domain interface stats");
@@ -193,5 +139,6 @@ GVirDomainInterfaceStats
*gvir_domain_interface_get_stats(GVirDomainInterface *s
end:
virDomainFree(handle);
+ g_free(path);
return ret;
}
ACK with these issues fixed.
Christophe
--
1.7.7.6
--
libvir-list mailing list
libvir-list(a)redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list