瀏覽代碼

small cleanups

Julius Pfrommer 10 年之前
父節點
當前提交
f5cd1455c9
共有 3 個文件被更改,包括 51 次插入121 次删除
  1. 16 72
      src/Makefile.am
  2. 二進制
      tests/check_services_view
  3. 35 49
      tools/generate_builtin.py

+ 16 - 72
src/Makefile.am

@@ -1,78 +1,23 @@
-#optimization levels depending on debug
 AM_CFLAGS = $(GLOBAL_AM_CFLAGS) -I$(top_builddir)/include -I$(top_builddir)/src -I. -I$(top_builddir)/src/util
-
-
 TOOL_DIR = ../tools
-#__top_builddir__bin_stackTest_out_SOURCES =	opcuaServer.c\
-#											opcua_builtInDatatypes.c\
-#											opcua_binaryEncDec.c\
-#											ua_transportLayer.c\
-#											opcua_builtInDatatypes.h\
-#											opcua_binaryEncDec.h\
-#											ua_transportLayer.h\
-#											opcua_advancedDatatypes.h\
-#											opcua_types.h\
-#											opcua_connectionHelper.h\
-#											tcp_layer.h
-
-#lib_LTLIBRARIES = libstack.la
-#libstack_la_SOURCES = ua_transportLayer.c\
-#					  ua_transportLayer.h\
-#					  opcua_advancedDatatypes.h\
-#					  opcua_connectionHelper.h	
 lib_LTLIBRARIES = libopen62541.la
 libopen62541_la_LDFLAGS = -avoid-version -no-undefined
-#libopen62541_la_SOURCES = 			opcua.c\
-#						ua_basictypes.c\
-#						ua_namespace_0.c\
-#						ua_transportLayer.c\
-#						ua_secureLayer.c\
-#						tcp_layer.c\
-#						ua_transportLayer.h\
-#						opcua_connectionHelper.h\
-#						opcua_encodingLayer.h\
-#						ua_secureLayer.h\
-#						tcp_layer.h\
-#						util/ua_list.c\
-#						util/ua_indexedList.c\
-#						ua_stackInternalTypes.c\
-#						ua_namespace.h\
-#						ua_namespace.c
-
-#libopen62541_ladir = $(top_builddir)/include . $(top_builddir)/src . $(top_builddir)/src/util					
-
-#libopen62541_la_HEADERS = opcua.h\
-#						ua_basictypes.h\
-#						ua_namespace.h\
-#						ua_transportLayer.h\
-#						opcua_connectionHelper.h\
-#						opcua_encodingLayer.h\
-#						ua_secureLayer.h\
-#						ua_namespace.h\
-#						ua_connection.h\
-#						ua_stackInternalTypes.h\
-#						ua_list.h\
-#						ua_indexedList.h
-
-libopen62541_la_SOURCES = opcua.c\
-						ua_basictypes.c\
-						ua_namespace_0.c\
-						util/ua_list.c\
-						util/ua_indexedList.c\
-						ua_transport.c\
-						ua_transport_binary.c\
-						ua_transport_binary_secure.c\
-						ua_namespace.c\
-						ua_services_attribute.c\
-						ua_services_session.c\
-						ua_services_discovery.c\
-						ua_services_securechannel.c\
-						ua_services_view.c\
-						ua_application.c
-
-#bin_PROGRAMS= $(top_builddir)/bin/open62541.out
-#__top_builddir__bin_libOpen62541_out_SOURCES = opcuaServer.c
-#libOpen62541_la_LIBADD = ../lib/libOpen62541.la		  										
+libopen62541_la_SOURCES = opcua.c \
+						  ua_basictypes.c \
+						  ua_namespace_0.c \
+						  util/ua_list.c \
+						  util/ua_indexedList.c \
+						  ua_transport.c \
+						  ua_transport_binary.c \
+						  ua_transport_binary_secure.c \
+						  ua_namespace.c \
+						  ua_services_attribute.c \
+						  ua_services_session.c \
+						  ua_services_discovery.c \
+						  ua_services_securechannel.c \
+						  ua_services_nodemanagement.c \
+						  ua_services_view.c \
+						  ua_application.c
 
 .PHONY: convenience-link clean-convenience-link
 
@@ -99,4 +44,3 @@ clean-convenience-link:
 all-local: convenience-link
 
 clean-local: clean-convenience-link
-

二進制
tests/check_services_view


+ 35 - 49
tools/generate_builtin.py

@@ -18,20 +18,8 @@ exclude_types = set(["Boolean", "SByte", "Byte", "Int16", "UInt16", "Int32", "UI
                     "QualifiedName", "LocalizedText", "ExtensionObject", "DataValue",
                      "Variant", "DiagnosticInfo", "IntegerId"])
 
