esx: Make esxVI_*_CastFromAnyType dynamically dispatched

This will be used in the ESX storage driver in order to handle
the DatastoreInfo type and inheriting types properly.
This commit is contained in:
Matthias Bolte 2010-05-18 17:53:12 +02:00
parent 90fce23f24
commit 894baa0af8
2 changed files with 33 additions and 8 deletions

View File

@ -765,7 +765,18 @@ class Object:
# cast from any type # cast from any type
if self.features & Object.FEATURE__ANY_TYPE: if self.features & Object.FEATURE__ANY_TYPE:
source += "/* esxVI_%s_CastFromAnyType */\n" % self.name source += "/* esxVI_%s_CastFromAnyType */\n" % self.name
source += "ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(%s)\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"
else:
source += "{\n"
for extended_by in self.extended_by:
source += " ESX_VI__TEMPLATE__DISPATCH__CAST_FROM_ANY_TYPE(%s)\n" % extended_by
source += "})\n\n"
if self.features & Object.FEATURE__LIST: if self.features & Object.FEATURE__LIST:
source += "/* esxVI_%s_CastListFromAnyType */\n" % self.name source += "/* esxVI_%s_CastListFromAnyType */\n" % self.name

View File

@ -183,7 +183,7 @@
#define ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(_type) \ #define ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(_type, _dispatch) \
int \ int \
esxVI_##_type##_CastFromAnyType(esxVI_AnyType *anyType, \ esxVI_##_type##_CastFromAnyType(esxVI_AnyType *anyType, \
esxVI_##_type **ptrptr) \ esxVI_##_type **ptrptr) \
@ -194,11 +194,16 @@
return -1; \ return -1; \
} \ } \
\ \
if (anyType->type != esxVI_Type_##_type) { \ switch (anyType->type) { \
_dispatch \
\
case esxVI_Type_##_type: \
break; \
\
default: \
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, \ ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, \
"Expecting type '%s' but found '%s'", \ _("Call to %s for unexpected type '%s'"), \
esxVI_Type_ToString(esxVI_Type_##_type), \ __FUNCTION__, anyType->other); \
anyType->other); \
return -1; \ return -1; \
} \ } \
\ \
@ -505,7 +510,7 @@
\ \
default: \ default: \
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, \ ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, \
"Call to %s for unexpected type '%s'", __FUNCTION__, \ _("Call to %s for unexpected type '%s'"), __FUNCTION__, \
esxVI_Type_ToString(item->_type)); \ esxVI_Type_ToString(item->_type)); \
return _error_return; \ return _error_return; \
} }
@ -526,6 +531,13 @@
#define ESX_VI__TEMPLATE__DISPATCH__CAST_FROM_ANY_TYPE(_type) \
case esxVI_Type_##_type: \
return esxVI_##_type##_Deserialize(anyType->node, \
(esxVI_##_type **)ptrptr);
#define ESX_VI__TEMPLATE__DISPATCH__SERIALIZE(_type) \ #define ESX_VI__TEMPLATE__DISPATCH__SERIALIZE(_type) \
case esxVI_Type_##_type: \ case esxVI_Type_##_type: \
return esxVI_##_type##_Serialize((esxVI_##_type *)item, element, \ return esxVI_##_type##_Serialize((esxVI_##_type *)item, element, \
@ -1359,7 +1371,9 @@ ESX_VI__TEMPLATE__DEEP_COPY(ManagedObjectReference,
ESX_VI__TEMPLATE__LIST__APPEND(ManagedObjectReference) ESX_VI__TEMPLATE__LIST__APPEND(ManagedObjectReference)
/* esxVI_ManagedObjectReference_CastFromAnyType */ /* esxVI_ManagedObjectReference_CastFromAnyType */
ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(ManagedObjectReference) ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(ManagedObjectReference,
{
})
/* esxVI_ManagedObjectReference_CastListFromAnyType */ /* esxVI_ManagedObjectReference_CastListFromAnyType */
ESX_VI__TEMPLATE__LIST__CAST_FROM_ANY_TYPE(ManagedObjectReference) ESX_VI__TEMPLATE__LIST__CAST_FROM_ANY_TYPE(ManagedObjectReference)