[Libvirt-cim] [PATCH] Add new function cu_copy_prop, which copies a property from one instance to another

Dan Smith danms at us.ibm.com
Tue Nov 20 23:09:34 UTC 2007


This is Jay's cu_copy_prop() function, which I got privately and
forgot to put in the tree before his patch that uses it.  I'm going to
commit it now.

-- 
Dan Smith
IBM Linux Technology Center
Open Hypervisor Team
email: danms at us.ibm.com

# HG changeset patch
# User Jay Gagnon <grendel at linux.vnet.ibm.com>
# Date 1195502361 18000
# Node ID 805e9c0e7a9d3c7c6fe4e4f9546f48df5bd6c372
# Parent  d6f1b6d1296bbe43c4edcc35475a05eef570e806
Add new function cu_copy_prop, which copies a property from one instance to another.

Signed-off-by: Jay Gagnon <grendel at linux.vnet.ibm.com>

diff -r d6f1b6d1296b -r 805e9c0e7a9d instance_util.c
--- a/instance_util.c	Thu Nov 15 13:07:50 2007 -0800
+++ b/instance_util.c	Mon Nov 19 14:59:21 2007 -0500
@@ -156,6 +156,37 @@ const char *cu_compare_ref(const CMPIObj
         prop = NULL;
  out:
         return prop;
+}
+
+CMPIStatus cu_copy_prop(const CMPIBroker *broker,
+                        CMPIInstance *src_inst, CMPIInstance *dest_inst,
+                        char *src_name, char *dest_name)
+{
+        CMPIData data;
+        CMPIStatus s = {CMPI_RC_OK, NULL};
+
+        if (src_name == NULL) {
+                cu_statusf(broker, &s, 
+                           CMPI_RC_ERR_FAILED,
+                           "No property name given");
+                goto out;
+        }
+
+        if (dest_name == NULL)
+                dest_name = src_name;
+
+        data = CMGetProperty(src_inst, src_name, &s);
+        if (s.rc != CMPI_RC_OK || CMIsNullValue(data)) {
+                cu_statusf(broker, &s, 
+                           CMPI_RC_ERR_FAILED,
+                           "Copy failed.  Could not get prop '%s'.", src_name);
+                goto out;
+        }
+
+        CMSetProperty(dest_inst, dest_name, &(data.value), data.type);
+
+ out:
+        return s;        
 }

 /*
diff -r d6f1b6d1296b -r 805e9c0e7a9d libcmpiutil.h
--- a/libcmpiutil.h	Thu Nov 15 13:07:50 2007 -0800
+++ b/libcmpiutil.h	Mon Nov 19 14:59:21 2007 -0500
@@ -61,6 +61,20 @@
  *     If set to anything else, uses value as name of log file to fprintf to.
  */
 void debug_print(char *fmt, ...);
+
+/**
+ * Copies a property from one CMPIInstance to another.  If dest_name is NULL, 
+ * it is assumed to be the same as src_name.
+ *
+ * @param broker CIM broker, needed for status calls
+ * @param src_inst Instance to copy from
+ * @param dest_inst Instance to copy to
+ * @param src_name Name of property to be copied from src_inst
+ * @param dest_name Name of property to be copied to dest_inst
+ */
+CMPIStatus cu_copy_prop(const CMPIBroker *broker, 
+                        CMPIInstance *src_inst, CMPIInstance *dest_inst,
+                        char *src_name, char *dest_name);

 /**
  * Check arguments (names and count)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 188 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvirt-cim/attachments/20071120/ccbb98c4/attachment.sig>


More information about the Libvirt-cim mailing list