Преглед изворни кода

merged generate_namespace

Conflicts:
	examples/src/xml2ns0.c
	include/ua_basictypes.h
	src/Makefile.am
	tools/generate_builtin.py
	tools/generate_namespace.py
	
While tests are working this merge unfortunately reintroduced a bug in
handling extension-objects.
Leon Urbas пре 10 година
родитељ
комит
750c95b7a3
12 измењених фајлова са 86 додато и 52 уклоњено
  1. 0 1
      AUTHORS
  2. 0 1
      COPYING
  3. 0 0
      ChangeLog
  4. 0 1
      NEWS
  5. 0 0
      README
  6. 1 0
      autogen.sh
  7. 3 2
      examples/src/xml2ns0.c
  8. 1 5
      include/ua_basictypes.h
  9. 47 3
      src/ua_basictypes.c
  10. 0 0
      tools/.coverity.sh
  11. 9 9
      tools/generate_builtin.py
  12. 25 30
      tools/generate_namespace.py

+ 0 - 1
AUTHORS

@@ -1 +0,0 @@
-

+ 0 - 1
COPYING

@@ -1 +0,0 @@
-<Place your desired license here.>


+ 0 - 1
NEWS

@@ -1 +0,0 @@
-Sample NEWS file for OPCUAServer project.


+ 1 - 0
autogen.sh

@@ -1,4 +1,5 @@
 #!/bin/bash
 
 #Script to invoke creation of configure script
+touch COPYING NEWS README AUTHORS ChangeLog
 autoreconf -fi

+ 3 - 2
examples/src/xml2ns0.c

