[Libvirt-cim] [PATCH] [CU] Add set_int_property() function to EO parse

Kaitlin Rupert kaitlin at linux.vnet.ibm.com
Wed Feb 27 16:44:16 UTC 2008


# HG changeset patch
# User Kaitlin Rupert <karupert at us.ibm.com>
# Date 1204130653 28800
# Node ID 64e51763141e107bc89710897ea9dc9c2fc08dbc
# Parent  e5931f33c94eb4895a359538b53cd1a1d075bb53
[CU] Add set_int_property() function to EO parse.

This function attempts to find the appropriate property value type and then sets that property value.

This change is needed to properly parse non 64 bit integer.  If the property is a uint16 value, and CMPI_uint64 is passed CMSetProperty(), the call will fail.

Signed-off-by: Kaitlin Rupert <karupert at us.ibm.com>

diff -r e5931f33c94e -r 64e51763141e eo_parser.c
--- a/eo_parser.c	Thu Feb 21 07:44:01 2008 -0800
+++ b/eo_parser.c	Wed Feb 27 08:44:13 2008 -0800
@@ -107,6 +107,62 @@ int cu_parse_embedded_instance(const cha
         }
 }
 
+static int _set_int_prop(CMPISint64 value,
+                         char *prop,
+                         CMPIType type,
+                         CMPIInstance *inst)
+{
+        CMPIStatus s;
+        uint64_t unsigned_val = 0;
+        int64_t signed_val = 0;
+           
+        switch(type) {
+        case CMPI_uint64:
+        case CMPI_uint32:
+        case CMPI_uint16:
+        case CMPI_uint8:
+                unsigned_val = value;
+                s = CMSetProperty(inst, prop, &(unsigned_val), type);
+                break;
+        case CMPI_sint64:
+        case CMPI_sint32:
+        case CMPI_sint16:
+        case CMPI_sint8:
+        default:
+                signed_val = value;
+                s = CMSetProperty(inst, prop, &(signed_val), type);
+        }
+
+        if (s.rc == CMPI_RC_OK)
+               return 1;
+
+        return 0;
+}
+
+CMPIType set_int_prop(CMPISint64 value,
+                      char *prop,
+                      CMPIInstance *inst)
+{
+        if (_set_int_prop(value, prop, CMPI_uint64, inst) == 1)
+               return CMPI_uint64;
+        else if (_set_int_prop(value, prop, CMPI_uint32, inst) == 1) 
+               return CMPI_uint32;
+        else if (_set_int_prop(value, prop, CMPI_uint16, inst) == 1) 
+               return CMPI_uint16;
+        else if (_set_int_prop(value, prop, CMPI_uint8, inst) == 1)
+               return CMPI_uint8;
+        else if (_set_int_prop(value, prop, CMPI_sint64, inst) == 1)
+               return CMPI_sint64;
+        else if (_set_int_prop(value, prop, CMPI_sint32, inst) == 1) 
+               return CMPI_sint32;
+        else if (_set_int_prop(value, prop, CMPI_sint16, inst) == 1) 
+               return CMPI_sint16;
+        else
+               _set_int_prop(value, prop, CMPI_sint8, inst);
+
+        return CMPI_sint8;
+}
+
 /*
  * Local Variables:
  * mode: C
diff -r e5931f33c94e -r 64e51763141e eo_parser_xml.h
--- a/eo_parser_xml.h	Thu Feb 21 07:44:01 2008 -0800
+++ b/eo_parser_xml.h	Wed Feb 27 08:44:13 2008 -0800
@@ -27,6 +27,10 @@ int cu_parse_ei_xml(const CMPIBroker *br
                     const char *xml,
                     CMPIInstance **instance);
 
+CMPIType set_int_prop(CMPISint64 value,
+                      char *prop,
+                      CMPIInstance *inst);
+
 #endif
 
 /*
diff -r e5931f33c94e -r 64e51763141e eo_util_parser.y
--- a/eo_util_parser.y	Thu Feb 21 07:44:01 2008 -0800
+++ b/eo_util_parser.y	Wed Feb 27 08:44:13 2008 -0800
@@ -10,9 +10,12 @@
 %{
 #include <stdlib.h>
 #include <stdio.h>
+#include <stdint.h>
 
 #include "cmpidt.h"
 #include "cmpift.h"
+
+#include "eo_parser_xml.h"
 
     /* specify prototypes to get rid of warnings */
 int eo_parse_lex (void);
@@ -103,12 +106,12 @@ property:	PROPERTYNAME '=' STRING ';'
 
 	|	PROPERTYNAME '=' INTEGER ';'
 			{
-			EOTRACE("propertyname = %s"
-				"\ttype = CMPI_sint64\n"
-				"\tvalue = %lld\n",
-				$1, $3);
-			unsigned long long value = $3;
-			CMSetProperty(*_INSTANCE, $1, &(value), CMPI_uint64);
+			EOTRACE("propertyname = %s\n", $1); 
+                        int rc;
+			//uint64_t value = $3;
+                        CMPIType t = set_int_prop($3, $1, *_INSTANCE);
+			EOTRACE("\ttype = %d\n"
+                                "\tvalue = %lld\n", t, $3); 
 			free($1);
 			}
 




More information about the Libvirt-cim mailing list