소스 검색

Added callback function to get client config from config plugin

The server implementation needs to initalize a client when it
shall register itself to a discovery server. To avoid including a
private header file of the plugin a callback function has been
declared in the server header file to be implemented by the plugin
implementation. This callback function are called by the server
when it shall initialize a client.
Jonas Green 7 년 전
부모
커밋
1e667aeb38
3개의 변경된 파일16개의 추가작업 그리고 3개의 파일을 삭제
  1. 8 0
      include/ua_server.h
  2. 6 1
      plugins/ua_config_default.c
  3. 2 2
      src/server/ua_server_discovery.c

+ 8 - 0
include/ua_server.h

@@ -20,6 +20,7 @@ extern "C" {
 #include "ua_types.h"
 #include "ua_types_generated.h"
 #include "ua_types_generated_handling.h"
+#include "ua_client.h"
 
 struct UA_ServerConfig;
 typedef struct UA_ServerConfig UA_ServerConfig;
@@ -540,6 +541,13 @@ UA_Server_setServerOnNetworkCallback(UA_Server *server,
 
 #endif /* UA_ENABLE_DISCOVERY_MULTICAST */
 
+/* Get the client configuration from the configuration plugin. Used by the
+ * server when it needs client functionality to register to a discovery server.
+ *
+ * @return The client configuration structure */
+UA_ClientConfig UA_EXPORT
+UA_Server_getClientConfig(void);
+
 #endif /* UA_ENABLE_DISCOVERY */
 
 /**

+ 6 - 1
plugins/ua_config_default.c

@@ -1,5 +1,5 @@
 /* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
- * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. 
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
  *
  *    Copyright 2017 (c) Julius Pfrommer, Fraunhofer IOSB
  *    Copyright 2017 (c) Julian Grothoff
@@ -652,3 +652,8 @@ const UA_ClientConfig UA_ClientConfig_default = {
 
     10 /* .outStandingPublishRequests */
 };
+
+UA_ClientConfig UA_Server_getClientConfig(void)
+{
+    return UA_ClientConfig_default;
+}

+ 2 - 2
src/server/ua_server_discovery.c

@@ -8,7 +8,6 @@
 
 #include "ua_server_internal.h"
 #include "ua_client.h"
-#include "ua_config_default.h"
 
 #ifdef UA_ENABLE_DISCOVERY
 
@@ -24,7 +23,8 @@ register_server_with_discovery_server(UA_Server *server,
     }
 
     /* Create the client */
-    UA_Client *client = UA_Client_new(UA_ClientConfig_default);
+    UA_ClientConfig clientConfig = UA_Server_getClientConfig();
+    UA_Client *client = UA_Client_new(clientConfig);
     if(!client)
         return UA_STATUSCODE_BADOUTOFMEMORY;