# HG changeset patch
# User Jay Gagnon <grendel(a)linux.vnet.ibm.com>
# Date 1202245292 18000
# Node ID 493b8a943286a780e2fb7c2829cd49e60ccaa264
# Parent ab0e3b05a10e7b5db7eb493920f01bb402d2feae
[CU] Add dup_instance function to libcmpiutil
It appears there are some situations where we have to duplicate an instance; this seemed
like the kind of thing that would belong in libcmpiutil.
Changes from #1 to #2:
cu dup_instance returns instance, sets status using pointer
cu_dup_instance copies all properties
Changes from #2 to #3:
use CMGetCharPtr instead of doing char * cast manually
Signed-off-by: Jay Gagnon <grendel(a)linux.vnet.ibm.com>
diff -r ab0e3b05a10e -r 493b8a943286 instance_util.c
--- a/instance_util.c Wed Jan 30 11:15:32 2008 -0800
+++ b/instance_util.c Tue Feb 05 16:01:32 2008 -0500
@@ -202,6 +202,55 @@ CMPIStatus cu_copy_prop(const CMPIBroker
out:
return s;
+}
+
+CMPIInstance *cu_dup_instance(const CMPIBroker *broker,
+ CMPIInstance *src,
+ CMPIStatus *s)
+{
+ int i;
+ int prop_count;
+ CMPIData data;
+ CMPIObjectPath *ref;
+ CMPIInstance *dest = NULL;
+
+ ref = CMGetObjectPath(src, NULL);
+ if ((s->rc != CMPI_RC_OK) || CMIsNullObject(ref)) {
+ cu_statusf(broker, s,
+ CMPI_RC_ERR_FAILED,
+ "Could not get objectpath from instance");
+ goto out;
+ }
+
+ dest = CMNewInstance(broker, ref, s);
+
+ prop_count = CMGetPropertyCount(src, s);
+ if (s->rc != CMPI_RC_OK) {
+ cu_statusf(broker, s,
+ CMPI_RC_ERR_FAILED,
+ "Could not get property count for copy");
+ goto out;
+ }
+
+ for (i = 0; i < prop_count; i++) {
+ CMPIString *prop;
+ char *prop_name;
+
+ data = CMGetPropertyAt(src, i, &prop, s);
+ prop_name = CMGetCharPtr(prop);
+ if (s->rc != CMPI_RC_OK) {
+ goto out;
+ }
+
+ *s = CMSetProperty(dest, prop_name,
+ &(data.value), data.type);
+ if (s->rc != CMPI_RC_OK) {
+ goto out;
+ }
+ }
+
+ out:
+ return dest;
}
/*
diff -r ab0e3b05a10e -r 493b8a943286 libcmpiutil.h
--- a/libcmpiutil.h Wed Jan 30 11:15:32 2008 -0800
+++ b/libcmpiutil.h Tue Feb 05 16:01:32 2008 -0500
@@ -164,6 +164,18 @@ CMPIrc cu_get_u16_path(const CMPIObjectP
CMPIrc cu_get_u16_path(const CMPIObjectPath *reference,
const char *key,
uint16_t *target);
+
+/**
+ * Create a copy of an instance
+ *
+ * @param src Source instance
+ * @param dest Destination instance
+ * @returns {CMPI_RC_OK, NULL} if success, CMPI_RC ERR_FAILED and
+ * error message otherwise
+ */
+CMPIInstance *cu_dup_instance(const CMPIBroker *broker,
+ CMPIInstance *src,
+ CMPIStatus *s);
/* Forward declaration */
struct inst_list;