Browse Source

Merge pull request #102 from acplt/generate_borrowed_at_runtime

declaring the borrowed vtable at runtme in the ua_application.c
Julius Pfrommer 10 years ago
parent
commit
0796a114ce
2 changed files with 16 additions and 35 deletions
  1. 7 0
      src/ua_application.c
  2. 9 35
      tools/generate_namespace.py

+ 7 - 0
src/ua_application.c

@@ -24,6 +24,13 @@ UA_Node* create_node_ns0(UA_Int32 class, UA_Int32 nodeClass, UA_Int32 const id,
 }
 
 void appMockup_init() {
+	//fill the UA_borrowed_ table that has been declaed in ua_namespace.c
+	for(UA_Int32 i=0;i<SIZE_UA_VTABLE;i++){
+		UA_borrowed_.types[i] = UA_.types[i];
+		UA_borrowed_.types[i].delete=(UA_Int32(*)(void *))phantom_delete;
+		UA_borrowed_.types[i].deleteMembers=(UA_Int32(*)(void *))phantom_delete;
+	}
+
 	// create namespaces
 	// TODO: A table that maps the namespaceUris to Ids
 	Namespace* ns0;

+ 9 - 35
tools/generate_namespace.py

@@ -132,6 +132,7 @@ printc('''const UA_VTable UA_ = {
 \t.getTypeIndex = UA_ns0ToVTableIndex,
 \t.types = (UA_VTable_Entry[]){''')
 
+i = 0
 for row in rows:
     if row[0] == "" or row[0] in exclude_types or row[2] in exclude_kinds:
         continue
@@ -141,7 +142,7 @@ for row in rows:
         name = "UA_ExtensionObject"
     else:
 	name = "UA_" + row[0]
-
+	i=i+1
     printh('#define '+name.upper()+'_NS0 '+row[1])
 
     printc("\t{.typeId={UA_NODEIDTYPE_FOURBYTE,0,.identifier.numeric=" + row[1] + "}" + 
@@ -164,43 +165,16 @@ for row in rows:
           ",\n.decode=(UA_decode)%(name)s_decodeXml}" +
           "}},")
 
-printc('''}};
-
-const UA_VTable UA_borrowed_ = {
-\t.getTypeIndex=UA_ns0ToVTableIndex,
-\t.types = (UA_VTable_Entry[]){''')
+printc('''}};''')
 
-for row in rows:
-    if row[0] == "" or row[0] in exclude_types or row[2] in exclude_kinds:
-        continue
-    if row[0] == "BaseDataType":
-        name = "UA_Variant"
-    elif row[0] == "Structure":
-        name = "UA_ExtensionObject"
-    else:	
-	name = "UA_" + row[0]
+printc("UA_VTable_Entry borrowed_types[" + str(i) + "];");
+printc("const UA_VTable UA_borrowed_ = {\n"+
+"\t.getTypeIndex=UA_ns0ToVTableIndex,\n"+
+"\t.types = borrowed_types\n"+
+"};")
 
-    printc("\t{.typeId={UA_NODEIDTYPE_FOURBYTE,0,.identifier.numeric=" + row[1] + "}" + 
-          ",\n.name=(UA_Byte*)&\"%(name)s\"" +
-          ",\n.new=(UA_Int32(*)(void **))%(name)s_new" +
-          ",\n.init=(UA_Int32(*)(void *))%(name)s_init" +
-          ",\n.copy=(UA_Int32(*)(void const * ,void*))%(name)s_copy" +
-          ",\n.delete=(UA_Int32(*)(void *))phantom_delete" +
-          ",\n.deleteMembers=(UA_Int32(*)(void *))phantom_delete" +
-          ",\n#ifdef DEBUG //FIXME: seems to be okay atm, however a pointer to a noop function would be more safe" + 
-          "\n.print=(void(*)(const void *, FILE *))%(name)s_print," +
-          "\n#endif" + 
-          "\n.memSize=" + ("sizeof(%(name)s)" if (name != "UA_InvalidType") else "0") +
-          ",\n.dynMembers=" + ("UA_FALSE" if (name in fixed_size) else "UA_TRUE") +
-          ",\n.encodings={{.calcSize=(UA_calcSize)" + name +"_calcSizeBinary" +
-          ",\n.encode=(UA_encode)%(name)s_encodeBinary" +
-          ",\n.decode=(UA_decode)%(name)s_decodeBinary}" +
-          ",\n{.calcSize=(UA_calcSize)%(name)s_calcSizeXml" +
-          ",\n.encode=(UA_encode)%(name)s_encodeXml" +
-          ",\n.decode=(UA_decode)%(name)s_decodeXml}" +
-          "}},")
+printh('\n#define SIZE_UA_VTABLE '+str(i));
 
-printc("}};")
 printh('\n#endif /* OPCUA_NAMESPACE_0_H_ */')
 
 fh.close()