Blame SOURCES/0014-Introduce-auxiliary-function-ovirt_sub_collection_ne.patch

1bd27f
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
3e596a
From: "Eduardo Lima (Etrunko)" <etrunko@redhat.com>
3e596a
Date: Thu, 18 May 2017 16:45:37 -0300
3e596a
Subject: [PATCH] Introduce auxiliary function
3e596a
 ovirt_sub_collection_new_from_resource()
3e596a
3e596a
This function eliminates duplication of code used to create a
3e596a
subcollection from a resource. Users are updated accordingly.
3e596a
3e596a
Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
3e596a
---
1bd27f
 govirt/ovirt-api.c                | 50 +++++++++++--------------------
3e596a
 govirt/ovirt-collection-private.h |  5 ++++
1bd27f
 govirt/ovirt-collection.c         | 15 ++++++++++
1bd27f
 govirt/ovirt-storage-domain.c     | 18 ++++-------
1bd27f
 govirt/ovirt-vm.c                 | 18 ++++-------
3e596a
 5 files changed, 50 insertions(+), 56 deletions(-)
3e596a
3e596a
diff --git a/govirt/ovirt-api.c b/govirt/ovirt-api.c
1bd27f
index 001ee42..37c0935 100644
3e596a
--- a/govirt/ovirt-api.c
3e596a
+++ b/govirt/ovirt-api.c
1bd27f
@@ -123,18 +123,14 @@ OvirtApi *ovirt_api_new(void)
3e596a
  */
3e596a
 OvirtCollection *ovirt_api_get_vms(OvirtApi *api)
3e596a
 {
3e596a
-    const char *href;
3e596a
-
3e596a
     g_return_val_if_fail(OVIRT_IS_API(api), NULL);
3e596a
 
3e596a
-    if (api->priv->vms != NULL)
3e596a
-        return api->priv->vms;
3e596a
-
3e596a
-    href = ovirt_resource_get_sub_collection(OVIRT_RESOURCE(api), "vms");
3e596a
-    if (href == NULL)
3e596a
-        return NULL;
3e596a
-
3e596a
-    api->priv->vms = ovirt_collection_new(href, "vms", OVIRT_TYPE_VM, "vm");
3e596a
+    if (api->priv->vms == NULL)
3e596a
+        api->priv->vms = ovirt_sub_collection_new_from_resource(OVIRT_RESOURCE(api),
3e596a
+                                                                "vms",
3e596a
+                                                                "vms",
3e596a
+                                                                OVIRT_TYPE_VM,
3e596a
+                                                                "vm");
3e596a
 
3e596a
     return api->priv->vms;
3e596a
 }
1bd27f
@@ -151,18 +147,14 @@ OvirtCollection *ovirt_api_get_vms(OvirtApi *api)
3e596a
  */
3e596a
 OvirtCollection *ovirt_api_get_vm_pools(OvirtApi *api)
3e596a
 {
3e596a
-    const char *href;
3e596a
-
3e596a
     g_return_val_if_fail(OVIRT_IS_API(api), NULL);
3e596a
 
3e596a
-    if (api->priv->vm_pools != NULL)
3e596a
-        return api->priv->vm_pools;
3e596a
-
3e596a
-    href = ovirt_resource_get_sub_collection(OVIRT_RESOURCE(api), "vmpools");
3e596a
-    if (href == NULL)
3e596a
-        return NULL;
3e596a
-
3e596a
-    api->priv->vm_pools = ovirt_collection_new(href, "vmpools", OVIRT_TYPE_VM_POOL, "vmpool");
3e596a
+    if (api->priv->vm_pools == NULL)
3e596a
+        api->priv->vm_pools = ovirt_sub_collection_new_from_resource(OVIRT_RESOURCE(api),
3e596a
+                                                                     "vmpools",
3e596a
+                                                                     "vmpools",
3e596a
+                                                                     OVIRT_TYPE_VM_POOL,
3e596a
+                                                                     "vmpool");
3e596a
 
3e596a
     return api->priv->vm_pools;
3e596a
 }
1bd27f
@@ -180,20 +172,14 @@ OvirtCollection *ovirt_api_get_vm_pools(OvirtApi *api)
3e596a
  */
3e596a
 OvirtCollection *ovirt_api_get_storage_domains(OvirtApi *api)
3e596a
 {
3e596a
-    const char *href;
3e596a
-
3e596a
     g_return_val_if_fail(OVIRT_IS_API(api), NULL);
3e596a
 
3e596a
-    if (api->priv->storage_domains != NULL)
3e596a
-        return api->priv->storage_domains;
3e596a
-
3e596a
-    href = ovirt_resource_get_sub_collection(OVIRT_RESOURCE(api), "storagedomains");
3e596a
-    if (href == NULL)
3e596a
-        return NULL;
3e596a
-
3e596a
-    api->priv->storage_domains = ovirt_collection_new(href, "storage_domains",
3e596a
-                                                      OVIRT_TYPE_STORAGE_DOMAIN,
3e596a
-                                                      "storage_domain");
3e596a
+    if (api->priv->storage_domains == NULL)
3e596a
+        api->priv->storage_domains = ovirt_sub_collection_new_from_resource(OVIRT_RESOURCE(api),
3e596a
+                                                                            "storagedomains",
3e596a
+                                                                            "storage_domains",
3e596a
+                                                                            OVIRT_TYPE_STORAGE_DOMAIN,
3e596a
+                                                                            "storage_domain");
3e596a
 
3e596a
     return api->priv->storage_domains;
3e596a
 }