@@ -30,7 +30,7 @@ void sam_attach(Namespace *ns,UA_Int32 ns0id,UA_Int32 type, void* p) {
 	nodeid.namespace = ns->namespaceId;
 	nodeid.identifier.numeric = ns0id;
 	nodeid.encodingByte = UA_NODEIDTYPE_FOURBYTE;
-	const UA_Node *result;
+	const UA_Node* result;
 	Namespace_get(ns,&nodeid,&result,&lock);
 	if (result->nodeClass == UA_NODECLASS_VARIABLE) {
 		UA_VariableNode* variable = (UA_VariableNode*) result;
@@ -213,13 +213,14 @@ int main() {
 	UA_Int32 i=0;
 	UA_Int32 retval=UA_SUCCESS;
 	UA_DateTime tStart = UA_DateTime_now();
-	// encoding takes roundabout 10 ns on my virtual machine with -O0, so 1E5 takes a second
+	// encoding takes roundabout 10 µs on my virtual machine with -O0, so 1E5 takes a second
 	for (i=0;i<1E5 && retval == UA_SUCCESS;i++) {
 		pos = 0;
 		sam.serverStatus.currentTime = UA_DateTime_now();
 		retval |= UAX_NodeId_encodeBinary(n.ns,&nodeid,&pos,&buffer);
 	}
 	UA_DateTime tEnd = UA_DateTime_now();
+	// tStart, tEnd count in 100 ns steps = 10 µs
 	UA_Double tDelta = ( tEnd - tStart ) / ( 10.0 * i);
 
 	printf("encode server node %d times: time/enc=%f us, retval=%d\n",i, tDelta, retval);

+ 1 - 5
include/ua_basictypes.h

@@ -176,10 +176,6 @@ UA_Int32 TYPE##_copy(TYPE const *src, TYPE *dst) {return TYPE_AS##_copy((TYPE_AS
 	UA_TYPE_METHOD_PROTOTYPES_AS_WOXML(TYPE, TYPE_AS) \
 	UA_TYPE_METHOD_DECODEXML_AS(TYPE, TYPE_AS)
 
-#define UA_TYPE_METHOD_PROTOTYPES_AS(TYPE, TYPE_AS) \
-UA_TYPE_METHOD_PROTOTYPES_AS_WOXML(TYPE, TYPE_AS) \
-UA_TYPE_METHOD_DECODEXML_AS(TYPE, TYPE_AS)
-
 #define UA_TYPE_METHOD_NEW_DEFAULT(TYPE) \
 UA_Int32 TYPE##_new(TYPE ** p) { \
 	UA_Int32 retval = UA_SUCCESS;\
@@ -398,7 +394,6 @@ typedef struct XML_Stack {
 } XML_Stack;
 
 typedef struct UA_VTable {
-	UA_Byte* name;
 	UA_UInt32 ns0Id;
 	UA_Int32 (*calcSize)(void const * ptr);
 	UA_Int32 (*decodeBinary)(UA_ByteString const * src, UA_Int32* pos, void* dst);
@@ -409,6 +404,7 @@ typedef struct UA_VTable {
 	UA_Int32 (*copy)(void const *src,void *dst);
 	UA_Int32 (*delete)(void * p);
 	UA_UInt32 memSize; // size of the struct only in memory (no dynamic components)
+	UA_Byte* name;
 } UA_VTable;
 
 /* VariantBinaryEncoding - Part: 6, Chapter: 5.2.2.16, Page: 22 */

+ 47 - 3
src/ua_basictypes.c

@@ -8,7 +8,7 @@
 
 static inline UA_Int32 UA_VTable_isValidType(UA_Int32 type) {
 	if(type < 0 /* UA_BOOLEAN */ || type > 271 /* UA_INVALID */)
-		return UA_INVALIDTYPE;
+		return UA_ERR_INVALID_VALUE;
 	return UA_SUCCESS;
 }
 
@@ -174,6 +174,25 @@ UA_TYPE_METHOD_DELETEMEMBERS_NOACTION(UA_Boolean)
 UA_TYPE_METHOD_NEW_DEFAULT(UA_Boolean)
 UA_TYPE_METHOD_COPY(UA_Boolean)
 
+UA_Int32 UA_Boolean_copycstring(cstring src, UA_Boolean* dst) {
+	*dst = UA_FALSE;
+	if (0 == strncmp(src, "true", 4) || 0 == strncmp(src, "TRUE", 4)) {
+		*dst = UA_TRUE;
+	}
+	return UA_SUCCESS;
+}
+UA_Int32 UA_Boolean_decodeXML(XML_Stack* s, XML_Attr* attr, UA_Boolean* dst, _Bool isStart) {
+	DBG_VERBOSE(printf("UA_Boolean entered with dst=%p,isStart=%d\n", (void* ) dst, isStart));
+	if (isStart) {
+		if (dst == UA_NULL) {
+			UA_Boolean_new(&dst);
+			s->parent[s->depth - 1].children[s->parent[s->depth - 1].activeChild].obj = (void*) dst;
+		}
+		UA_Boolean_copycstring((cstring) attr[1], dst);
+	}
+	return UA_SUCCESS;
+}
+
 /* UA_Byte */
 UA_TYPE_METHOD_CALCSIZE_SIZEOF(UA_Byte)
 UA_TYPE_ENCODEBINARY(UA_Byte, dst->data[(*pos)++] = *src;)
@@ -183,6 +202,7 @@ UA_TYPE_METHOD_DELETEMEMBERS_NOACTION(UA_Byte)
 UA_TYPE_METHOD_INIT_DEFAULT(UA_Byte)
 UA_TYPE_METHOD_NEW_DEFAULT(UA_Byte)
 UA_TYPE_METHOD_COPY(UA_Byte)
+UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_Byte)
 
 /* UA_SByte */
 UA_TYPE_METHOD_CALCSIZE_SIZEOF(UA_SByte)
@@ -193,6 +213,8 @@ UA_TYPE_METHOD_DELETEMEMBERS_NOACTION(UA_SByte)
 UA_TYPE_METHOD_INIT_DEFAULT(UA_SByte)
 UA_TYPE_METHOD_NEW_DEFAULT(UA_SByte)
 UA_TYPE_METHOD_COPY(UA_SByte)
+UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_SByte)
+
 
 /* UA_UInt16 */
 UA_TYPE_METHOD_CALCSIZE_SIZEOF(UA_UInt16)
@@ -207,6 +229,7 @@ UA_TYPE_METHOD_DELETEMEMBERS_NOACTION(UA_UInt16)
 UA_TYPE_METHOD_INIT_DEFAULT(UA_UInt16)
 UA_TYPE_METHOD_NEW_DEFAULT(UA_UInt16)
 UA_TYPE_METHOD_COPY(UA_UInt16)
+UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_UInt16)
 
 /** UA_Int16 - signed integer, 2 bytes */
 UA_TYPE_METHOD_CALCSIZE_SIZEOF(UA_Int16)
@@ -252,6 +275,7 @@ UA_TYPE_METHOD_DELETEMEMBERS_NOACTION(UA_UInt32)
 UA_TYPE_METHOD_INIT_DEFAULT(UA_UInt32)
 UA_TYPE_METHOD_NEW_DEFAULT(UA_UInt32)
 UA_TYPE_METHOD_COPY(UA_UInt32)
+UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_UInt32)
 
 /** UA_Int64 - signed integer, 8 bytes */
 UA_TYPE_METHOD_CALCSIZE_SIZEOF(UA_Int64)
