[libvirt-glib 2/2] Allow unsetting of object properties

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

 



From: "Zeeshan Ali (Khattak)" <zeeshanak@xxxxxxxxx>

This changes gvir_config_object_attach_replace to accept a NULL
child object. Since we need to be able to find the node to remove
when this happens, gvir_config_object_attach_replace gets a third
argument with the name of the node to add/remove.
---
 .../libvirt-gconfig-domain-controller.c            |    9 ++++--
 libvirt-gconfig/libvirt-gconfig-domain-redirdev.c  |    9 ++++--
 libvirt-gconfig/libvirt-gconfig-domain.c           |   34 ++++++++++++++++----
 libvirt-gconfig/libvirt-gconfig-object-private.h   |    1 +
 libvirt-gconfig/libvirt-gconfig-object.c           |   11 +++++--
 .../libvirt-gconfig-storage-pool-target.c          |   10 ++++--
 libvirt-gconfig/libvirt-gconfig-storage-pool.c     |   20 +++++++++---
 .../libvirt-gconfig-storage-vol-target.c           |   10 ++++--
 libvirt-gconfig/libvirt-gconfig-storage-vol.c      |   20 +++++++++---
 9 files changed, 100 insertions(+), 24 deletions(-)

diff --git a/libvirt-gconfig/libvirt-gconfig-domain-controller.c b/libvirt-gconfig/libvirt-gconfig-domain-controller.c
index 2024b54..4fed84c 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-controller.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-controller.c
@@ -115,12 +115,17 @@ guint gvir_config_domain_controller_get_index(GVirConfigDomainController *contro
     return index;
 }
 
+/**
+ * gvir_config_domain_controller_set_address:
+ * @address: (allow-none):
+ */
 void gvir_config_domain_controller_set_address(GVirConfigDomainController *controller,
                                                GVirConfigDomainAddress *address)
 {
     g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_CONTROLLER(controller));
-    g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS(address));
+    g_return_if_fail(address == NULL || GVIR_CONFIG_IS_DOMAIN_ADDRESS(address));
 
     gvir_config_object_attach_replace(GVIR_CONFIG_OBJECT(controller),
-                                      GVIR_CONFIG_OBJECT(address));
+                                      "address",
+                                      (GVirConfigObject *)address);
 }
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-redirdev.c b/libvirt-gconfig/libvirt-gconfig-domain-redirdev.c
index efecb5a..435abff 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-redirdev.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-redirdev.c
@@ -81,12 +81,17 @@ void gvir_config_domain_redirdev_set_bus(GVirConfigDomainRedirdev *redirdev,
                                                NULL);
 }
 
+/**
+ * gvir_config_domain_redirdev_set_address:
+ * @address: (allow-none):
+ */
 void gvir_config_domain_redirdev_set_address(GVirConfigDomainRedirdev *redirdev,
                                              GVirConfigDomainAddress *address)
 {
     g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_REDIRDEV(redirdev));
-    g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS(address));
+    g_return_if_fail(address == NULL || GVIR_CONFIG_IS_DOMAIN_ADDRESS(address));
 
     gvir_config_object_attach_replace(GVIR_CONFIG_OBJECT(redirdev),
-                                      GVIR_CONFIG_OBJECT(address));
+                                      "address",
+                                      (GVirConfigObject *)address);
 }
diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c
index d100009..52ce0ef 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain.c
@@ -321,14 +321,19 @@ void gvir_config_domain_set_features(GVirConfigDomain *domain,
     g_object_notify(G_OBJECT(domain), "features");
 }
 
