[libgovirt] storage-domain: Add support for 'files' subcollection



commit 443ffb63c2fca8cef3c4c83f169bce0a75313578
Author: Christophe Fergeau <cfergeau redhat com>
Date:   Wed Aug 21 18:01:56 2013 +0200

    storage-domain: Add support for 'files' subcollection

 govirt/govirt.sym             |    2 +
 govirt/ovirt-storage-domain.c |   49 +++++++++++++++++++++++++++++++++++++++++
 govirt/ovirt-storage-domain.h |    3 ++
 3 files changed, 54 insertions(+), 0 deletions(-)
---
diff --git a/govirt/govirt.sym b/govirt/govirt.sym
index a04bcc6..4faef2c 100644
--- a/govirt/govirt.sym
+++ b/govirt/govirt.sym
@@ -69,6 +69,8 @@ GOVIRT_0.2.1 {
         ovirt_storage_domain_format_version_get_type;
         ovirt_storage_domain_type_get_type;
         ovirt_storage_domain_new;
+
+        ovirt_storage_domain_get_files;
 } GOVIRT_0.2.0;
 
 
diff --git a/govirt/ovirt-storage-domain.c b/govirt/ovirt-storage-domain.c
index 22d9df2..1012007 100644
--- a/govirt/ovirt-storage-domain.c
+++ b/govirt/ovirt-storage-domain.c
@@ -29,6 +29,8 @@
         (G_TYPE_INSTANCE_GET_PRIVATE((obj), OVIRT_TYPE_STORAGE_DOMAIN, OvirtStorageDomainPrivate))
 
 struct _OvirtStorageDomainPrivate {
+    OvirtCollection *files;
+
     OvirtStorageDomainType type;
     gboolean is_master;
     guint64 available;
@@ -125,6 +127,18 @@ static void ovirt_storage_domain_set_property(GObject *object,
     }
 }
 
+
+static void
+ovirt_storage_domain_dispose(GObject *obj)
+{
+    OvirtStorageDomain *domain = OVIRT_STORAGE_DOMAIN(obj);
+
+    g_clear_object(&domain->priv->files);
+
+    G_OBJECT_CLASS(ovirt_storage_domain_parent_class)->dispose(obj);
+}
+
+
 static gboolean ovirt_storage_domain_init_from_xml(OvirtResource *resource,
                                                    RestXmlNode *node,
                                                    GError **error)
@@ -143,6 +157,7 @@ static gboolean ovirt_storage_domain_init_from_xml(OvirtResource *resource,
     return parent_class->init_from_xml(resource, node, error);
 }
 
+
 static void ovirt_storage_domain_class_init(OvirtStorageDomainClass *klass)
 {
     GObjectClass *object_class = G_OBJECT_CLASS(klass);
@@ -152,6 +167,7 @@ static void ovirt_storage_domain_class_init(OvirtStorageDomainClass *klass)
     g_type_class_add_private(klass, sizeof(OvirtStorageDomainPrivate));
 
     resource_class->init_from_xml = ovirt_storage_domain_init_from_xml;
+    object_class->dispose = ovirt_storage_domain_dispose;
     object_class->get_property = ovirt_storage_domain_get_property;
     object_class->set_property = ovirt_storage_domain_set_property;
 
@@ -332,3 +348,36 @@ ovirt_storage_domain_refresh_from_xml(OvirtStorageDomain *domain,
 
     return ovirt_resource_parse_xml(OVIRT_RESOURCE(domain), node, storage_domain_elements);
 }
+
+
+/**
+ * ovirt_storage_domain_get_files:
+ * @domain: a #OvirtStorageDomain
+ *
+ * Gets a #OvirtCollection representing the list of remote files from a
+ * storage domain object.  This method does not initiate any network
+ * activity, the remote file list must be then be fetched using
+ * ovirt_collection_fetch() or ovirt_collection_fetch_async().
+ *
+ * Return value: (transfer full): a #OvirtCollection representing the list
+ * of files associated with @domain.
+ */
+OvirtCollection *ovirt_storage_domain_get_files(OvirtStorageDomain *domain)
+{
+    const char *href;
+
+    g_return_val_if_fail(OVIRT_IS_STORAGE_DOMAIN(domain), NULL);
+
+    if (domain->priv->files != NULL)
+        return domain->priv->files;
+
+    href = ovirt_resource_get_sub_collection(OVIRT_RESOURCE(domain), "files");
+    if (href == NULL)
+        return NULL;
+
+    domain->priv->files = ovirt_collection_new(href, "files",
+                                               OVIRT_TYPE_RESOURCE,
+                                               "file");
+
+    return domain->priv->files;
+}
diff --git a/govirt/ovirt-storage-domain.h b/govirt/ovirt-storage-domain.h
index ddd78c0..85b18e1 100644
--- a/govirt/ovirt-storage-domain.h
+++ b/govirt/ovirt-storage-domain.h
@@ -24,6 +24,7 @@
 
 #include <gio/gio.h>
 #include <glib-object.h>
+#include <govirt/ovirt-collection.h>
 #include <govirt/ovirt-resource.h>
 #include <govirt/ovirt-types.h>
 
@@ -82,6 +83,8 @@ GType ovirt_storage_domain_get_type(void);
 
 OvirtStorageDomain *ovirt_storage_domain_new(void);
 
+OvirtCollection *ovirt_storage_domain_get_files(OvirtStorageDomain *domain);
+
 G_END_DECLS
 
 #endif /* __OVIRT_STORAGE_DOMAIN_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]