[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH] 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.
---
 src/esx/esx_vi_generator.py |   13 ++++++++++++-
 src/esx/esx_vi_types.c      |   28 +++++++++++++++++++++-------
 2 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/src/esx/esx_vi_generator.py b/src/esx/esx_vi_generator.py
index d249e2d..6ae13c0 100755
--- a/src/esx/esx_vi_generator.py
+++ b/src/esx/esx_vi_generator.py
@@ -765,7 +765,18 @@ class Object:
         # 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
+            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:
                 source += "/* esxVI_%s_CastListFromAnyType */\n" % self.name
diff --git a/src/esx/esx_vi_types.c b/src/esx/esx_vi_types.c
index de2839f..8334efd 100644
--- a/src/esx/esx_vi_types.c
+++ b/src/esx/esx_vi_types.c
@@ -183,7 +183,7 @@
 
 
 
-#define ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(_type)                           \
+#define ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(_type, _dispatch)                \
     int                                                                       \
     esxVI_##_type##_CastFromAnyType(esxVI_AnyType *anyType,                   \
                                     esxVI_##_type **ptrptr)                   \
@@ -194,11 +194,16 @@
             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,                              \
-                         "Expecting type '%s' but found '%s'",                \
-                         esxVI_Type_ToString(esxVI_Type_##_type),             \
-                         anyType->other);                                     \
+                         _("Call to %s for unexpected type '%s'"),            \
+                         __FUNCTION__, anyType->other);                       \
             return -1;                                                        \
         }                                                                     \
                                                                               \
@@ -505,7 +510,7 @@
                                                                               \
       default:                                                                \
         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));                       \
         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)                          \
     case esxVI_Type_##_type:                                                  \
       return esxVI_##_type##_Serialize((esxVI_##_type *)item, element,        \
@@ -1359,7 +1371,9 @@ 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)
-- 
1.7.0.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]