Bläddra i källkod

simplify the variable nodes

Julius Pfrommer 9 år sedan
förälder
incheckning
5bbab27f49

+ 1 - 1
include/ua_types.h

@@ -193,7 +193,7 @@ typedef struct {
 typedef struct {
     UA_Int32  arrayLength;        // total number of elements in the data-pointer
     void     *dataPtr;
-    UA_Int32  arrayDimensionsLength;
+    UA_Int32  arrayDimensionsSize;
     UA_Int32 *arrayDimensions;
 } UA_VariantData;
 

+ 1 - 12
src/server/ua_nodes.c

@@ -102,9 +102,7 @@ void UA_VariableNode_init(UA_VariableNode *p) {
     p->nodeClass = UA_NODECLASS_VARIABLE;
     UA_Variant_init(&p->value);
     UA_NodeId_init(&p->dataType);
-    p->valueRank = 0;
-    p->arrayDimensionsSize = -1;
-    p->arrayDimensions = UA_NULL;
+    p->valueRank = -2; // scalar or array of any dimension
     p->accessLevel = 0;
     p->userAccessLevel = 0;
     p->minimumSamplingInterval = 0.0;
@@ -121,8 +119,6 @@ UA_VariableNode * UA_VariableNode_new(void) {
 void UA_VariableNode_deleteMembers(UA_VariableNode *p) {
     UA_Node_deleteMembers((UA_Node*)p);
     UA_Variant_deleteMembers(&p->value);
-    UA_Array_delete(p->arrayDimensions, p->arrayDimensionsSize, &UA_TYPES[UA_TYPES_UINT32]);
-    p->arrayDimensionsSize = -1;
 }
 
 void UA_VariableNode_delete(UA_VariableNode *p) {
@@ -141,13 +137,6 @@ UA_StatusCode UA_VariableNode_copy(const UA_VariableNode *src, UA_VariableNode *
         UA_VariableNode_deleteMembers(dst);
         return retval;
     }
-    retval = UA_Array_copy(src->arrayDimensions, src->arrayDimensionsSize, (void**)&dst->arrayDimensions,
-                           &UA_TYPES[UA_TYPES_UINT32]);
-    if(retval) {
-        UA_VariableNode_deleteMembers(dst);
-        return retval;
-    }
-    dst->arrayDimensionsSize = src->arrayDimensionsSize;
     dst->accessLevel = src->accessLevel;
     dst->userAccessLevel = src->accessLevel;
     dst->minimumSamplingInterval = src->minimumSamplingInterval;

+ 7 - 3
src/server/ua_nodes.h

@@ -35,9 +35,13 @@ typedef struct {
     UA_STANDARD_NODEMEMBERS
     UA_Variant value;
     UA_NodeId dataType;
-    UA_Int32 valueRank;
-    UA_Int32 arrayDimensionsSize;
-    UA_UInt32 *arrayDimensions;
+    UA_Int32 valueRank; /**< n >= 1: the value is an array with the specified number of dimensions.
+                             n = 0: the value is an array with one or more dimensions.
+                             n = -1: the value is a scalar.
+                             n = -2: the value can be a scalar or an array with any number of dimensions.
+                             n = -3:  the value can be a scalar or a one dimensional array. */
+    // UA_Int32 arrayDimensionsSize; // taken from the value-variant
+    // UA_UInt32 *arrayDimensions;
     UA_Byte accessLevel;
     UA_Byte userAccessLevel;
     UA_Double minimumSamplingInterval;

+ 0 - 6
src/server/ua_server.c

@@ -481,12 +481,6 @@ UA_Server * UA_Server_new(void) {
                           &((UA_String *)(namespaceArray->value.storage.data.dataPtr))[0]);
     UA_String_copycstring("urn:myServer:myApplication",
                           &((UA_String *)(namespaceArray->value.storage.data.dataPtr))[1]);
-    UA_UInt32 *dimensions = UA_malloc(sizeof(UA_UInt32));
-    if(dimensions) {
-        *dimensions = 2;
-        namespaceArray->arrayDimensions = dimensions;
-        namespaceArray->arrayDimensionsSize = 1;
-    }
     namespaceArray->dataType.identifier.numeric = UA_TYPES_IDS[UA_TYPES_STRING];
     namespaceArray->valueRank = 1;
     namespaceArray->minimumSamplingInterval = 1.0;

+ 7 - 6
src/server/ua_services_nodemanagement.c

@@ -55,12 +55,13 @@ static UA_StatusCode parseVariableNode(UA_ExtensionObject *attributes, UA_Node *
     if(attr.specifiedAttributes & UA_NODEATTRIBUTESMASK_VALUERANK)
         vnode->valueRank = attr.valueRank;
 
-    if(attr.specifiedAttributes & UA_NODEATTRIBUTESMASK_ARRAYDIMENSIONS) {
-        vnode->arrayDimensionsSize = attr.arrayDimensionsSize;
-        vnode->arrayDimensions = attr.arrayDimensions;
-        attr.arrayDimensionsSize = -1;
-        attr.arrayDimensions = UA_NULL;
-    }
+    // don't use extra dimension spec. This comes from the value.
+    /* if(attr.specifiedAttributes & UA_NODEATTRIBUTESMASK_ARRAYDIMENSIONS) { */
+    /*     vnode->arrayDimensionsSize = attr.arrayDimensionsSize; */
+    /*     vnode->arrayDimensions = attr.arrayDimensions; */
+    /*     attr.arrayDimensionsSize = -1; */
+    /*     attr.arrayDimensions = UA_NULL; */
+    /* } */
 
     if(attr.specifiedAttributes & UA_NODEATTRIBUTESMASK_DATATYPE ||
        attr.specifiedAttributes & UA_NODEATTRIBUTESMASK_OBJECTTYPEORDATATYPE) {

+ 5 - 5
src/ua_types.c

@@ -570,9 +570,9 @@ UA_TYPE_NEW_DEFAULT(UA_Variant)
 void UA_Variant_init(UA_Variant *p) {
     p->storageType = UA_VARIANT_DATA;
     p->storage.data.arrayLength = -1;  // no element, p->data == UA_NULL
-    p->storage.data.dataPtr        = UA_NULL;
-    p->storage.data.arrayDimensions       = UA_NULL;
-    p->storage.data.arrayDimensionsLength = -1;
+    p->storage.data.dataPtr = UA_NULL;
+    p->storage.data.arrayDimensions = UA_NULL;
+    p->storage.data.arrayDimensionsSize = -1;
     UA_NodeId_init(&p->typeId);
     p->type = UA_NULL;
 }
@@ -625,10 +625,10 @@ UA_StatusCode UA_Variant_copy(UA_Variant const *src, UA_Variant *dst) {
         UA_NodeId_copy(&src->typeId, &dst->typeId);
         dstdata->arrayLength = srcdata->arrayLength;
         if(srcdata->arrayDimensions) {
-            retval |= UA_Array_copy(srcdata->arrayDimensions, srcdata->arrayDimensionsLength,
+            retval |= UA_Array_copy(srcdata->arrayDimensions, srcdata->arrayDimensionsSize,
                                     (void **)&dstdata->arrayDimensions, &UA_TYPES[UA_TYPES_INT32]);
             if(retval == UA_STATUSCODE_GOOD)
-                dstdata->arrayDimensionsLength = srcdata->arrayDimensionsLength;
+                dstdata->arrayDimensionsSize = srcdata->arrayDimensionsSize;
             else {
                 UA_Variant_deleteMembers(dst);
                 UA_Variant_init(dst);

+ 7 - 4
src/ua_types_encoding_binary.c

@@ -709,7 +709,8 @@ size_t UA_Variant_calcSizeBinary(UA_Variant const *p) {
     }
 
     if(arrayLength != 1 && data->arrayDimensions != UA_NULL)
-        length += UA_Array_calcSizeBinary(data->arrayDimensions, data->arrayDimensionsLength, &UA_TYPES[UA_TYPES_INT32]);
+        length += UA_Array_calcSizeBinary(data->arrayDimensions, data->arrayDimensionsSize,
+                                          &UA_TYPES[UA_TYPES_INT32]);
     
     if(p->storageType == UA_VARIANT_DATASOURCE)
         p->storage.datasource.release(p->storage.datasource.handle, data);
@@ -763,7 +764,8 @@ UA_StatusCode UA_Variant_encodeBinary(UA_Variant const *src, UA_ByteString *dst,
     }
 
     if(hasDimensions)
-        retval |= UA_Array_encodeBinary(data->arrayDimensions, data->arrayDimensionsLength, &UA_TYPES[UA_TYPES_INT32], dst, offset);
+        retval |= UA_Array_encodeBinary(data->arrayDimensions, data->arrayDimensionsSize,
+                                        &UA_TYPES[UA_TYPES_INT32], dst, offset);
 
     if(src->storageType == UA_VARIANT_DATASOURCE)
         src->storage.datasource.release(src->storage.datasource.handle, data);
@@ -814,9 +816,10 @@ UA_StatusCode UA_Variant_decodeBinary(UA_ByteString const *src, size_t *offset,
     }
 
     if(hasDimensions && retval == UA_STATUSCODE_GOOD) {
-        retval |= UA_Int32_decodeBinary(src, offset, &data->arrayDimensionsLength);
+        retval |= UA_Int32_decodeBinary(src, offset, &data->arrayDimensionsSize);
         if(retval == UA_STATUSCODE_GOOD)
-            retval |= UA_Array_decodeBinary(src, offset, data->arrayDimensionsLength, &data->dataPtr, &UA_TYPES[UA_TYPES_INT32]);
+            retval |= UA_Array_decodeBinary(src, offset, data->arrayDimensionsSize,
+                                            &data->dataPtr, &UA_TYPES[UA_TYPES_INT32]);
         if(retval)
             data->arrayLength = -1; // for deleteMembers
     }

+ 5 - 5
tests/check_builtin.c

@@ -1480,7 +1480,7 @@ START_TEST(UA_Variant_copyShallWorkOnSingleValueExample) {
 		ck_assert_int_eq(copiedString.data[i], testString.data[i]);
 	ck_assert_int_eq(copiedString.length, testString.length);
 
-	ck_assert_int_eq(value.storage.data.arrayDimensionsLength, copiedValue.storage.data.arrayDimensionsLength);
+	ck_assert_int_eq(value.storage.data.arrayDimensionsSize, copiedValue.storage.data.arrayDimensionsSize);
 	ck_assert_int_eq(value.storage.data.arrayLength, copiedValue.storage.data.arrayLength);
 
 	//finally
@@ -1508,7 +1508,7 @@ START_TEST(UA_Variant_copyShallWorkOn1DArrayExample) {
 
 	value.storage.data.arrayLength = 3;
 	value.storage.data.dataPtr = (void *)srcArray;
-	value.storage.data.arrayDimensionsLength = 1;
+	value.storage.data.arrayDimensionsSize = 1;
 	value.storage.data.arrayDimensions = dimensions;
 	value.type = &UA_TYPES[UA_TYPES_STRING];
 
@@ -1530,7 +1530,7 @@ START_TEST(UA_Variant_copyShallWorkOn1DArrayExample) {
 	}
 	ck_assert_int_eq(((UA_String *)copiedValue.storage.data.dataPtr)[0].data[2], 'o');
 	ck_assert_int_eq(((UA_String *)copiedValue.storage.data.dataPtr)[0].data[3], 'p');
-	ck_assert_int_eq(value.storage.data.arrayDimensionsLength, copiedValue.storage.data.arrayDimensionsLength);
+	ck_assert_int_eq(value.storage.data.arrayDimensionsSize, copiedValue.storage.data.arrayDimensionsSize);
 	ck_assert_int_eq(value.storage.data.arrayLength, copiedValue.storage.data.arrayLength);
 
 	//finally
@@ -1563,7 +1563,7 @@ START_TEST(UA_Variant_copyShallWorkOn2DArrayExample) {
 
 	value.storage.data.arrayLength = 6;
 	value.storage.data.dataPtr     = srcArray;
-	value.storage.data.arrayDimensionsLength = 2;
+	value.storage.data.arrayDimensionsSize = 2;
 	value.storage.data.arrayDimensions       = dimensions;
 	value.type = &UA_TYPES[UA_TYPES_INT32];
 
@@ -1592,7 +1592,7 @@ START_TEST(UA_Variant_copyShallWorkOn2DArrayExample) {
 		ck_assert_int_eq(i2, i);
 	}
 
-	ck_assert_int_eq(value.storage.data.arrayDimensionsLength, copiedValue.storage.data.arrayDimensionsLength);
+	ck_assert_int_eq(value.storage.data.arrayDimensionsSize, copiedValue.storage.data.arrayDimensionsSize);
 	ck_assert_int_eq(value.storage.data.arrayLength, copiedValue.storage.data.arrayLength);
 
 	//finally