Преглед изворни кода

move user-facing api to includes folder

Julius Pfrommer пре 9 година
родитељ
комит
a5ff55e370

+ 1 - 0
CMakeLists.txt

@@ -8,6 +8,7 @@ set(open62541_VERSION_MINOR 1)
 set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
 
 # main sources of libopen62541
+include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
 include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src")
 file(GLOB_RECURSE headers "${CMAKE_CURRENT_SOURCE_DIR}/src/*.h")
 file(GLOB generated_headers "${PROJECT_BINARY_DIR}/src_generated/*.h")

+ 1 - 1
examples/logger_stdout.h

@@ -6,7 +6,7 @@
 #ifndef LOGGER_STDOUT_H_
 #define LOGGER_STDOUT_H_
 
-#include "util/ua_log.h"
+#include "ua_log.h"
 
 /** Initialises the logger for the current thread. */
 void Logger_Stdout_init(UA_Logger *logger);

+ 1 - 0
examples/networklayer_tcp.c

@@ -21,6 +21,7 @@
 #endif /* WIN32 */
 
 #include <stdlib.h> // exit
+#include <stdio.h>
 #include <errno.h> // errno, EINTR
 #include <memory.h> // memset
 #include <fcntl.h> // fcntl

+ 1 - 1
examples/networklayer_tcp.h

@@ -6,7 +6,7 @@
 #ifndef NETWORKLAYERTCP_H_
 #define NETWORKLAYERTCP_H_
 
-#include "server/ua_server.h"
+#include "ua_server.h"
 
 struct NetworklayerTCP;
 typedef struct NetworklayerTCP NetworklayerTCP;

+ 1 - 1
examples/opcuaServer.c

@@ -18,7 +18,7 @@
 #include <signal.h>
 #include <errno.h> // errno, EINTR
 
-#include "server/ua_server.h"
+#include "ua_server.h"
 #include "logger_stdout.h"
 #include "networklayer_tcp.h"
 

+ 27 - 5
src/ua_connection.h

@@ -1,18 +1,36 @@
+/*
+ * Copyright (C) 2014 the contributors as stated in the AUTHORS file
+ *
+ * This file is part of open62541. open62541 is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU Lesser General
+ * Public License, version 3 (as published by the Free Software Foundation) with
+ * a static linking exception as stated in the LICENSE file provided with
+ * open62541.
+ *
+ * open62541 is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ */
+
 #ifndef UA_CONNECTION_H_
 #define UA_CONNECTION_H_
 
-#include "ua_transport.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "ua_types.h"
+
+/** @defgroup connection Connection */
 
-/* used for zero-copy communication. the array of bytestrings is sent over the
+/** Used for zero-copy communication. The array of bytestrings is sent over the
    network as a single buffer. */
 typedef struct UA_ByteStringArray {
     UA_UInt32      stringsSize;
     UA_ByteString *strings;
 } UA_ByteStringArray;
 
