]> xenbits.xensource.com Git - libvirt.git/commitdiff
esx: Cleanup and refactor CastFromAnyType macros
authorMatthias Bolte <matthias.bolte@googlemail.com>
Sun, 10 Apr 2011 11:27:19 +0000 (13:27 +0200)
committerMatthias Bolte <matthias.bolte@googlemail.com>
Thu, 14 Apr 2011 15:03:42 +0000 (17:03 +0200)
Add CastFromAnyType functions for the String type.

src/esx/esx_vi_generator.py
src/esx/esx_vi_types.c
src/esx/esx_vi_types.h

index 622a34a0ebf47384185274a263be97654178316a..0fd84dd8f32a785bdaba529725376efa000bab72 100755 (executable)
@@ -773,12 +773,11 @@ class Object(Base):
         # cast from any type
         if self.features & Object.FEATURE__ANY_TYPE:
             source += "/* esxVI_%s_CastFromAnyType */\n" % self.name
-            source += "ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(%s,\n" % self.name
 
             if self.extended_by is None:
-                source += "{\n"
-                source += "})\n\n"
+                source += "ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(%s)\n\n" % self.name
             else:
+                source += "ESX_VI__TEMPLATE__DYNAMIC_CAST_FROM_ANY_TYPE(%s,\n" % self.name
                 source += "{\n"
 
                 for extended_by in self.extended_by:
index f3df2b5510ae343a4b317cd3241b945762fbbe55..f3cdf2aeb95a6a71877d9c2f9b9ff427f57909a4 100644 (file)
 
 
 
-#define ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(_type, _dispatch)                \
+#define ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE_EXTRA(_type, _dest_type, _extra, \
+                                                   _dest_extra)               \
     int                                                                       \
-    esxVI_##_type##_CastFromAnyType(esxVI_AnyType *anyType,                   \
-                                    esxVI_##_type **ptrptr)                   \
+    esxVI_##_type##_Cast##_dest_extra##FromAnyType(esxVI_AnyType *anyType,    \
+                                                   _dest_type **ptrptr)       \
     {                                                                         \
+        _dest_type *item;                                                     \
+                                                                              \
         if (anyType == NULL || ptrptr == NULL || *ptrptr != NULL) {           \
             ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",                        \
                          _("Invalid argument"));                              \
             return -1;                                                        \
         }                                                                     \
                                                                               \
-        switch (anyType->type) {                                              \
-          _dispatch                                                           \
+        item = *ptrptr;                                                       \
                                                                               \
-          case esxVI_Type_##_type:                                            \
-            break;                                                            \
+        _extra                                                                \
                                                                               \
-          default:                                                            \
+        return esxVI_##_type##_Deserialize##_dest_extra(anyType->node,        \
+                                                        ptrptr);              \
+    }
+
+
+
+#define ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(_type)                           \
+    ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE_EXTRA(_type, esxVI_##_type,          \
+    {                                                                         \
+        if (anyType->type != esxVI_Type_##_type) {                            \
             ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,                              \
                          _("Call to %s for unexpected type '%s'"),            \
                          __FUNCTION__, anyType->other);                       \
             return -1;                                                        \
         }                                                                     \
-                                                                              \
-        return esxVI_##_type##_Deserialize(anyType->node, ptrptr);            \
-    }
+    }, /* nothing */)
+
+
+
+#define ESX_VI__TEMPLATE__CAST_VALUE_FROM_ANY_TYPE(_type, _value_type)        \
+    ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE_EXTRA(_type, _value_type,            \
+    {                                                                         \
+        if (anyType->type != esxVI_Type_##_type) {                            \
+            ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,                              \
+                         _("Call to %s for unexpected type '%s'"),            \
+                         __FUNCTION__, anyType->other);                       \
+            return -1;                                                        \
+        }                                                                     \
+    }, Value)
 
 
 
 
 
 
+#define ESX_VI__TEMPLATE__DYNAMIC_CAST_FROM_ANY_TYPE(__type, _dispatch)       \
+    ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE_EXTRA(__type, esxVI_##__type,        \
+      ESX_VI__TEMPLATE__DISPATCH(__type, _dispatch, -1),                      \
+      /* nothing */)
+
+
+
 #define ESX_VI__TEMPLATE__DYNAMIC_SERIALIZE(__type, _dispatch, _serialize)    \
     ESX_VI__TEMPLATE__SERIALIZE_EXTRA(__type,                                 \
       ESX_VI__TEMPLATE__DISPATCH(__type, _dispatch, -1),                      \
@@ -1111,6 +1139,12 @@ esxVI_String_DeepCopyValue(char **dest, const char *src)
     return 0;
 }
 
+/* esxVI_String_CastFromAnyType */
+ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(String)
+
+/* esxVI_String_CastValueFromAnyType */
+ESX_VI__TEMPLATE__CAST_VALUE_FROM_ANY_TYPE(String, char)
+
 int
 esxVI_String_Serialize(esxVI_String *string, const char *element,
                        virBufferPtr output)
@@ -1240,9 +1274,7 @@ ESX_VI__TEMPLATE__VALIDATE(Long,
 ESX_VI__TEMPLATE__LIST__APPEND(Long)
 
 /* esxVI_Long_CastFromAnyType */
-ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(Long,
-{
-})
+ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(Long)
 
 /* esxVI_Long_Serialize */
 ESX_VI__TEMPLATE__SERIALIZE(Long,
@@ -1522,9 +1554,7 @@ ESX_VI__TEMPLATE__DEEP_COPY(ManagedObjectReference,
 ESX_VI__TEMPLATE__LIST__APPEND(ManagedObjectReference)
 
 /* esxVI_ManagedObjectReference_CastFromAnyType */
-ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(ManagedObjectReference,
-{
-})
+ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(ManagedObjectReference)
 
 /* esxVI_ManagedObjectReference_CastListFromAnyType */
 ESX_VI__TEMPLATE__LIST__CAST_FROM_ANY_TYPE(ManagedObjectReference)
index 1ab39dad76da32bf7379af9e6a277194c296b88b..e53ccdaa6c2f46852c7fba3aedd55b4e25030cfc 100644 (file)
@@ -178,6 +178,8 @@ int esxVI_String_AppendValueListToList(esxVI_String **stringList,
 int esxVI_String_DeepCopy(esxVI_String **dest, esxVI_String *src);
 int esxVI_String_DeepCopyList(esxVI_String **destList, esxVI_String *srcList);
 int esxVI_String_DeepCopyValue(char **dest, const char *src);
+int esxVI_String_CastFromAnyType(esxVI_AnyType *anyType, esxVI_String **string);
+int esxVI_String_CastValueFromAnyType(esxVI_AnyType *anyType, char **string);
 int esxVI_String_Serialize(esxVI_String *string, const char *element,
                            virBufferPtr output);
 int esxVI_String_SerializeList(esxVI_String *stringList, const char *element,