Ver código fonte

fix(server): call register callback for every client registering

Stefan Profanter 5 anos atrás
pai
commit
1e76b7e786
2 arquivos alterados com 12 adições e 7 exclusões
  1. 3 2
      include/open62541/server.h
  2. 9 5
      src/server/ua_services_discovery.c

+ 3 - 2
include/open62541/server.h

@@ -564,8 +564,9 @@ typedef void (*UA_Server_registerServerCallback)(const UA_RegisteredServer *regi
                                                  void* data);
 
 /* Set the callback which is called if another server registeres or unregisters
- * with this instance. If called multiple times, previous data will be
- * overwritten.
+ * with this instance. This callback is called every time the server gets a register
+ * call. This especially means that for every periodic server register the callback will
+ * be called.
  *
  * @param server
  * @param cb the callback

+ 9 - 5
src/server/ua_services_discovery.c

@@ -441,15 +441,19 @@ process_RegisterServer(UA_Server *server, UA_Session *session,
 #else
         UA_atomic_addSize(&server->discoveryManager.registeredServersSize, 1);
 #endif
-
-        if(server->discoveryManager.registerServerCallback)
-            server->discoveryManager.
-                registerServerCallback(requestServer,
-                                       server->discoveryManager.registerServerCallbackData);
     } else {
         UA_RegisteredServer_deleteMembers(&registeredServer_entry->registeredServer);
     }
 
+    // Always call the callback, if it is set.
+    // Previously we only called it if it was a new register call. It may be the case that this endpoint
+    // registered before, then crashed, restarts and registeres again. In that case the entry is not deleted
+    // and the callback would not be called.
+    if(server->discoveryManager.registerServerCallback)
+        server->discoveryManager.
+            registerServerCallback(requestServer,
+                                   server->discoveryManager.registerServerCallbackData);
+
     // copy the data from the request into the list
     UA_RegisteredServer_copy(requestServer, &registeredServer_entry->registeredServer);
     registeredServer_entry->lastSeen = UA_DateTime_nowMonotonic();