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

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@us.ibm.com # HG changeset patch # User Jay Gagnon <grendel@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@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)

Dan Smith wrote:
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.
This patch looks good to me, fwiw. =) -- Kaitlin Rupert IBM Linux Technology Center karupert@us.ibm.com

Dan Smith wrote:
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.
Heh, you forgot "and Jay has repeatedly forgot to send along with the patch that uses it." Thanks for taking care of that for me. :) -- -Jay
participants (3)
-
Dan Smith
-
Jay Gagnon
-
Kaitlin Rupert