esx: Fix generator for string return values

Distinguish between strings as parameters (const char *)
and strings as return values (char **).
This commit is contained in:
Matthias Bolte 2010-08-29 19:17:10 +02:00
parent a9afbf4fc5
commit 1504cc4f02
2 changed files with 32 additions and 18 deletions

View File

@ -94,11 +94,11 @@ class Parameter:
def generate_return(self, offset = 0, end_of_line = ";"): def generate_return(self, offset = 0, end_of_line = ";"):
if self.occurrence == OCCURRENCE__IGNORED: if self.occurrence == OCCURRENCE__IGNORED:
raise ValueError("invalid function parameteroccurrence value '%s'" % self.occurrence) raise ValueError("invalid function parameter occurrence value '%s'" % self.occurrence)
else: else:
string = " " string = " "
string += " " * offset string += " " * offset
string += "%s*%s)%s" % (self.get_type_string(), self.name, end_of_line) string += "%s%s)%s" % (self.get_type_string(True), self.name, end_of_line)
while len(string) < 59: while len(string) < 59:
string += " " string += " "
@ -124,15 +124,25 @@ class Parameter:
return " ESX_VI__METHOD__PARAMETER__SERIALIZE(%s, %s)\n" % (self.type, self.name) return " ESX_VI__METHOD__PARAMETER__SERIALIZE(%s, %s)\n" % (self.type, self.name)
def get_type_string(self): def get_type_string(self, as_return_value = False):
string = ""
if self.type == "String" and \ if self.type == "String" and \
self.occurrence not in [OCCURRENCE__REQUIRED_LIST, self.occurrence not in [OCCURRENCE__REQUIRED_LIST,
OCCURRENCE__OPTIONAL_LIST]: OCCURRENCE__OPTIONAL_LIST]:
return "const char *" if as_return_value:
string += "char *"
else:
string += "const char *"
elif self.is_enum(): elif self.is_enum():
return "esxVI_%s " % self.type string += "esxVI_%s " % self.type
else: else:
return "esxVI_%s *" % self.type string += "esxVI_%s *" % self.type
if as_return_value:
string += "*"
return string
def get_occurrence_comment(self): def get_occurrence_comment(self):
@ -225,9 +235,11 @@ class Method:
source += "),\n" source += "),\n"
if self.returns is None: if self.returns is None:
source += " void, None,\n" source += " void, /* nothing */, None,\n"
elif self.returns.type == "String":
source += " String, Value, %s,\n" % self.returns.get_occurrence_short_enum()
else: else:
source += " %s, %s,\n" % (self.returns.type, self.returns.get_occurrence_short_enum()) source += " %s, /* nothing */, %s,\n" % (self.returns.type, self.returns.get_occurrence_short_enum())
source += "{\n" source += "{\n"

View File

@ -67,34 +67,34 @@
#define ESX_VI__METHOD__DESERIALIZE_OUTPUT__None(_type) \ #define ESX_VI__METHOD__DESERIALIZE_OUTPUT__None(_type, _suffix) \
/* nothing */ /* nothing */
#define ESX_VI__METHOD__DESERIALIZE_OUTPUT__RequiredItem(_type) \ #define ESX_VI__METHOD__DESERIALIZE_OUTPUT__RequiredItem(_type, _suffix) \
if (esxVI_##_type##_Deserialize(response->node, output) < 0) { \ if (esxVI_##_type##_Deserialize##_suffix(response->node, output) < 0) { \
goto cleanup; \ goto cleanup; \
} }
#define ESX_VI__METHOD__DESERIALIZE_OUTPUT__RequiredList(_type) \ #define ESX_VI__METHOD__DESERIALIZE_OUTPUT__RequiredList(_type, _suffix) \
if (esxVI_##_type##_DeserializeList(response->node, output) < 0) { \ if (esxVI_##_type##_DeserializeList(response->node, output) < 0) { \
goto cleanup; \ goto cleanup; \
} }
#define ESX_VI__METHOD__DESERIALIZE_OUTPUT__OptionalItem(_type) \ #define ESX_VI__METHOD__DESERIALIZE_OUTPUT__OptionalItem(_type, _suffix) \
if (response->node != NULL && \ if (response->node != NULL && \
esxVI_##_type##_Deserialize(response->node, output) < 0) { \ esxVI_##_type##_Deserialize##_suffix(response->node, output) < 0) { \
goto cleanup; \ goto cleanup; \
} }
#define ESX_VI__METHOD__DESERIALIZE_OUTPUT__OptionalList(_type) \ #define ESX_VI__METHOD__DESERIALIZE_OUTPUT__OptionalList(_type, _suffix) \
if (response->node != NULL && \ if (response->node != NULL && \
esxVI_##_type##_DeserializeList(response->node, output) < 0) { \ esxVI_##_type##_DeserializeList(response->node, output) < 0) { \
goto cleanup; \ goto cleanup; \
@ -103,7 +103,8 @@
#define ESX_VI__METHOD(_name, _this_from_service, _parameters, _output_type, \ #define ESX_VI__METHOD(_name, _this_from_service, _parameters, _output_type, \
_occurrence, _validate, _serialize) \ _deserialize_suffix, _occurrence, _validate, \
_serialize) \
int \ int \
esxVI_##_name _parameters \ esxVI_##_name _parameters \
{ \ { \
@ -139,7 +140,8 @@
goto cleanup; \ goto cleanup; \
} \ } \
\ \
ESX_VI__METHOD__DESERIALIZE_OUTPUT__##_occurrence(_output_type) \ ESX_VI__METHOD__DESERIALIZE_OUTPUT__##_occurrence \
(_output_type, _deserialize_suffix) \
\ \
result = 0; \ result = 0; \
\ \
@ -284,7 +286,7 @@ ESX_VI__METHOD(ValidateMigration, /* special _this */,
esxVI_ManagedObjectReference *pool, /* optional */ esxVI_ManagedObjectReference *pool, /* optional */
esxVI_ManagedObjectReference *host, /* optional */ esxVI_ManagedObjectReference *host, /* optional */
esxVI_Event **output), /* optional, list */ esxVI_Event **output), /* optional, list */
Event, OptionalList, Event, /* nothing */, OptionalList,
{ {
ESX_VI__METHOD__PARAMETER__REQUIRE(vm) ESX_VI__METHOD__PARAMETER__REQUIRE(vm)
}, },