@@ -278,6 +302,7 @@ UA_TYPE_METHOD_DELETEMEMBERS_NOACTION(UA_Int64)
 UA_TYPE_METHOD_INIT_DEFAULT(UA_Int64)
 UA_TYPE_METHOD_NEW_DEFAULT(UA_Int64)
 UA_TYPE_METHOD_COPY(UA_Int64)
+UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_Int64)
 
 /** UA_UInt64 - unsigned integer, 8 bytes */
 UA_TYPE_METHOD_CALCSIZE_SIZEOF(UA_UInt64)
@@ -297,6 +322,7 @@ UA_TYPE_METHOD_DELETEMEMBERS_NOACTION(UA_UInt64)
 UA_TYPE_METHOD_INIT_DEFAULT(UA_UInt64)
 UA_TYPE_METHOD_NEW_DEFAULT(UA_UInt64)
 UA_TYPE_METHOD_COPY(UA_UInt64)
+UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_UInt64)
 
 /** UA_Float - IEE754 32bit float with biased exponent */
 UA_TYPE_METHOD_CALCSIZE_SIZEOF(UA_Float)
@@ -328,6 +354,8 @@ UA_Int32 UA_Float_init(UA_Float * p){
 }
 UA_TYPE_METHOD_NEW_DEFAULT(UA_Float)
 UA_TYPE_METHOD_COPY(UA_Float)
+UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_Float)
+
 
 /** UA_Float - IEEE754 64bit float with biased exponent*/
 UA_TYPE_METHOD_CALCSIZE_SIZEOF(UA_Double)
@@ -362,6 +390,7 @@ UA_TYPE_METHOD_DELETEMEMBERS_NOACTION(UA_Double)
 UA_TYPE_METHOD_INIT_DEFAULT(UA_Double)
 UA_TYPE_METHOD_NEW_DEFAULT(UA_Double)
 UA_TYPE_METHOD_COPY(UA_Double)
+UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_Double)
 
 /** UA_String */
 UA_Int32 UA_String_calcSize(UA_String const * string) {
@@ -594,6 +623,7 @@ UA_Int32 UA_Guid_copy(UA_Guid const *src, UA_Guid *dst)
 	retval |= UA_memcpy((void*)dst,(void*)src,UA_Guid_calcSize(UA_NULL));
 	return retval;
 }
+UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_Guid)
 
 /* UA_LocalizedText */
 UA_Int32 UA_LocalizedText_calcSize(UA_LocalizedText const * p) {
@@ -1006,6 +1036,9 @@ UA_TYPE_ENCODEBINARY(UA_ExtensionObject,
 	case UA_EXTENSIONOBJECT_ENCODINGMASK_NOBODYISENCODED:
 		break;
 	case UA_EXTENSIONOBJECT_ENCODINGMASK_BODYISBYTESTRING:
+		// FIXME: This code is valid for numeric nodeIds in ns0 only!
+		retval |= UA_[UA_ns0ToVTableIndex(src->typeId.identifier.numeric)].encodeBinary(src->body.data,pos,dst);
+		break;
 	case UA_EXTENSIONOBJECT_ENCODINGMASK_BODYISXML:
 		retval |= UA_ByteString_encodeBinary(&(src->body),pos,dst);
 		break;
@@ -1198,7 +1231,10 @@ UA_Int32 UA_DiagnosticInfo_copy(UA_DiagnosticInfo const  *src, UA_DiagnosticInfo
 
 	return retval;
 }
-UA_TYPE_METHOD_PROTOTYPES_AS(UA_DateTime,UA_Int64)
+UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_DiagnosticInfo)
+
+UA_TYPE_METHOD_PROTOTYPES_AS_WOXML(UA_DateTime,UA_Int64)
+UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_DateTime)
 UA_TYPE_METHOD_NEW_DEFAULT(UA_DateTime)
 
 #include <sys/time.h>
@@ -1263,8 +1299,12 @@ UA_TYPE_METHOD_NEW_DEFAULT(UA_XmlElement)
 UA_TYPE_METHOD_PROTOTYPES_AS(UA_IntegerId, UA_Int32)
 UA_TYPE_METHOD_NEW_DEFAULT(UA_IntegerId)
 