-elementary_size = dict()
-elementary_size["Boolean"] = 1;
-elementary_size["SByte"] = 1;
-elementary_size["Byte"] = 1;
-elementary_size["Int16"] = 2;
-elementary_size["UInt16"] = 2;
-elementary_size["Int32"] = 4;
-elementary_size["UInt32"] = 4;
-elementary_size["Int64"] = 8;
-elementary_size["UInt64"] = 8;
-elementary_size["Float"] = 4;
-elementary_size["Double"] = 8;
-elementary_size["DateTime"] = 8;
-elementary_size["StatusCode"] = 4;
+elementary_size = {"Boolean":1, "SByte":1, "Byte":1, "Int16":2, "UInt16":2, "Int32":4, "UInt32":4,
+                   "Int64":8, "UInt64":8, "Float":4, "Double":8, "DateTime":8, "StatusCode":4}
 
 enum_types = []
 structured_types = []
@@ -48,16 +36,12 @@ def skipType(name):
 def stripTypename(tn):
     return tn[tn.find(":")+1:]
 
-def camlCase2AdaCase(item):
-    (newitem, n) = re.subn("(?<!^)(?<![A-Z])([A-Z])", "_\\1", item)
-    return newitem
-    
 def camlCase2CCase(item):
     if item in ["Float","Double"]:
         return "my" + item
     return item[:1].lower() + item[1:] if item else ''
 
-# are the prerequisites in place? if not, postpone.
+# are the types we need already in place? if not, postpone.
 def printableStructuredType(element):
     for child in element:
         if child.tag == "{http://opcfoundation.org/BinarySchema/}Field":
@@ -66,14 +50,13 @@ def printableStructuredType(element):
                 return False
     return True
 
-# There three types of types in the bsd file:
+# There are three types of types in the bsd file:
 # StructuredType, EnumeratedType OpaqueType
 
 def createEnumerated(element):
     valuemap = OrderedDict()
     name = "UA_" + element.get("Name")
     enum_types.append(name)
-    print("\n", file=fh)
     for child in element:
         if child.tag == "{http://opcfoundation.org/BinarySchema/}Documentation":
             print("/** @brief " + child.text + " */", end='\n', file=fh)
@@ -116,12 +99,6 @@ def createStructured(element):
             else:
                 valuemap[childname] = typename
 
-    # if "Response" in name[len(name)-9:]:
-    #    print("type " + name + " is new Response_Base with "),
-    # elif "Request" in name[len(name)-9:]:
-    #    print ("type " + name + " is new Request_Base with "),
-    # else:
-    #    print ("type " + name + " is new UA_Builtin with "),
     print("typedef struct " + name + " {", end='\n', file=fh)
     if len(valuemap) == 0:
         typename = stripTypename(element.get("BaseType"))
@@ -191,10 +168,13 @@ def createStructured(element):
                 print('\tCHECKED_DECODE(UA_'+t+'_decodeBinary(src,pos,&(dst->'+n+')), '+name+'_deleteMembers(dst));', end='\n', file=fc)
             elif t.find("**") != -1:
             	# decode size
-		print('\tCHECKED_DECODE(UA_Int32_decodeBinary(src,pos,&(dst->'+n+'Size)), '+name+'_deleteMembers(dst)); // decode size', end='\n', file=fc)
+		print('\tCHECKED_DECODE(UA_Int32_decodeBinary(src,pos,&(dst->'+n+'Size)), ' +
+                      name + '_deleteMembers(dst)); // decode size', end='\n', file=fc)
 		# allocate memory for array
-		print("\tCHECKED_DECODE(UA_Array_new((void***)&dst->"+n+", dst->"+n+"Size, UA_"+t[0:t.find("*")].upper()+"), dst->"+n+" = UA_NULL; "+name+'_deleteMembers(dst));', end='\n', file=fc)
-		print("\tCHECKED_DECODE(UA_Array_decodeBinary(src,dst->"+n+"Size, UA_" + t[0:t.find("*")].upper()+",pos,(void *** const) (&dst->"+n+")), "+name+'_deleteMembers(dst));', end='\n', file=fc)
+		print("\tCHECKED_DECODE(UA_Array_new((void***)&dst->"+n+", dst->"+n+"Size, UA_"+t[0:t.find("*")].upper()+"), dst->" +
+                      n + " = UA_NULL; "+name+'_deleteMembers(dst));', end='\n', file=fc)
+		print("\tCHECKED_DECODE(UA_Array_decodeBinary(src,dst->"+n+"Size, UA_" + t[0:t.find("*")].upper() +
+                      ",pos,(void *** const) (&dst->"+n+")), "+name+'_deleteMembers(dst));', end='\n', file=fc)
             elif t.find("*") != -1:
 		#allocate memory using new
 		print('\tCHECKED_DECODE(UA_'+ t[0:t.find("*")] +"_new(&(dst->" + n + ")), "+name+'_deleteMembers(dst));', end='\n', file=fc)