+/**
+ * gvir_config_domain_set_clock:
+ * @klock: (allow-none):
+ */
 void gvir_config_domain_set_clock(GVirConfigDomain *domain,
                                   GVirConfigDomainClock *klock)
 {
     g_return_if_fail(GVIR_CONFIG_IS_DOMAIN(domain));
-    g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_CLOCK(klock));
+    g_return_if_fail(klock != NULL || GVIR_CONFIG_IS_DOMAIN_CLOCK(klock));
 
     gvir_config_object_attach_replace(GVIR_CONFIG_OBJECT(domain),
-                                      GVIR_CONFIG_OBJECT(klock));
+                                      "clock",
+                                      (GVirConfigObject *)klock);
 }
 
 /**
@@ -349,24 +354,35 @@ GVirConfigDomainOs *gvir_config_domain_get_os(GVirConfigDomain *domain)
     return GVIR_CONFIG_DOMAIN_OS(object);
 }
 
+/**
+ * gvir_config_domain_set_os:
+ * @os: (allow-none):
+ */
 void gvir_config_domain_set_os(GVirConfigDomain *domain,
                                GVirConfigDomainOs *os)
 {
     g_return_if_fail(GVIR_CONFIG_IS_DOMAIN(domain));
-    g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_OS(os));
+    g_return_if_fail(os == NULL || GVIR_CONFIG_IS_DOMAIN_OS(os));
 
     gvir_config_object_attach_replace(GVIR_CONFIG_OBJECT(domain),
-                                      GVIR_CONFIG_OBJECT(os));
+                                      "os",
+                                      (GVirConfigObject *)os);
 }
 