-UA_TYPE_METHOD_PROTOTYPES_AS(UA_StatusCode, UA_UInt32)
+UA_TYPE_METHOD_PROTOTYPES_AS_WOXML(UA_StatusCode, UA_UInt32)
 UA_TYPE_METHOD_NEW_DEFAULT(UA_StatusCode)
+UA_Int32 UA_StatusCode_decodeXML(XML_Stack* s, XML_Attr* attr, UA_StatusCode* dst, _Bool isStart) {
+	DBG_VERBOSE(printf("UA_StatusCode_decodeXML entered with dst=%p,isStart=%d\n", (void* ) dst, isStart));
+	return UA_ERR_NOT_IMPLEMENTED;
+}
 
 /** QualifiedName - Part 4, Chapter
  * but see Part 6, Chapter 5.2.2.13 for Binary Encoding
@@ -1625,6 +1665,8 @@ UA_Int32 UA_DataValue_copy(UA_DataValue const *src, UA_DataValue *dst){
 	UA_Variant_copy(&(src->value),&(dst->value));
 	return retval;
 }
+UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_DataValue)
+
 
 /* UA_InvalidType - internal type necessary to handle inited Variants correctly */
 UA_Int32 UA_InvalidType_calcSize(UA_InvalidType const * p) { return 0; }