-UA_Int32 UA_ByteStringArray_init(UA_ByteStringArray *stringarray, UA_UInt32 length);
-UA_Int32 UA_ByteStringArray_deleteMembers(UA_ByteStringArray *stringarray);
-
 typedef enum UA_ConnectionState {
     UA_CONNECTION_OPENING,
     UA_CONNECTION_CLOSING,
@@ -52,4 +70,8 @@ UA_Int32 UA_LIBEXPORT UA_Connection_deleteMembers(UA_Connection *connection);
 
 // todo: closing a binaryconnection that was closed on the network level
 
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
 #endif /* UA_CONNECTION_H_ */

+ 29 - 4
src/util/ua_log.h

@@ -1,11 +1,32 @@
+/*
+ * Copyright (C) 2014 the contributors as stated in the AUTHORS file
+ *
+ * This file is part of open62541. open62541 is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU Lesser General
+ * Public License, version 3 (as published by the Free Software Foundation) with
+ * a static linking exception as stated in the LICENSE file provided with
+ * open62541.
+ *
+ * open62541 is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ */
+
 #ifndef UA_LOG_H_
 #define UA_LOG_H_
 
-/**
-   @defgroup logging Logging
+#ifdef __cplusplus
+extern "C" {
+#endif
 
-   @brief Logging functionality is externally provided to the open62541 libary.
-   The server contains a logger-struct with function callbacks
+#include "ua_config.h"
+
+/**
+ * @defgroup logging Logging
+ *
+ * @brief Logging functionality is externally provided to the open62541 libary.
+ * The server contains a logger-struct with function callbacks
  */
 
 typedef enum UA_LoggerCategory {
@@ -60,4 +81,8 @@ typedef struct UA_Logger {
 #define UA_LOG_FATAL(CATEGORY, MSG, ...) do {} while(0)
 #endif
 
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
 #endif /* UA_LOG_H_ */

+ 26 - 6
src/server/ua_server.h

@@ -1,14 +1,31 @@
+/*
+ * Copyright (C) 2014 the contributors as stated in the AUTHORS file
+ *
+ * This file is part of open62541. open62541 is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU Lesser General
+ * Public License, version 3 (as published by the Free Software Foundation) with
+ * a static linking exception as stated in the LICENSE file provided with
+ * open62541.
+ *
+ * open62541 is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ */
+
 #ifndef UA_SERVER_H_
 #define UA_SERVER_H_
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include "ua_types.h"
 #include "ua_types_generated.h"
 #include "ua_connection.h"
-#include "util/ua_log.h"
+#include "ua_log.h"
 
-/**
-   @defgroup server Server
- */
+/** @defgroup server Server */
 
 struct UA_SecureChannelManager;
 typedef struct UA_SecureChannelManager UA_SecureChannelManager;
@@ -30,7 +47,10 @@ typedef struct UA_Server {
 
 void UA_LIBEXPORT UA_Server_init(UA_Server *server, UA_String *endpointUrl);
 UA_Int32 UA_LIBEXPORT UA_Server_deleteMembers(UA_Server *server);
-UA_Int32 UA_LIBEXPORT UA_Server_processBinaryMessage(UA_Server *server, UA_Connection *connection,
-                                                     const UA_ByteString *msg);
+UA_Int32 UA_LIBEXPORT UA_Server_processBinaryMessage(UA_Server *server, UA_Connection *connection, const UA_ByteString *msg);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
 
 #endif /* UA_SERVER_H_ */

+ 2 - 3
src/ua_types.h

@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 {contributors}
+ * Copyright (C) 2014 the contributors as stated in the AUTHORS file
  *
  * This file is part of open62541. open62541 is free software: you can
  * redistribute it and/or modify it under the terms of the GNU Lesser General
@@ -20,9 +20,8 @@
 extern "C" {
 #endif
 
-#include "ua_config.h"
-#include <stdio.h>
 #include <stdint.h>
+#include "ua_config.h"
 
 /**
  * @defgroup types Datatypes

+ 19 - 0
src/server/ua_server_binary.c

@@ -5,6 +5,25 @@
 #include "ua_securechannel_manager.h"
 #include "util/ua_util.h"
 
+static UA_Int32 UA_ByteStringArray_init(UA_ByteStringArray *stringarray, UA_UInt32 length) {
+    if(!stringarray || length == 0)
+        return UA_ERROR;
+    if(UA_alloc((void **)&stringarray->strings, sizeof(UA_String) * length) != UA_SUCCESS)
+        return UA_ERROR;
+    for(UA_UInt32 i = 0;i < length;i++)
+        UA_String_init(&stringarray->strings[i]);
+    stringarray->stringsSize = length;
+    return UA_ERROR;
+}
+
+static UA_Int32 UA_ByteStringArray_deleteMembers(UA_ByteStringArray *stringarray) {
+    if(!stringarray)
+        return UA_ERROR;
+    for(UA_UInt32 i = 0;i < stringarray->stringsSize;i++)
+        UA_String_deleteMembers(&stringarray->strings[i]);
+    return UA_SUCCESS;
+}
+
 static void processHello(UA_Connection *connection, const UA_ByteString *msg,
                          UA_UInt32 *pos) {
     UA_TcpHelloMessage helloMessage;

+ 0 - 19
src/ua_connection.c

@@ -5,25 +5,6 @@ UA_ConnectionConfig UA_ConnectionConfig_standard = { .protocolVersion = 0,    .s
                                                      .recvBufferSize  = 8192, .maxMessageSize = 8192,
                                                      .maxChunkCount   = 1 };
 
-UA_Int32 UA_ByteStringArray_init(UA_ByteStringArray *stringarray, UA_UInt32 length) {
-    if(!stringarray || length == 0)
-        return UA_ERROR;
-    if(UA_alloc((void **)&stringarray->strings, sizeof(UA_String) * length) != UA_SUCCESS)
-        return UA_ERROR;
-    for(UA_UInt32 i = 0;i < length;i++)
-        UA_String_init(&stringarray->strings[i]);
-    stringarray->stringsSize = length;
-    return UA_ERROR;
-}
-
-UA_Int32 UA_ByteStringArray_deleteMembers(UA_ByteStringArray *stringarray) {
-    if(!stringarray)
-        return UA_ERROR;
-    for(UA_UInt32 i = 0;i < stringarray->stringsSize;i++)
-        UA_String_deleteMembers(&stringarray->strings[i]);
-    return UA_SUCCESS;
-}
-
 UA_Int32 UA_Connection_init(UA_Connection *connection, UA_ConnectionConfig localConf, void *callbackHandle,
                             UA_Connection_closeCallback close, UA_Connection_writeCallback write) {
     connection->state          = UA_CONNECTION_OPENING;

+ 5 - 3
src/ua_types.c

@@ -1,14 +1,16 @@
-#include <stdlib.h> // alloc, free, vsnprintf
-#include <string.h>
 #include <stdarg.h> // va_start, va_end
-
 #include <time.h>
+
 #ifdef WIN32
 #include <windows.h>
 #else
 #include <sys/time.h>
 #endif
 
+#ifdef DEBUG
+#include <stdio.h>
+#endif
+
 #include "util/ua_util.h"
 #include "ua_types.h"
 #include "ua_types_encoding_binary.h"

+ 1 - 0
src/util/ua_util.h

@@ -5,6 +5,7 @@
 #include <stdlib.h> // malloc, free
 #include <string.h> // memcpy
 #include <assert.h> // assert
+
 #include "ua_config.h"
 #ifndef MSVC
 #ifndef WIN32