+/**
+ * gvir_config_domain_set_seclabel:
+ * @seclabel: (allow-none):
+ */
 void gvir_config_domain_set_seclabel(GVirConfigDomain *domain,
                                      GVirConfigDomainSeclabel *seclabel)
 {
     g_return_if_fail(GVIR_CONFIG_IS_DOMAIN(domain));
-    g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_SECLABEL(seclabel));
+    g_return_if_fail(seclabel == NULL ||
+                     GVIR_CONFIG_IS_DOMAIN_SECLABEL(seclabel));
 
     gvir_config_object_attach_replace(GVIR_CONFIG_OBJECT(domain),
-                                      GVIR_CONFIG_OBJECT(seclabel));
+                                      "seclabel",
+                                      (GVirConfigObject *)seclabel);
 }
 
 void gvir_config_domain_set_lifecycle(GVirConfigDomain *domain,
@@ -402,8 +418,13 @@ void gvir_config_domain_set_devices(GVirConfigDomain *domain,
 
     g_return_if_fail(GVIR_CONFIG_IS_DOMAIN(domain));
 
+    if (devices == NULL) {
+        gvir_config_object_delete_children(GVIR_CONFIG_OBJECT(domain), "devices", NULL);
+        return;
+    }
     devices_node = gvir_config_object_new(GVIR_CONFIG_TYPE_OBJECT,
                                           "devices", NULL);
+
     for (it = devices; it != NULL; it = it->next) {
         if (!GVIR_CONFIG_IS_DOMAIN_DEVICE(it->data)) {
             g_warn_if_reached();
@@ -414,6 +435,7 @@ void gvir_config_domain_set_devices(GVirConfigDomain *domain,
     }
 
     gvir_config_object_attach_replace(GVIR_CONFIG_OBJECT(domain),
+                                      "devices",
                                       devices_node);
     g_object_unref(G_OBJECT(devices_node));
 }
diff --git a/libvirt-gconfig/libvirt-gconfig-object-private.h b/libvirt-gconfig/libvirt-gconfig-object-private.h
index eb2cc09..a22b945 100644
--- a/libvirt-gconfig/libvirt-gconfig-object-private.h
+++ b/libvirt-gconfig/libvirt-gconfig-object-private.h
@@ -85,6 +85,7 @@ void gvir_config_object_set_child(GVirConfigObject *object,
 void gvir_config_object_attach_add(GVirConfigObject *parent,
                                    GVirConfigObject *child);
 void gvir_config_object_attach_replace(GVirConfigObject *parent,
+                                       const char *child_name,
                                        GVirConfigObject *child);
 void gvir_config_object_set_attribute(GVirConfigObject *object,
                                       ...) G_GNUC_NULL_TERMINATED;
diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c
index 288bbc4..76e3134 100644
--- a/libvirt-gconfig/libvirt-gconfig-object.c
+++ b/libvirt-gconfig/libvirt-gconfig-object.c
@@ -839,9 +839,16 @@ gvir_config_object_attach(GVirConfigObject *parent, GVirConfigObject *child, gbo
 }
 
 G_GNUC_INTERNAL void
-gvir_config_object_attach_replace(GVirConfigObject *parent, GVirConfigObject *child)
+gvir_config_object_attach_replace(GVirConfigObject *parent,
+                                  const char *child_name,
+                                  GVirConfigObject *child)
 {
-    gvir_config_object_attach(parent, child, TRUE);
+    g_return_if_fail(child_name != NULL);
+
+    if (child == NULL)
+        gvir_config_object_delete_children(parent, child_name, NULL);
+    else
+        gvir_config_object_attach(parent, child, TRUE);
 }
 
 G_GNUC_INTERNAL void
diff --git a/libvirt-gconfig/libvirt-gconfig-storage-pool-target.c b/libvirt-gconfig/libvirt-gconfig-storage-pool-target.c
index bf97194..cd8c9ee 100644
--- a/libvirt-gconfig/libvirt-gconfig-storage-pool-target.c
+++ b/libvirt-gconfig/libvirt-gconfig-storage-pool-target.c
@@ -84,12 +84,18 @@ void gvir_config_storage_pool_target_set_path(GVirConfigStoragePoolTarget *targe
                                         "path", path);
 }
 
+/**
+ * gvir_config_storage_pool_perms_set_permissions:
+ * @perms: (allow-none):
+ */
 void gvir_config_storage_pool_target_set_permissions(GVirConfigStoragePoolTarget *target,
                                                      GVirConfigStoragePermissions *perms)
 {
     g_return_if_fail(GVIR_CONFIG_IS_STORAGE_POOL_TARGET(target));
-    g_return_if_fail(GVIR_CONFIG_IS_STORAGE_PERMISSIONS(perms));
+    g_return_if_fail(perms == NULL ||
+                     GVIR_CONFIG_IS_STORAGE_PERMISSIONS(perms));
 
     gvir_config_object_attach_replace(GVIR_CONFIG_OBJECT(target),
-                                      GVIR_CONFIG_OBJECT(perms));
+                                      "permissions",
+                                      (GVirConfigObject *)perms);
 }
diff --git a/libvirt-gconfig/libvirt-gconfig-storage-pool.c b/libvirt-gconfig/libvirt-gconfig-storage-pool.c
index 1bbcfe9..1ea410a 100644
--- a/libvirt-gconfig/libvirt-gconfig-storage-pool.c
+++ b/libvirt-gconfig/libvirt-gconfig-storage-pool.c
@@ -139,22 +139,34 @@ void gvir_config_storage_pool_set_available(GVirConfigStoragePool *pool,
                                                "available", available);
 }
 
+/**
+ * gvir_config_storage_pool_set_source:
+ * @source: (allow-none):
+ */
 void gvir_config_storage_pool_set_source(GVirConfigStoragePool *pool,
                                          GVirConfigStoragePoolSource *source)
 {
     g_return_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool));
-    g_return_if_fail(GVIR_CONFIG_IS_STORAGE_POOL_SOURCE(source));
+    g_return_if_fail(source == NULL ||
+                     GVIR_CONFIG_IS_STORAGE_POOL_SOURCE(source));
 
     gvir_config_object_attach_replace(GVIR_CONFIG_OBJECT(pool),
-                                      GVIR_CONFIG_OBJECT(source));
+                                      "source",
+                                      (GVirConfigObject *)source);
 }
 
+/**
+ * gvir_config_storage_pool_set_target:
+ * @target: (allow-none):
+ */
 void gvir_config_storage_pool_set_target(GVirConfigStoragePool *pool,
                                         GVirConfigStoragePoolTarget *target)
 {
     g_return_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool));
