소스 검색

support data types that are different from (nsIndex==0) (#1605)

support both internal and custom data types that are different from nsIndex==0
Thomas Bender 7 년 전
부모
커밋
ba3b55ab4a
2개의 변경된 파일36개의 추가작업 그리고 18개의 파일을 삭제
  1. 22 7
      src/ua_types.c
  2. 14 11
      src/ua_types_encoding_binary.c

+ 22 - 7
src/ua_types.c

@@ -41,13 +41,29 @@ const UA_ExpandedNodeId UA_EXPANDEDNODEID_NULL = {{0, UA_NODEIDTYPE_NUMERIC, {0}
  * more efficient. */
 const UA_DataType *
 UA_findDataType(const UA_NodeId *typeId) {
-    if(typeId->identifierType != UA_NODEIDTYPE_NUMERIC ||
-       typeId->namespaceIndex != 0)
+    if(typeId->identifierType != UA_NODEIDTYPE_NUMERIC)
         return NULL;
+
+    /* Always look in built-in types first
+     * (may contain data types from all namespaces) */
     for(size_t i = 0; i < UA_TYPES_COUNT; ++i) {
-        if(UA_TYPES[i].typeId.identifier.numeric == typeId->identifier.numeric)
+        if(UA_TYPES[i].typeId.identifier.numeric == typeId->identifier.numeric
+           && UA_TYPES[i].typeId.namespaceIndex == typeId->namespaceIndex)
             return &UA_TYPES[i];
     }
+
+    /* TODO When other namespace look in custom types, too, requires access to custom types array here! */
+    /*if(typeId->namespaceIndex != 0) {
+        size_t customTypesArraySize;
+        const UA_DataType *customTypesArray;
+        UA_getCustomTypes(&customTypesArraySize, &customTypesArray);
+        for(size_t i = 0; i < customTypesArraySize; ++i) {
+            if(customTypesArray[i].typeId.identifier.numeric == typeId->identifier.numeric
+               && customTypesArray[i].typeId.namespaceIndex == typeId->namespaceIndex)
+                return &customTypesArray[i];
+        }
+    }*/
+
     return NULL;
 }
 
@@ -281,15 +297,14 @@ UA_NodeId_isNull(const UA_NodeId *p) {
 
 UA_Boolean
 UA_NodeId_equal(const UA_NodeId *n1, const UA_NodeId *n2) {
+    if(n1 == NULL || n2 == NULL)
+        return false;
     if(n1->namespaceIndex != n2->namespaceIndex ||
        n1->identifierType!=n2->identifierType)
         return false;
     switch(n1->identifierType) {
     case UA_NODEIDTYPE_NUMERIC:
-        if(n1->identifier.numeric == n2->identifier.numeric)
-            return true;
-        else
-            return false;
+        return (n1->identifier.numeric == n2->identifier.numeric);
     case UA_NODEIDTYPE_STRING:
         return UA_String_equal(&n1->identifier.string,
                                &n2->identifier.string);

+ 14 - 11
src/ua_types_encoding_binary.c

@@ -800,20 +800,23 @@ UA_findDataTypeByBinaryInternal(const UA_NodeId *typeId, Ctx *ctx) {
     if(typeId->identifierType != UA_NODEIDTYPE_NUMERIC)
         return NULL;
 
-    /* Custom or standard data type? */
-    const UA_DataType *types = UA_TYPES;
-    size_t typesSize = UA_TYPES_COUNT;
-    if(typeId->namespaceIndex != 0) {
-        types = ctx->customTypesArray;
-        typesSize = ctx->customTypesArraySize;
+    /* Always look in built-in types first
+     * (may contain data types from all namespaces) */
+    for(size_t i = 0; i < UA_TYPES_COUNT; ++i) {
+        if(UA_TYPES[i].binaryEncodingId == typeId->identifier.numeric &&
+           UA_TYPES[i].typeId.namespaceIndex == typeId->namespaceIndex)
+            return &UA_TYPES[i];
     }
 
-    /* Iterate over the array */
-    for(size_t i = 0; i < typesSize; ++i) {
-        if(types[i].binaryEncodingId == typeId->identifier.numeric &&
-           types[i].typeId.namespaceIndex == typeId->namespaceIndex)
-            return &types[i];
+    /* When other namespace look in custom types, too */
+    if(typeId->namespaceIndex != 0) {
+        for(size_t i = 0; i < ctx->customTypesArraySize; ++i) {
+            if(ctx->customTypesArray[i].binaryEncodingId == typeId->identifier.numeric &&
+               ctx->customTypesArray[i].typeId.namespaceIndex == typeId->namespaceIndex)
+                return &ctx->customTypesArray[i];
+        }
     }
+
     return NULL;
 }