mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
esx: Cleanup and refactor CastFromAnyType macros
Add CastFromAnyType functions for the String type.
This commit is contained in:
parent
a8ad5a40c6
commit
ac1e6586ec
@ -773,12 +773,11 @@ class Object(Base):
|
|||||||
# 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
|
|
||||||
|
|
||||||
if self.extended_by is None:
|
if self.extended_by is None:
|
||||||
source += "{\n"
|
source += "ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(%s)\n\n" % self.name
|
||||||
source += "})\n\n"
|
|
||||||
else:
|
else:
|
||||||
|
source += "ESX_VI__TEMPLATE__DYNAMIC_CAST_FROM_ANY_TYPE(%s,\n" % self.name
|
||||||
source += "{\n"
|
source += "{\n"
|
||||||
|
|
||||||
for extended_by in self.extended_by:
|
for extended_by in self.extended_by:
|
||||||
|
@ -183,32 +183,53 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#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 \
|
int \
|
||||||
esxVI_##_type##_CastFromAnyType(esxVI_AnyType *anyType, \
|
esxVI_##_type##_Cast##_dest_extra##FromAnyType(esxVI_AnyType *anyType, \
|
||||||
esxVI_##_type **ptrptr) \
|
_dest_type **ptrptr) \
|
||||||
{ \
|
{ \
|
||||||
|
_dest_type *item; \
|
||||||
|
\
|
||||||
if (anyType == NULL || ptrptr == NULL || *ptrptr != NULL) { \
|
if (anyType == NULL || ptrptr == NULL || *ptrptr != NULL) { \
|
||||||
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", \
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", \
|
||||||
_("Invalid argument")); \
|
_("Invalid argument")); \
|
||||||
return -1; \
|
return -1; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
switch (anyType->type) { \
|
item = *ptrptr; \
|
||||||
_dispatch \
|
|
||||||
\
|
\
|
||||||
case esxVI_Type_##_type: \
|
_extra \
|
||||||
break; \
|
|
||||||
\
|
\
|
||||||
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, \
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, \
|
||||||
_("Call to %s for unexpected type '%s'"), \
|
_("Call to %s for unexpected type '%s'"), \
|
||||||
__FUNCTION__, anyType->other); \
|
__FUNCTION__, anyType->other); \
|
||||||
return -1; \
|
return -1; \
|
||||||
} \
|
} \
|
||||||
\
|
}, /* nothing */)
|
||||||
return esxVI_##_type##_Deserialize(anyType->node, ptrptr); \
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -591,6 +612,13 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#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) \
|
#define ESX_VI__TEMPLATE__DYNAMIC_SERIALIZE(__type, _dispatch, _serialize) \
|
||||||
ESX_VI__TEMPLATE__SERIALIZE_EXTRA(__type, \
|
ESX_VI__TEMPLATE__SERIALIZE_EXTRA(__type, \
|
||||||
ESX_VI__TEMPLATE__DISPATCH(__type, _dispatch, -1), \
|
ESX_VI__TEMPLATE__DISPATCH(__type, _dispatch, -1), \
|
||||||
@ -1111,6 +1139,12 @@ esxVI_String_DeepCopyValue(char **dest, const char *src)
|
|||||||
return 0;
|
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
|
int
|
||||||
esxVI_String_Serialize(esxVI_String *string, const char *element,
|
esxVI_String_Serialize(esxVI_String *string, const char *element,
|
||||||
virBufferPtr output)
|
virBufferPtr output)
|
||||||
@ -1240,9 +1274,7 @@ ESX_VI__TEMPLATE__VALIDATE(Long,
|
|||||||
ESX_VI__TEMPLATE__LIST__APPEND(Long)
|
ESX_VI__TEMPLATE__LIST__APPEND(Long)
|
||||||
|
|
||||||
/* esxVI_Long_CastFromAnyType */
|
/* esxVI_Long_CastFromAnyType */
|
||||||
ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(Long,
|
ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(Long)
|
||||||
{
|
|
||||||
})
|
|
||||||
|
|
||||||
/* esxVI_Long_Serialize */
|
/* esxVI_Long_Serialize */
|
||||||
ESX_VI__TEMPLATE__SERIALIZE(Long,
|
ESX_VI__TEMPLATE__SERIALIZE(Long,
|
||||||
@ -1522,9 +1554,7 @@ 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)
|
||||||
|
@ -178,6 +178,8 @@ int esxVI_String_AppendValueListToList(esxVI_String **stringList,
|
|||||||
int esxVI_String_DeepCopy(esxVI_String **dest, esxVI_String *src);
|
int esxVI_String_DeepCopy(esxVI_String **dest, esxVI_String *src);
|
||||||
int esxVI_String_DeepCopyList(esxVI_String **destList, esxVI_String *srcList);
|
int esxVI_String_DeepCopyList(esxVI_String **destList, esxVI_String *srcList);
|
||||||
int esxVI_String_DeepCopyValue(char **dest, const char *src);
|
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,
|
int esxVI_String_Serialize(esxVI_String *string, const char *element,
|
||||||
virBufferPtr output);
|
virBufferPtr output);
|
||||||
int esxVI_String_SerializeList(esxVI_String *stringList, const char *element,
|
int esxVI_String_SerializeList(esxVI_String *stringList, const char *element,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user