Sfoglia il codice sorgente

refactor(server): Move UA_Server_new to plugins

That way, plugins for logging can be populated early.
Julius Pfrommer 5 anni fa
parent
commit
a237c8b353

+ 7 - 2
include/open62541/server.h

@@ -42,9 +42,14 @@ struct UA_Client;
  * Server Lifecycle
  * ---------------- */
 
-UA_Server UA_EXPORT * UA_Server_new(void);
+/* The method UA_Server_new is defined in server_config_default.h. So default
+ * plugins outside of the core library (for logging, etc) are already available
+ * during the initialization.
+ *
+ * UA_Server UA_EXPORT * UA_Server_new(void);
+ */
 
-/* Makes a (shallow) copy of the config into the server object.
+/* Creates a new server. Moves the config into the server with a shallow copy.
  * The config content is cleared together with the server. */
 UA_Server UA_EXPORT *
 UA_Server_newWithConfig(const UA_ServerConfig *config);

+ 4 - 0
plugins/include/open62541/server_config_default.h

@@ -14,6 +14,10 @@
 
 _UA_BEGIN_DECLS
 
+/* Create a new server with default plugins for logging etc. used during
+ * initialization. No network layer and SecurityPolicies are set so far. */
+UA_Server UA_EXPORT * UA_Server_new(void);
+
 /**********************/
 /* Default Connection */
 /**********************/

+ 8 - 0
plugins/ua_config_default.c

@@ -37,6 +37,14 @@ UA_DURATIONRANGE(UA_Duration min, UA_Duration max) {
     return range;
 }
 
+UA_Server *
+UA_Server_new() {
+    UA_ServerConfig config;
+    memset(&config, 0, sizeof(UA_ServerConfig));
+    config.logger = UA_Log_Stdout_;
+    return UA_Server_newWithConfig(&config);
+}
+
 /*******************************/
 /* Default Connection Settings */
 /*******************************/

+ 3 - 12
src/server/ua_server.c

@@ -321,23 +321,14 @@ UA_Server_init(UA_Server *server) {
     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) {
+    if(!config)
+        return NULL;
     UA_Server *server = (UA_Server *)UA_calloc(1, sizeof(UA_Server));
     if(!server)
         return NULL;
-    if(config)
-        server->config = *config;
+    server->config = *config;
     return UA_Server_init(server);
 }