-    g_return_if_fail(GVIR_CONFIG_IS_STORAGE_POOL_TARGET(target));
+    g_return_if_fail(target == NULL ||
+                     GVIR_CONFIG_IS_STORAGE_POOL_TARGET(target));
 
     gvir_config_object_attach_replace(GVIR_CONFIG_OBJECT(pool),
-                                      GVIR_CONFIG_OBJECT(target));
+                                      "target",
+                                      (GVirConfigObject *)target);
 }
diff --git a/libvirt-gconfig/libvirt-gconfig-storage-vol-target.c b/libvirt-gconfig/libvirt-gconfig-storage-vol-target.c
index 3786e2b..5ffcfe4 100644
--- a/libvirt-gconfig/libvirt-gconfig-storage-vol-target.c
+++ b/libvirt-gconfig/libvirt-gconfig-storage-vol-target.c
@@ -84,12 +84,18 @@ void gvir_config_storage_vol_target_set_format(GVirConfigStorageVolTarget *targe
     g_object_unref(G_OBJECT(node));
 }
 
+/**
+ * gvir_config_storage_vol_target_set_permissions:
+ * @perms: (allow-none):
+ */
 void gvir_config_storage_vol_target_set_permissions(GVirConfigStorageVolTarget *target,
                                                     GVirConfigStoragePermissions *perms)
 {
     g_return_if_fail(GVIR_CONFIG_IS_STORAGE_VOL_TARGET(target));
-    g_return_if_fail(GVIR_CONFIG_IS_STORAGE_PERMISSIONS(perms));
+    g_return_if_fail(perms == NULL ||
+                     GVIR_CONFIG_IS_STORAGE_PERMISSIONS(perms));
 
     gvir_config_object_attach_replace(GVIR_CONFIG_OBJECT(target),
-                                      GVIR_CONFIG_OBJECT(perms));
+                                      "permissions",
+                                      (GVirConfigObject *)perms);
 }
diff --git a/libvirt-gconfig/libvirt-gconfig-storage-vol.c b/libvirt-gconfig/libvirt-gconfig-storage-vol.c
index e20dca3..316ea9e 100644
--- a/libvirt-gconfig/libvirt-gconfig-storage-vol.c
+++ b/libvirt-gconfig/libvirt-gconfig-storage-vol.c
@@ -105,22 +105,34 @@ void gvir_config_storage_vol_set_allocation(GVirConfigStorageVol *vol,
                                                "allocation", allocation);
 }
 
+/**
+ * gvir_config_storage_vol_set_target:
+ * @target: (allow-none):
+ */
 void gvir_config_storage_vol_set_target(GVirConfigStorageVol *vol,
                                         GVirConfigStorageVolTarget *target)
 {
     g_return_if_fail(GVIR_CONFIG_IS_STORAGE_VOL(vol));
-    g_return_if_fail(GVIR_CONFIG_IS_STORAGE_VOL_TARGET(target));
+    g_return_if_fail(target == NULL ||
+                     GVIR_CONFIG_IS_STORAGE_VOL_TARGET(target));
 
     gvir_config_object_attach_replace(GVIR_CONFIG_OBJECT(vol),
-                                      GVIR_CONFIG_OBJECT(target));
+                                      "target",
+                                      (GVirConfigObject *)target);
 }
 
+/**
+ * gvir_config_storage_vol_set_backing_store:
+ * @backing_store: (allow-none):
+ */
 void gvir_config_storage_vol_set_backing_store(GVirConfigStorageVol *vol,
                                                GVirConfigStorageVolBackingStore *backing_store)
 {
     g_return_if_fail(GVIR_CONFIG_IS_STORAGE_VOL(vol));
-    g_return_if_fail(GVIR_CONFIG_IS_STORAGE_VOL_BACKING_STORE(backing_store));
+    g_return_if_fail(backing_store == NULL ||
+                     GVIR_CONFIG_IS_STORAGE_VOL_BACKING_STORE(backing_store));
 
     gvir_config_object_attach_replace(GVIR_CONFIG_OBJECT(vol),
-                                      GVIR_CONFIG_OBJECT(backing_store));
+                                      "backingStore",
+                                      (GVirConfigObject *)backing_store);
 }
-- 
1.7.10.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]