@@ -1636,3 +1678,5 @@ UA_Int32 UA_InvalidType_deleteMembers(UA_InvalidType* p) { return UA_ERR_INVALID
 UA_Int32 UA_InvalidType_init(UA_InvalidType* p) { return UA_ERR_INVALID_VALUE; }
 UA_Int32 UA_InvalidType_copy(UA_InvalidType const* src, UA_InvalidType *dst) { return UA_ERR_INVALID_VALUE; }
 UA_Int32 UA_InvalidType_new(UA_InvalidType** p) { return UA_ERR_INVALID_VALUE; }
+UA_TYPE_METHOD_DECODEXML_NOTIMPL(UA_InvalidType)
+

.coverity.sh → tools/.coverity.sh


+ 9 - 9
tools/generate_builtin.py

@@ -49,12 +49,12 @@ def camlCase2CCase(item):
 
 # 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":
-			typename = stripTypename(child.get("TypeName"))
-			if typename not in printed_types:
-				return False
-	return True
+    for child in element:
+        if child.tag == "{http://opcfoundation.org/BinarySchema/}Field":
+            typename = stripTypename(child.get("TypeName"))
+            if typename not in printed_types:
+                return False
+    return True
 
 # There are three types of types in the bsd file:
 # StructuredType, EnumeratedType OpaqueType
@@ -86,7 +86,7 @@ def createEnumerated(element):
 def createStructured(element):
     valuemap = OrderedDict()
     name = "UA_" + element.get("Name")
-    print("\n/** @name UA_" + name + " */", end='\n', file=fh)
+    print("\n/** @name " + name + " */\n", file=fh)
 
     lengthfields = set()
     for child in element:
@@ -256,7 +256,7 @@ def createStructured(element):
 	
 def createOpaque(element):
     name = "UA_" + element.get("Name")
-    print("\n/** @name UA_" + name + " */", end='\n', file=fh)
+    print("\n/** @name " + name + " */\n", file=fh)
     for child in element:
         if child.tag == "{http://opcfoundation.org/BinarySchema/}Documentation":
             print("/** @brief " + child.text + " */", end='\n', file=fh)
@@ -303,7 +303,7 @@ print('''/**
  * 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);
 
 # types for which we create a vector type

+ 25 - 30
tools/generate_namespace.py

@@ -26,9 +26,8 @@ exclude_types = set(["Number", "Integer", "UInteger", "Enumeration",
 	"MultiStateDiscreteType", "ProgramDiagnosticType", "StateVariableType", "FiniteStateVariableType",
 	"TransitionVariableType", "FiniteTransitionVariableType", "BuildInfoType", "TwoStateVariableType",
 	"ConditionVariableType", "MultiStateValueDiscreteType", "OptionSetType", "ArrayItemType",
-	"YArrayItemType", "XYArrayItemType", "ImageItemType", "CubeItemType", "NDimensionArrayItemType"
-	])
-	
+	"YArrayItemType", "XYArrayItemType", "ImageItemType", "CubeItemType", "NDimensionArrayItemType"])
+
 f = open(sys.argv[1])
 input_str = f.read() + "\nInvalidType,0,DataType"
 input_str = input_str.replace('\r','')
@@ -111,27 +110,25 @@ 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"
+        name = "UA_Variant"
     elif row[0] == "Structure":
         name = "UA_ExtensionObject"
     else:
-        name = "UA_" + row[0]
+	name = "UA_" + row[0]
 
     print('#define '+name.upper()+'_NS0 '+row[1], file=fh)
 
-    print("\t{" +
-          '(UA_Byte*)"'+ name +'",' +
-          row[1] + 
-          ",(UA_Int32(*)(void const*))"+ name +"_calcSize" + 
-          ",(UA_Int32(*)(UA_ByteString const*,UA_Int32*,void*))"+ name + "_decodeBinary" +
-          ",(UA_Int32(*)(void const*,UA_Int32*,UA_ByteString*))"+ name +"_encodeBinary"+
+    print("\t{" + row[1] + 
+          ",(UA_Int32(*)(void const*))"+name+"_calcSize" + 
+          ",(UA_Int32(*)(UA_ByteString const*,UA_Int32*,void*))"+name+ "_decodeBinary" +
+          ",(UA_Int32(*)(void const*,UA_Int32*,UA_ByteString*))"+name+"_encodeBinary"+
           ",(UA_Int32(*)(XML_Stack*,XML_Attr*,void*,_Bool))"+ name + "_decodeXML" +
-          ",(UA_Int32(*)(void *))" + name + "_init" +
-          ",(UA_Int32(*)(void **))" + name + "_new" +
-	  ",(UA_Int32(*)(void const * ,void*))" + name + "_copy" +
-          ",(UA_Int32(*)(void *))" + name + "_delete" +
-          (",sizeof(" + name + ")" if (name != "UA_InvalidType") else ",0") +
-          "},",end='\n',file=fc) 
+          ",(UA_Int32(*)(void *))"+name+"_init"+
+          ",(UA_Int32(*)(void **))"+name+"_new"+
+          ",(UA_Int32(*)(void const * ,void*))"+name+"_copy"+
+          ",(UA_Int32(*)(void *))"+name+"_delete"+
+          (",sizeof("+name+")" if (name != "UA_InvalidType") else ",0") +
+          ',(UA_Byte*)"'+name+'"},',end='\n',file=fc) 
 
 print("};\n\nUA_VTable UA_noDelete_[] = {", end='\n', file=fc)
 
@@ -145,19 +142,17 @@ for row in rows:
     else:	
 	name = "UA_" + row[0]
 
-    print("\t{" +
-          '(UA_Byte*)"' + name + '",' +
-          row[1] + 
-          ",(UA_Int32(*)(void const*))" + name + "_calcSize" + 
-          ",(UA_Int32(*)(UA_ByteString const*,UA_Int32*,void*))" + name + "_decodeBinary" +
-          ",(UA_Int32(*)(void const*,UA_Int32*,UA_ByteString*))" + name + "_encodeBinary"+
-          ",(UA_Int32(*)(XML_Stack*,XML_Attr*,void*,_Bool))" + name + "_decodeXML" +
-          ",(UA_Int32(*)(void *))" + name + "_init" +
-          ",(UA_Int32(*)(void **))" + name + "_new" +
-	  ",(UA_Int32(*)(void const * ,void*))" + name + "_copy" +
-          ",(UA_Int32(*)(void *))phantom_delete" +
-          (",sizeof(" + name + ")" if (name != "UA_InvalidType") else ",0") +
-          "},",end='\n',file=fc)
+    print("\t{" + row[1] +
+          ",(UA_Int32(*)(void const*))"+name+"_calcSize" + 
+          ",(UA_Int32(*)(UA_ByteString const*,UA_Int32*,void*))"+name+ "_decodeBinary" +
+          ",(UA_Int32(*)(void const*,UA_Int32*,UA_ByteString*))"+name+"_encodeBinary"+
+          ",(UA_Int32(*)(XML_Stack*,XML_Attr*,void*,_Bool))" + name + "_decodeXML" +          
+          ",(UA_Int32(*)(void *))"+name+"_init"+
+          ",(UA_Int32(*)(void **))"+name+"_new"+
+          ",(UA_Int32(*)(void const * ,void*))"+name+"_copy"+
+          ",(UA_Int32(*)(void *))phantom_delete"+
+          (",sizeof("+name+")" if (name != "UA_InvalidType") else ",0") +
+          ',(UA_Byte*)"'+name+'"},',end='\n',file=fc)
 print("};", end='\n', file=fc) 
 
 print('\n#endif /* OPCUA_NAMESPACE_0_H_ */', end='\n', file=fh)