Browse Source

remove UA_borrowed. not-deleting variant data is now indicated by the storagetype enum.

Julius Pfrommer 10 years ago
parent
commit
b2f4460e60
4 changed files with 6 additions and 28 deletions
  1. 2 9
      src/server/ua_server.c
  2. 2 8
      src/server/ua_services_attribute.c
  3. 0 2
      src/ua_types.c
  4. 2 9
      tools/generate_namespace.py

+ 2 - 9
src/server/ua_server.c

@@ -30,14 +30,6 @@ void UA_Server_init(UA_Server *server, UA_String *endpointUrl) {
     UA_SessionManager_new(&server->sessionManager, MAXSESSIONCOUNT, SESSIONLIFETIME,
                           STARTSESSIONID);
 
-    // todo: get this out of here!!!
-    // 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 = (void (*)(void *))phantom_delete;
-        UA_borrowed_.types[i].deleteMembers = (void (*)(void *))phantom_delete;
-    }
-
     UA_NodeStore_new(&server->nodestore);
     //ns0: C2UA_STRING("http://opcfoundation.org/UA/"));
     //ns1: C2UA_STRING("http://localhost:16664/open62541/"));
@@ -519,10 +511,11 @@ void UA_Server_init(UA_Server *server, UA_String *endpointUrl) {
     UA_QualifiedName_copycstring("State", &state->browseName);
     UA_LocalizedText_copycstring("State", &state->displayName);
     UA_LocalizedText_copycstring("State", &state->description);
-    state->value.vt = &UA_borrowed_.types[UA_SERVERSTATE];
+    state->value.vt = &UA_.types[UA_SERVERSTATE];
     state->value.storage.data.arrayDimensionsLength = 1; // added to ensure encoding in readreponse
     state->value.storage.data.arrayLength = 1;
     state->value.storage.data.dataPtr = &status->state; // points into the other object.
+    state->value.storageType = UA_VARIANT_DATA_NODELETE;
     UA_NodeStore_insert(server->nodestore, (UA_Node**)&state, UA_NODESTORE_INSERT_UNIQUE);
 
     //TODO: free(namespaceArray->value.data) later or forget it

+ 2 - 8
src/server/ua_services_attribute.c

@@ -128,10 +128,7 @@ static UA_DataValue service_read_node(UA_Server *server, const UA_ReadValueId *i
     case UA_ATTRIBUTEID_VALUE:
         CHECK_NODECLASS(UA_NODECLASS_VARIABLE | UA_NODECLASS_VARIABLETYPE);
         v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
-        // TODO: Ensure that the borrowed value is not freed prematurely (multithreading)
-        /* retval |= UA_Variant_borrowSetValue(&v.value, &UA_.types[UA_VARIANT], */
-        /*                                     &((UA_VariableNode *)node)->value); */
-        retval |= UA_Variant_copy(&((UA_VariableNode *)node)->value, &v.value);
+        retval |= UA_Variant_copy(&((UA_VariableNode *)node)->value, &v.value); // todo: zero-copy
         break;
 
     case UA_ATTRIBUTEID_DATATYPE:
@@ -320,10 +317,7 @@ UA_Int32 Service_Write_writeNode(UA_Server *server, UA_WriteValue *writeValue,
 
     case UA_ATTRIBUTEID_VALUE:
         if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT) {
-            // TODO: Ensure that the borrowed value is not freed prematurely (multithreading)
-            /* retval |= UA_Variant_borrowSetValue(&v.value, &UA_.types[UA_VARIANT], */
-            /*                                     &((UA_VariableNode *)node)->value); */
-            retval |= UA_Variant_copy(&writeValue->value.value, &((UA_VariableNode *)node)->value);
+            retval |= UA_Variant_copy(&writeValue->value.value, &((UA_VariableNode *)node)->value); // todo: zero-copy
             *result = UA_STATUSCODE_GOOD;
         }
 

+ 0 - 2
src/ua_types.c

@@ -908,8 +908,6 @@ void UA_Variant_print(const UA_Variant *p, FILE *stream) {
     fprintf(stream, "(UA_Variant){/*%s*/", p->vt->name);
     if(p->vt == &UA_.types[ns0id])
         fprintf(stream, "UA_.types[%d]", ns0id);
-    else if(p->vt == &UA_borrowed_.types[ns0id])
-        fprintf(stream, "UA_borrowed_.types[%d]", ns0id);
     else
         fprintf(stream, "ERROR (not a builtin type)");
     UA_Int32_print(&p->arrayLength, stream);

+ 2 - 9
tools/generate_namespace.py

@@ -105,9 +105,8 @@ printh('''/**********************************************************
  * @retval the corresponding index into UA_VTable
  */\n
 UA_Int32 UA_ns0ToVTableIndex(const UA_NodeId *id);\n
-extern const UA_VTable UA_;\n
-static UA_Int32 phantom_delete(void * p) { return UA_SUCCESS; }
-extern const UA_VTable UA_borrowed_;\n
+extern const UA_VTable UA_;
+
 /**
  * @brief the set of possible indices into UA_VTable
  *
@@ -186,12 +185,6 @@ for row in rows:
 
 printc('''}};''')
 
-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"+
-"};")
-
 printh('\n#define SIZE_UA_VTABLE '+str(i));
 
 printh('\n#endif /* OPCUA_NAMESPACE_0_H_ */')