提交 6c1d30a7 编写于 作者: M Matthias Bolte

esx: Generate implicit _this macros

Several vSphere API methods are called on global objects like the
FileManager, the PerformanceManager or the SearchIndex. The generator
input file allows to mark such methods and the generator generates
such method in a way that automatically handles marked parameter. This
is done by some special macros. Those were manually written and this
patch moves them to the generator.
上级 0b85d104
......@@ -347,6 +347,7 @@ ESX_DRIVER_SOURCES = \
ESX_DRIVER_GENERATED = \
esx/esx_vi_methods.generated.c \
esx/esx_vi_methods.generated.h \
esx/esx_vi_methods.generated.macro \
esx/esx_vi_types.generated.c \
esx/esx_vi_types.generated.h \
esx/esx_vi_types.generated.typedef \
......
......@@ -26,7 +26,6 @@ import os.path
OCCURRENCE__REQUIRED_ITEM = "r"
OCCURRENCE__REQUIRED_LIST = "rl"
OCCURRENCE__OPTIONAL_ITEM = "o"
......@@ -39,10 +38,19 @@ valid_occurrences = [OCCURRENCE__REQUIRED_ITEM,
OCCURRENCE__OPTIONAL_LIST,
OCCURRENCE__IGNORED]
autobind_map = { "FileManager" : "fileManager",
"PerformanceManager" : "perfManager",
"PropertyCollector" : "propertyCollector",
"SearchIndex" : "searchIndex",
"SessionManager" : "sessionManager",
"VirtualDiskManager" : "virtualDiskManager" }
autobind_map_usage = set()
def aligned(left, right):
while len(left) < 59:
def aligned(left, right, length=59):
while len(left) < length:
left += " "
return left + right
......@@ -50,13 +58,6 @@ def aligned(left, right):
class Parameter:
autobind_map = { "FileManager" : "fileManager",
"PerformanceManager" : "perfManager",
"PropertyCollector" : "propertyCollector",
"SearchIndex" : "searchIndex",
"SessionManager" : "sessionManager",
"VirtualDiskManager" : "virtualDiskManager" }
def __init__(self, type, name, occurrence):
self.type = type
self.occurrence = occurrence
......@@ -212,7 +213,8 @@ class Method:
source += "ESX_VI__METHOD(%s," % self.name
if self.autobind_parameter is not None:
source += " %s,\n" % Parameter.autobind_map[self.autobind_parameter.autobind_type]
autobind_map_usage.add(self.autobind_parameter.autobind_type)
source += " %s,\n" % autobind_map[self.autobind_parameter.autobind_type]
else:
source += " /* explicit _this */,\n"
......@@ -1482,6 +1484,7 @@ types_header = open_and_print(os.path.join(output_dirname, "esx_vi_types.generat
types_source = open_and_print(os.path.join(output_dirname, "esx_vi_types.generated.c"))
methods_header = open_and_print(os.path.join(output_dirname, "esx_vi_methods.generated.h"))
methods_source = open_and_print(os.path.join(output_dirname, "esx_vi_methods.generated.c"))
methods_macro = open_and_print(os.path.join(output_dirname, "esx_vi_methods.generated.macro"))
helpers_header = open_and_print(os.path.join(output_dirname, "esx_vi.generated.h"))
helpers_source = open_and_print(os.path.join(output_dirname, "esx_vi.generated.c"))
......@@ -1586,8 +1589,6 @@ for obj in objects_by_name.values():
for obj in managed_objects_by_name.values():
for property in obj.properties:
if property.occurrence != OCCURRENCE__IGNORED and \
......@@ -1610,15 +1611,11 @@ for obj in managed_objects_by_name.values():
for obj in objects_by_name.values():
inherit_features(obj)
types_typedef.write("/* Generated by esx_vi_generator.py */\n\n\n\n")
types_typeenum.write("/* Generated by esx_vi_generator.py */\n\n")
types_typetostring.write("/* Generated by esx_vi_generator.py */\n\n")
......@@ -1627,10 +1624,12 @@ types_header.write("/* Generated by esx_vi_generator.py */\n\n\n\n")
types_source.write("/* Generated by esx_vi_generator.py */\n\n\n\n")
methods_header.write("/* Generated by esx_vi_generator.py */\n\n\n\n")
methods_source.write("/* Generated by esx_vi_generator.py */\n\n\n\n")
methods_macro.write("/* Generated by esx_vi_generator.py */\n\n\n\n")
helpers_header.write("/* Generated by esx_vi_generator.py */\n\n\n\n")
helpers_source.write("/* Generated by esx_vi_generator.py */\n\n\n\n")
# output enums
types_typedef.write("/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n" +
" * VI Enums\n" +
......@@ -1658,8 +1657,6 @@ types_typeenum.write("\n")
types_typetostring.write("\n")
types_typefromstring.write("\n")
names = objects_by_name.keys()
names.sort()
......@@ -1682,8 +1679,6 @@ types_typeenum.write("\n")
types_typetostring.write("\n")
types_typefromstring.write("\n")
names = managed_objects_by_name.keys()
names.sort()
......@@ -1705,6 +1700,17 @@ for name in names:
methods_header.write(methods_by_name[name].generate_header())
methods_source.write(methods_by_name[name].generate_source())
sorted_usage = list(autobind_map_usage)
sorted_usage.sort()
for usage in sorted_usage:
name = autobind_map[usage]
string = aligned("#define ESX_VI__METHOD__PARAMETER__THIS__%s " % name, "\\\n", 78)
string += " ESX_VI__METHOD__PARAMETER__THIS_FROM_SERVICE(ManagedObjectReference, \\\n"
string += aligned("", "%s)\n\n\n\n" % name, 49)
methods_macro.write(string)
# output helpers
......
......@@ -175,42 +175,6 @@
#define ESX_VI__METHOD__PARAMETER__THIS__fileManager \
ESX_VI__METHOD__PARAMETER__THIS_FROM_SERVICE(ManagedObjectReference, \
fileManager)
#define ESX_VI__METHOD__PARAMETER__THIS__perfManager \
ESX_VI__METHOD__PARAMETER__THIS_FROM_SERVICE(ManagedObjectReference, \
perfManager)
#define ESX_VI__METHOD__PARAMETER__THIS__propertyCollector \
ESX_VI__METHOD__PARAMETER__THIS_FROM_SERVICE(ManagedObjectReference, \
propertyCollector)
#define ESX_VI__METHOD__PARAMETER__THIS__searchIndex \
ESX_VI__METHOD__PARAMETER__THIS_FROM_SERVICE(ManagedObjectReference, \
searchIndex)
#define ESX_VI__METHOD__PARAMETER__THIS__sessionManager \
ESX_VI__METHOD__PARAMETER__THIS_FROM_SERVICE(ManagedObjectReference, \
sessionManager)
#define ESX_VI__METHOD__PARAMETER__THIS__virtualDiskManager \
ESX_VI__METHOD__PARAMETER__THIS_FROM_SERVICE(ManagedObjectReference, \
virtualDiskManager)
/*
* A required parameter must be != 0 (NULL for pointers, "undefined" == 0 for
* enumeration values).
......@@ -248,6 +212,10 @@
#include "esx_vi_methods.generated.macro"
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* VI Methods
*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册