Browse Source

ongoing work

Julius Pfrommer 10 years ago
parent
commit
1763b9658d
2 changed files with 26 additions and 19 deletions
  1. 7 13
      include/ua_types.h
  2. 19 6
      tools/generate_datatypes.py

+ 7 - 13
include/ua_types.h

@@ -410,25 +410,19 @@ void UA_EXPORT UA_Array_print(const void *p, UA_Int32 noElements, const UA_TypeV
 
 #define UA_MAX_MEMBERS 16 // Maximum number of members per complex type
 
-/**
- * The type descriptions points to the table in which the type is defined.
- * That is necessary so that we can find the layouts of the member types.
- *
- * DataTypeTables are self-contained. Only the built-in types can be assumed.
- * All the other types must be built up within the same table and cannot
- * cross-reference. In the server, we store one datatypetable per namespace.
- */
+struct UA_DataTypeMember {
+    UA_UInt16 memberTypeIndex : 10; ///< Index of the member in the datatypelayout table
+    UA_Byte padding : 5; ///< How much padding is there before this member element?
+    UA_Boolean isArray : 1;
+};
+    
 typedef struct {
     UA_UInt16 memSize; ///< Size of the struct in memory
     UA_UInt16 binarySize : 14; ///< Size of the type in binary encoding. Including _all_ members with constantSize == true.
     UA_Boolean constantSize : 1; ///< Does the type have constant size in memory? (no pointers, also not in members)
     UA_Boolean binaryZeroCopy: 1; ///< Given an array of this type, can we just point into the binary stream? The boolean is a shortcut for (memSize == binarySize && constantSize).
     UA_Boolean isBuiltin : 1; ///< The type is builtin. Use special functions if necessary. membersSize is 0, but the builtin-type index we have is encoded in memberDetails[0].memberTypeIndex.
-    struct {
-        UA_UInt16 memberTypeIndex : 10; ///< Index of the member in the datatypelayout table
-        UA_Byte padding : 5; ///< How much padding is there before this member element?
-        UA_Boolean isArray : 1;
-    } memberDetails[UA_MAX_MEMBERS];
+    struct UA_DataTypeMember memberDetails[UA_MAX_MEMBERS];
     UA_Byte membersSize; ///< How many members does the struct have? (max. 32)
     struct UA_DataTypeLayout *table; /**< Point to the beginning of the table where the members can be found with their indices  */
 } UA_DataTypeLayout;

+ 19 - 6
tools/generate_datatypes.py

@@ -27,7 +27,10 @@ class Type(object):
         self.name = name
         self.description = description
 
-    def string_c(self):
+    def typedef_c(self):
+        pass
+
+    def typelayout_c(self):
         pass
 
 class EnumerationType(Type):
@@ -39,14 +42,24 @@ class EnumerationType(Type):
     def append_enum(name, value):
         self.elements[name] = value
 
-    def string_c(self):
+    def typedef_c(self):
         return "typedef enum { \n    " + \
-            ",\n    ".join(map(lambda (key, value) : key.upper() + " = " + value, self.elements.iteritems())) + \
+            ",\n    ".join(map(lambda (key,value) : key.upper() + " = " + value,self.elements.iteritems())) + \
             "\n} " + self.name + ";"
 
+    def typelayout_c(self, tablename):
+        return "(UA_DataTypeLayout) {.memsize = sizeof(" + self.name "), .binarySize = 4," + \
+            ".constantSize = UA_TRUE, .binaryZeroCopy = UA_TRUE, isBuiltin = UA_FALSE," + \
+            ".memberDetails = " + \
+            ".membersSize = 0, .table = " + tablename + " }"
+
 class OpaqueType(Type):
-    def string_c(self):
+    def typedef_c(self):
         return "typedef UA_ByteString " + self.name + ";"
+    def typelayout_c(self, tablename):
+        return "(UA_DataTypeLayout) {.memsize = sizeof(" + self.name "), .binarySize = 4," + \
+            ".constantSize = UA_TRUE, .binaryZeroCopy = UA_TRUE, isBuiltin = UA_FALSE," + \
+            ".membersSize = 0, .table = " + tablename + " }"
 
 class StructMember(object):
     def __init__(self, name, memberType, isArray):
@@ -68,7 +81,7 @@ class StructType(Type):
                 return False
         return True
 
-    def string_c(self):
+    def typedef_c(self):
         if len(self.members) == 0:
             return "typedef void * " + self.name + ";"
         returnstr =  "typedef struct {\n"
@@ -239,7 +252,7 @@ extern "C" {
         printh("")
         if t.description != "":
             printh("/** @brief " + t.description + "*/")
-        printh(t.string_c())
+        printh(t.typedef_c())
 
     printh('''
 /// @} /* end of group */