[libgovirt] api: Implement ovirt_api_get_vms()



commit e4c0f69645ef78009ecac8099eea1bc4e1415bec
Author: Christophe Fergeau <cfergeau redhat com>
Date:   Fri Aug 23 15:23:43 2013 +0200

    api: Implement ovirt_api_get_vms()
    
    This returns an OvirtCollection that can then be used to fetch
    the actual list of VMs. Having the fetching code in a generic
    OvirtCollection class avoids to have multiple ovirt_api_fetch_xxx()
    methods for each collectionb, as well as the async variants.

 govirt/govirt.sym  |    1 +
 govirt/ovirt-api.c |   42 +++++++++++++++++++++++++++++++++++++++++-
 govirt/ovirt-api.h |    3 +++
 3 files changed, 45 insertions(+), 1 deletions(-)
---
diff --git a/govirt/govirt.sym b/govirt/govirt.sym
index 9e16573..e23a17f 100644
--- a/govirt/govirt.sym
+++ b/govirt/govirt.sym
@@ -52,6 +52,7 @@ GOVIRT_0.2.0 {
 GOVIRT_0.2.1 {
         ovirt_api_get_type;
         ovirt_api_new;
+        ovirt_api_get_vms;
 
         ovirt_collection_fetch;
         ovirt_collection_fetch_async;
diff --git a/govirt/ovirt-api.c b/govirt/ovirt-api.c
index cb3048b..31a9e48 100644
--- a/govirt/ovirt-api.c
+++ b/govirt/ovirt-api.c
@@ -39,7 +39,7 @@
 
 
 struct _OvirtApiPrivate {
-    gboolean unused;
+    OvirtCollection *vms;
 };
 
 
@@ -64,12 +64,26 @@ static gboolean ovirt_api_init_from_xml(OvirtResource *resource,
     return parent_class->init_from_xml(resource, node, error);
 }
 
+
+static void ovirt_api_dispose(GObject *object)
+{
+    OvirtApi *api = OVIRT_API(object);
+
+    g_clear_object(&api->priv->vms);
+
+    G_OBJECT_CLASS(ovirt_api_parent_class)->dispose(object);
+}
+
+
 static void ovirt_api_class_init(OvirtApiClass *klass)
 {
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
     OvirtResourceClass *resource_class = OVIRT_RESOURCE_CLASS(klass);
 
     g_type_class_add_private(klass, sizeof(OvirtApiPrivate));
 
+    object_class->dispose = ovirt_api_dispose;
+
     resource_class->init_from_xml = ovirt_api_init_from_xml;
 }
 
@@ -84,7 +98,33 @@ OvirtApi *ovirt_api_new_from_xml(RestXmlNode *node, GError **error)
                                    "xml-node", node, NULL));
 }
 
+
 OvirtApi *ovirt_api_new(void)
 {
     return OVIRT_API(g_initable_new(OVIRT_TYPE_API, NULL, NULL, NULL));
 }
+
+
+/**
+ * ovirt_api_get_vms:
+ * @api: a #OvirtApi
+ *
+ * Return value: (transfer full):
+ */
+OvirtCollection *ovirt_api_get_vms(OvirtApi *api)
+{
+    const char *href;
+
+    g_return_val_if_fail(OVIRT_IS_API(api), NULL);
+
+    if (api->priv->vms != NULL)
+        return api->priv->vms;
+
+    href = ovirt_resource_get_sub_collection(OVIRT_RESOURCE(api), "vms");
+    if (href == NULL)
+        return NULL;
+
+    api->priv->vms = ovirt_collection_new(href, "vms", OVIRT_TYPE_VM, "vm");
+
+    return api->priv->vms;
+}
diff --git a/govirt/ovirt-api.h b/govirt/ovirt-api.h
index d28328a..2fdce69 100644
--- a/govirt/ovirt-api.h
+++ b/govirt/ovirt-api.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>
 
@@ -60,6 +61,8 @@ struct _OvirtApiClass
 GType ovirt_api_get_type(void);
 OvirtApi *ovirt_api_new(void);
 
+OvirtCollection *ovirt_api_get_vms(OvirtApi *api);
+
 G_END_DECLS
 
 #endif /* __OVIRT_API_H__ */


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