3e596a
diff --git a/govirt/ovirt-collection-private.h b/govirt/ovirt-collection-private.h
3e596a
index 5bc294f..d955fc6 100644
3e596a
--- a/govirt/ovirt-collection-private.h
3e596a
+++ b/govirt/ovirt-collection-private.h
3e596a
@@ -41,6 +41,11 @@ OvirtCollection *ovirt_collection_new_from_xml(RestXmlNode *root_node,
3e596a
                                                GType resource_type,
3e596a
                                                const char *resource_name,
3e596a
                                                GError **error);
3e596a
+OvirtCollection *ovirt_sub_collection_new_from_resource(OvirtResource *resource,
3e596a
+                                                        const char *href,
3e596a
+                                                        const char *collection_name,
3e596a
+                                                        GType resource_type,
3e596a
+                                                        const char *resource_name);
3e596a
 
3e596a
 G_END_DECLS
3e596a
 
3e596a
diff --git a/govirt/ovirt-collection.c b/govirt/ovirt-collection.c
1bd27f
index a3b0f3f..6ec1c6e 100644
3e596a
--- a/govirt/ovirt-collection.c
3e596a
+++ b/govirt/ovirt-collection.c
1bd27f
@@ -344,6 +344,21 @@ OvirtCollection *ovirt_collection_new_from_xml(RestXmlNode *root_node,
3e596a
 }
3e596a
 
3e596a
 
3e596a
+OvirtCollection *ovirt_sub_collection_new_from_resource(OvirtResource *resource,
3e596a
+                                                        const char *href,
3e596a
+                                                        const char *collection_name,
3e596a
+                                                        GType resource_type,
3e596a
+                                                        const char *resource_name)
3e596a
+{
3e596a
+    const char *link = ovirt_resource_get_sub_collection(resource, href);
3e596a
+
3e596a
+    if (link == NULL)
3e596a
+        return NULL;
3e596a
+
3e596a
+    return ovirt_collection_new(link, collection_name, resource_type, resource_name);
3e596a
+}
3e596a
+
3e596a
+
3e596a
 /**
3e596a
  * ovirt_collection_fetch:
3e596a
  * @collection: a #OvirtCollection
3e596a
diff --git a/govirt/ovirt-storage-domain.c b/govirt/ovirt-storage-domain.c
3e596a
index 0582203..38c4a62 100644
3e596a
--- a/govirt/ovirt-storage-domain.c
3e596a
+++ b/govirt/ovirt-storage-domain.c
3e596a
@@ -317,20 +317,14 @@ OvirtStorageDomain *ovirt_storage_domain_new(void)
3e596a
  */
3e596a
 OvirtCollection *ovirt_storage_domain_get_files(OvirtStorageDomain *domain)
3e596a
 {
3e596a
-    const char *href;
3e596a
-
3e596a
     g_return_val_if_fail(OVIRT_IS_STORAGE_DOMAIN(domain), NULL);
3e596a
 
3e596a
-    if (domain->priv->files != NULL)
3e596a
-        return domain->priv->files;
3e596a
-
3e596a
-    href = ovirt_resource_get_sub_collection(OVIRT_RESOURCE(domain), "files");
3e596a
-    if (href == NULL)
3e596a
-        return NULL;
3e596a
-
3e596a
-    domain->priv->files = ovirt_collection_new(href, "files",
3e596a
-                                               OVIRT_TYPE_RESOURCE,
3e596a
-                                               "file");
3e596a
+    if (domain->priv->files == NULL)
3e596a
+        domain->priv->files = ovirt_sub_collection_new_from_resource(OVIRT_RESOURCE(domain),
3e596a
+                                                                     "files",
3e596a
+                                                                     "files",
3e596a
+                                                                     OVIRT_TYPE_RESOURCE,
3e596a
+                                                                     "file");
3e596a
 
3e596a
     return domain->priv->files;
3e596a
 }
3e596a
diff --git a/govirt/ovirt-vm.c b/govirt/ovirt-vm.c
1bd27f
index 9a07c2f..3d64649 100644
3e596a
--- a/govirt/ovirt-vm.c
3e596a
+++ b/govirt/ovirt-vm.c
1bd27f
@@ -329,20 +329,14 @@ gboolean ovirt_vm_refresh_finish(OvirtVm *vm,
3e596a
  */
3e596a
 OvirtCollection *ovirt_vm_get_cdroms(OvirtVm *vm)
3e596a
 {
3e596a
-    const char *href;
3e596a
-
3e596a
     g_return_val_if_fail(OVIRT_IS_VM(vm), NULL);
3e596a
 
3e596a
-    if (vm->priv->cdroms != NULL)
3e596a
-        return vm->priv->cdroms;
3e596a
-
3e596a
-    href = ovirt_resource_get_sub_collection(OVIRT_RESOURCE(vm), "cdroms");
3e596a
-    if (href == NULL)
3e596a
-        return NULL;
3e596a
-
3e596a
-    vm->priv->cdroms =  ovirt_collection_new(href, "cdroms",
3e596a
-                                             OVIRT_TYPE_CDROM,
3e596a
-                                             "cdrom");
3e596a
+    if (vm->priv->cdroms == NULL)
3e596a
+        vm->priv->cdroms = ovirt_sub_collection_new_from_resource(OVIRT_RESOURCE(vm),
3e596a
+                                                                  "cdroms",
3e596a
+                                                                  "cdroms",
3e596a
+                                                                  OVIRT_TYPE_CDROM,
3e596a
+                                                                  "cdrom");
3e596a
 
3e596a
     return vm->priv->cdroms;
3e596a
 }