@@ -215,7 +195,7 @@ def createStructured(element):
     for n,t in valuemap.iteritems():
         if t not in elementary_size:
             if t.find("**") != -1:
-		print("\tretval |= UA_Array_delete((void***)&p->"+n+",p->"+n+"Size,UA_"+t[0:t.find("*")].upper()+"); p->"+n+" = UA_NULL;", end='\n', file=fc) #not tested
+		print("\tretval |= UA_Array_delete((void***)&p->"+n+",p->"+n+"Size,UA_"+t[0:t.find("*")].upper()+"); p->"+n+" = UA_NULL;", end='\n', file=fc)
             elif t.find("*") != -1:
 		print('\tretval |= UA_' + t[0:t.find("*")] + "_delete(p->"+n+");", end='\n', file=fc)
             else:
@@ -252,7 +232,8 @@ def createStructured(element):
                 print('\tretval |= UA_'+t+'_copy(&(src->'+n+'),&(dst->'+n+'));', end='\n', file=fc)
             elif t.find("**") != -1:
                 print('\tretval |= UA_Int32_copy(&(src->'+n+'Size),&(dst->'+n+'Size)); // size of following array', end='\n', file=fc)
-		print("\tretval |= UA_Array_copy((void const* const*) (src->"+n+"), src->"+n+"Size," + "UA_"+t[0:t.find("*")].upper()+",(void***)&(dst->"+n+"));", end='\n', file=fc)
+		print("\tretval |= UA_Array_copy((void const* const*) (src->"+n+"), src->"+n+"Size," + "UA_" +
+                      t[0:t.find("*")].upper()+",(void***)&(dst->"+n+"));", end='\n', file=fc)
             elif t.find("*") != -1:
                 print('\tretval |= UA_' + t[0:t.find("*")] + '_copy(src->' + n + ',dst->' + n + ');', end='\n', file=fc)
             else:
@@ -285,12 +266,30 @@ types = tree.xpath("/opc:TypeDictionary/*[not(self::opc:Import)]", namespaces=ns
 
 fh = open(sys.argv[2] + ".hgen",'w');
 fc = open(sys.argv[2] + ".cgen",'w');
-print('''/**********************************************************
- * '''+sys.argv[2]+'''.cgen -- do not modify
- **********************************************************
+
+print('''/**
+ * @file '''+sys.argv[2]+'''.h
+ *
+ * @brief Autogenerated data types defined in the UA standard
+ *
  * Generated from '''+sys.argv[1]+''' with script '''+sys.argv[0]+'''
  * on host '''+platform.uname()[1]+''' by user '''+getpass.getuser()+''' at '''+ time.strftime("%Y-%m-%d %I:%M:%S")+'''
- **********************************************************/
+ */
+
+#ifndef OPCUA_H_
+#define OPCUA_H_
+
+#include "ua_basictypes.h"
+#include "ua_namespace_0.h"''', end='\n', file=fh);
+
+print('''/**
+ * @file '''+sys.argv[2]+'''.c
+ *
+ * @brief Autogenerated function implementations to manage the data types defined in the UA standard
+ *
+ * Generated from '''+sys.argv[1]+''' with script '''+sys.argv[0]+'''
+ * on host '''+platform.uname()[1]+''' by user '''+getpass.getuser()+''' at '''+ time.strftime("%Y-%m-%d %I:%M:%S")+'''
+ */
  
 #include "''' + sys.argv[2] + '.h"', end='\n', file=fc);
 
@@ -303,19 +302,6 @@ for field in fields:
 
 deferred_types = OrderedDict()
 
-print('''/**********************************************************
- * '''+sys.argv[2]+'''.hgen -- do not modify
- **********************************************************
- * Generated from '''+sys.argv[1]+''' with script '''+sys.argv[0]+'''
- * on host '''+platform.uname()[1]+''' by user '''+getpass.getuser()+''' at '''+ time.strftime("%Y-%m-%d %I:%M:%S")+'''
- **********************************************************/
-
-#ifndef OPCUA_H_
-#define OPCUA_H_
-
-#include "ua_basictypes.h"
-#include "ua_namespace_0.h"''', end='\n', file=fh);
-
 #plugin handling
 import os
 files = [f for f in os.listdir('.') if os.path.isfile(f) and f[-3:] == ".py" and f[:7] == "plugin_"]