ソースを参照

Server: Allow server_new with an existing config

Julius Pfrommer 4 年 前
コミット
b04af1d6f7
共有2 個のファイルを変更した27 個の追加7 個の削除を含む
  1. 5 0
      include/open62541/server.h
  2. 22 7
      src/server/ua_server.c

+ 5 - 0
include/open62541/server.h

@@ -44,6 +44,11 @@ struct UA_Client;
 
 UA_Server UA_EXPORT * UA_Server_new(void);
 
+/* Makes a (shallow) copy of the config into the server object.
+ * The config content is cleared together with the server. */
+UA_Server UA_EXPORT *
+UA_Server_newWithConfig(const UA_ServerConfig *config);
+
 void UA_EXPORT UA_Server_delete(UA_Server *server);
 
 UA_ServerConfig UA_EXPORT *

+ 22 - 7
src/server/ua_server.c

@@ -209,13 +209,8 @@ UA_Server_cleanup(UA_Server *server, void *_) {
 /* Server Lifecycle */
 /********************/
 
-UA_Server *
-UA_Server_new() {
-    /* Allocate the server */
-    UA_Server *server = (UA_Server *)UA_calloc(1, sizeof(UA_Server));
-    if(!server)
-        return NULL;
-
+static UA_Server *
+UA_Server_init(UA_Server *server) {
     /* Init start time to zero, the actual start time will be sampled in
      * UA_Server_run_startup() */
     server->startTime = 0;
@@ -276,6 +271,26 @@ UA_Server_new() {
     return NULL;
 }
 
+UA_Server *
+UA_Server_new() {
+    /* Allocate the server */
+    UA_Server *server = (UA_Server *)UA_calloc(1, sizeof(UA_Server));
+    if(!server)
+        return NULL;
+    return UA_Server_init(server);
+}
+
+
+UA_Server *
+UA_Server_newWithConfig(const UA_ServerConfig *config) {
+    UA_Server *server = (UA_Server *)UA_calloc(1, sizeof(UA_Server));
+    if(!server)
+        return NULL;
+    if(config)
+        server->config = *config;
+    return UA_Server_init(server);
+}
+
 /*******************/
 /* Timed Callbacks */
 /*******************/