Pārlūkot izejas kodu

FindServers implemented

Stasik0 10 gadi atpakaļ
vecāks
revīzija
b23fcf1311

+ 7 - 0
src/server/ua_server.c

@@ -212,6 +212,13 @@ UA_Server * UA_Server_new(void) {
     UA_ApplicationDescription_init(&server->description);
     UA_String_copycstring(PRODUCT_URI, &server->description.productUri);
     UA_String_copycstring(APPLICATION_URI, &server->description.applicationUri);
+    server->description.discoveryUrlsSize = 1;
+    server->description.discoveryUrls = UA_String_new();
+    if(!server->description.discoveryUrls)
+    	return UA_NULL;
+    UA_String_copycstring("opc.tcp://0.0.0.0", server->description.discoveryUrls); //TODO: what to resturn here?
+
+
     UA_LocalizedText_copycstring("Unconfigured open62541 application", &server->description.applicationName);
     server->description.applicationType = UA_APPLICATIONTYPE_SERVER;
     server->externalNamespacesSize = 0;

+ 16 - 0
src/server/ua_server_binary.c

@@ -238,6 +238,22 @@ static void processMSG(UA_Connection *connection, UA_Server *server, const UA_By
         break;
     }
 
+    case UA_NS0ID_FINDSERVERSREQUEST: {
+        UA_FindServersRequest  p;
+        UA_FindServersResponse r;
+        if(UA_FindServersRequest_decodeBinary(msg, pos, &p))
+            return;
+        UA_FindServersResponse_init(&r);
+        init_response_header(&p.requestHeader, &r.responseHeader);
+        Service_FindServers(server, &p, &r);
+        ALLOC_MESSAGE(message, UA_FindServersResponse_calcSizeBinary(&r));
+        UA_FindServersResponse_encodeBinary(&r, message, &sendOffset);
+        UA_FindServersRequest_deleteMembers(&p);
+        UA_FindServersResponse_deleteMembers(&r);
+        responseType = requestType.identifier.numeric + 3;
+        break;
+    }
+
     case UA_NS0ID_CREATESESSIONREQUEST: {
         UA_CreateSessionRequest  p;
         UA_CreateSessionResponse r;

+ 3 - 1
src/server/ua_services.h

@@ -24,7 +24,9 @@
  * @{
  */
 // Service_FindServers
-
+void Service_FindServers(UA_Server                    *server,
+                          const UA_FindServersRequest *request,
+                          UA_FindServersResponse      *response);
 /**
  * Returns the Endpoints supported by a Server and all of the configuration
  * information required to establish a SecureChannel and a Session.

+ 16 - 0
src/server/ua_services_discovery.c

@@ -2,6 +2,22 @@
 #include "ua_services.h"
 #include "ua_util.h"
 
+void Service_FindServers(UA_Server                    *server,
+                          const UA_FindServersRequest *request,
+                          UA_FindServersResponse      *response) {
+    response->servers = UA_malloc(sizeof(UA_ApplicationDescription));
+    if(!response->servers) {
+        response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
+        return;
+    }
+    if(UA_ApplicationDescription_copy(&server->description, response->servers) != UA_STATUSCODE_GOOD) {
+        UA_free(response->servers);
+        response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
+        return;
+    }
+	response->serversSize = 1;
+}
+
 void Service_GetEndpoints(UA_Server                    *server,
                           const UA_GetEndpointsRequest *request,
                           UA_GetEndpointsResponse      *response) {

+ 1 - 1
tools/generate_datatypes.py

@@ -39,7 +39,7 @@ minimal_types = ["InvalidType", "Node", "NodeClass", "ReferenceNode", "Applicati
                  "SecurityTokenRequestType", "MessageSecurityMode", "CloseSessionResponse", "CloseSessionRquest",
                  "ActivateSessionRequest", "ActivateSessionResponse", "SignatureData", "SignedSoftwareCertificate",
                  "CreateSessionResponse", "CreateSessionRequest", "EndpointDescription", "UserTokenPolicy", "UserTokenType",
-                 "GetEndpointsRequest", "GetEndpointsResponse", "PublishRequest", "PublishResponse",
+                 "GetEndpointsRequest", "GetEndpointsResponse", "PublishRequest", "PublishResponse", "FindServersRequest", "FindServersResponse",
                  "SetPublishingModeResponse", "SubscriptionAcknowledgement", "NotificationMessage", "ExtensionObject",
                  "Structure", "ReadRequest", "ReadResponse", "ReadValueId", "TimestampsToReturn", "WriteRequest",
                  "WriteResponse", "WriteValue", "SetPublishingModeRequest", "CreateMonitoredItemsResponse",