浏览代码

restore DEBUG flag for Debug-builds and fix all compiler warnings

Julius Pfrommer 10 年之前
父节点
当前提交
d22a8a3853

+ 2 - 5
CMakeLists.txt

@@ -4,6 +4,7 @@ cmake_minimum_required(VERSION 2.6)
 project(open62541 C)
 set(open62541_VERSION_MAJOR 0)
 set(open62541_VERSION_MINOR 1)
+set(CMAKE_C_FLAGS_DEBUG "-DDEBUG")
 
 set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
 
@@ -22,7 +23,6 @@ set(lib_sources src/ua_types.c
                 src/ua_securechannel.c
                 src/ua_session.c
                 src/ua_util.c
-                #src/util/ua_base64.c
                 src/server/ua_server.c
                 src/server/ua_securechannel_manager.c
                 src/server/ua_session_manager.c
@@ -33,7 +33,6 @@ set(lib_sources src/ua_types.c
                 src/server/ua_services_securechannel.c
                 src/server/ua_services_nodemanagement.c
                 src/server/ua_services_view.c
-                #src/server/ua_services_subscription.c
                 src/server/ua_services_monitoreditems.c
                 ${headers}
                 ${generated_headers})
@@ -68,7 +67,6 @@ if(ENABLE_SELFSIGNED)
                            ${CMAKE_CURRENT_SOURCE_DIR}/tools/certs/localhost.cnf)
 endif()
 
-
 ## auto-generate all types or only the relevant subset?
 option(TYPES_ONLY_NEEDED "Include only compile-needed types" OFF)
 if(TYPES_ONLY_NEEDED)
@@ -113,7 +111,7 @@ else()
     list(APPEND lib_sources src/server/ua_nodestore.c)
 endif()
 
-add_library(open62541 ${lib_sources}) # we can add more files to lib_sources later on
+add_library(open62541 SHARED ${lib_sources}) # we can add more files to lib_sources later on
 
 ## logging
 set(UA_LOGLEVEL 400 CACHE STRING "Level at which logs shall be reported")
@@ -220,4 +218,3 @@ endif(WIN32)
 #if(MULTITHREADING)
 #    target_link_libraries(api-design urcu-cds urcu)
 #endif(MULTITHREADING)
-

+ 3 - 3
include/ua_connection.h

@@ -45,7 +45,7 @@ typedef struct UA_ConnectionConfig {
     UA_UInt32 maxChunkCount;
 } UA_ConnectionConfig;
 
-extern UA_LIBEXPORT UA_ConnectionConfig UA_ConnectionConfig_standard;
+extern UA_EXPORT UA_ConnectionConfig UA_ConnectionConfig_standard;
 
 /* Forward declaration */
 struct UA_SecureChannel;
@@ -64,9 +64,9 @@ typedef struct UA_Connection {
     UA_Connection_closeCallback close;
 } UA_Connection;
 
-UA_Int32 UA_LIBEXPORT UA_Connection_init(UA_Connection *connection, UA_ConnectionConfig localConf, void *callbackHandle,
+UA_Int32 UA_EXPORT UA_Connection_init(UA_Connection *connection, UA_ConnectionConfig localConf, void *callbackHandle,
                                          UA_Connection_closeCallback close, UA_Connection_writeCallback write);
-UA_Int32 UA_LIBEXPORT UA_Connection_deleteMembers(UA_Connection *connection);
+UA_Int32 UA_EXPORT UA_Connection_deleteMembers(UA_Connection *connection);
 
 // todo: closing a binaryconnection that was closed on the network level
 

+ 10 - 10
include/ua_server.h

@@ -53,18 +53,18 @@ typedef struct UA_Server {
     UA_NodeId hasComponentReferenceTypeId;
 } 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);
+void UA_EXPORT UA_Server_init(UA_Server *server, UA_String *endpointUrl);
+UA_Int32 UA_EXPORT UA_Server_deleteMembers(UA_Server *server);
+UA_Int32 UA_EXPORT UA_Server_processBinaryMessage(UA_Server *server, UA_Connection *connection, const UA_ByteString *msg);
 
 /* Services for local use */
-UA_AddNodesResult UA_Server_addScalarVariableNode(UA_Server *server, UA_String *browseName, void *value,
-                                                  const UA_VTable_Entry *vt, UA_ExpandedNodeId *parentNodeId,
-                                                  UA_NodeId *referenceTypeId );
-UA_AddNodesResult UA_Server_addNode(UA_Server *server, UA_Node **node, UA_ExpandedNodeId *parentNodeId,
-                                    UA_NodeId *referenceTypeId);
-void UA_Server_addReferences(UA_Server *server, const UA_AddReferencesRequest *request,
-                             UA_AddReferencesResponse *response);
+UA_AddNodesResult UA_EXPORT UA_Server_addScalarVariableNode(UA_Server *server, UA_String *browseName, void *value,
+                                                            const UA_VTable_Entry *vt, UA_ExpandedNodeId *parentNodeId,
+                                                            UA_NodeId *referenceTypeId );
+UA_AddNodesResult UA_EXPORT UA_Server_addNode(UA_Server *server, UA_Node **node, UA_ExpandedNodeId *parentNodeId,
+                                              UA_NodeId *referenceTypeId);
+void UA_EXPORT UA_Server_addReferences(UA_Server *server, const UA_AddReferencesRequest *request,
+                                       UA_AddReferencesResponse *response);
 
 #ifdef __cplusplus
 } // extern "C"

+ 44 - 40
include/ua_types.h

@@ -23,6 +23,10 @@ extern "C" {
 #include <stdint.h>
 #include "ua_config.h"
 
+#ifdef DEBUG
+#include <stdio.h>
+#endif
+
 /**
  * @defgroup types Datatypes
  *
@@ -305,19 +309,19 @@ typedef void UA_InvalidType;
 
 #ifdef DEBUG
 #define UA_TYPE_PROTOTYPES(TYPE)                                   \
-    UA_Int32 UA_LIBEXPORT TYPE##_new(TYPE **p);                    \
-    void UA_LIBEXPORT     TYPE##_init(TYPE * p);                   \
-    void UA_LIBEXPORT     TYPE##_delete(TYPE * p);                 \
-    void UA_LIBEXPORT     TYPE##_deleteMembers(TYPE * p);          \
-    UA_Int32 UA_LIBEXPORT TYPE##_copy(const TYPE *src, TYPE *dst); \
-    void UA_LIBEXPORT     TYPE##_print(const TYPE *p, FILE *stream);
+    UA_Int32 UA_EXPORT TYPE##_new(TYPE **p);                    \
+    void UA_EXPORT     TYPE##_init(TYPE * p);                   \
+    void UA_EXPORT     TYPE##_delete(TYPE * p);                 \
+    void UA_EXPORT     TYPE##_deleteMembers(TYPE * p);          \
+    UA_Int32 UA_EXPORT TYPE##_copy(const TYPE *src, TYPE *dst); \
+    void UA_EXPORT     TYPE##_print(const TYPE *p, FILE *stream);
 #else
 #define UA_TYPE_PROTOTYPES(TYPE)                          \
-    UA_Int32 UA_LIBEXPORT TYPE##_new(TYPE **p);           \
-    void UA_LIBEXPORT     TYPE##_init(TYPE * p);          \
-    void UA_LIBEXPORT     TYPE##_delete(TYPE * p);        \
-    void UA_LIBEXPORT     TYPE##_deleteMembers(TYPE * p); \
-    UA_Int32 UA_LIBEXPORT TYPE##_copy(const TYPE *src, TYPE *dst);
+    UA_Int32 UA_EXPORT TYPE##_new(TYPE **p);           \
+    void UA_EXPORT     TYPE##_init(TYPE * p);          \
+    void UA_EXPORT     TYPE##_delete(TYPE * p);        \
+    void UA_EXPORT     TYPE##_deleteMembers(TYPE * p); \
+    UA_Int32 UA_EXPORT TYPE##_copy(const TYPE *src, TYPE *dst);
 #endif
 
 /* Functions for all types */
@@ -354,17 +358,17 @@ UA_TYPE_PROTOTYPES(UA_InvalidType)
         VARIABLE.length = sizeof(STRING)-1;     \
         VARIABLE.data   = (UA_Byte *)STRING; } while(0)
 
-UA_Int32 UA_LIBEXPORT UA_String_copycstring(char const *src, UA_String *dst);
-UA_Int32 UA_LIBEXPORT UA_String_copyprintf(char const *fmt, UA_String *dst, ...);
-UA_EQUALITY UA_LIBEXPORT UA_String_equal(const UA_String *string1, const UA_String *string2);
+UA_Int32 UA_EXPORT UA_String_copycstring(char const *src, UA_String *dst);
+UA_Int32 UA_EXPORT UA_String_copyprintf(char const *fmt, UA_String *dst, ...);
+UA_EQUALITY UA_EXPORT UA_String_equal(const UA_String *string1, const UA_String *string2);
 #ifdef DEBUG
-void UA_LIBEXPORT UA_String_printf(char const *label, const UA_String *string);
-void UA_LIBEXPORT UA_String_printx(char const *label, const UA_String *string);
-void UA_LIBEXPORT UA_String_printx_hex(char const *label, const UA_String *string);
+void UA_EXPORT UA_String_printf(char const *label, const UA_String *string);
+void UA_EXPORT UA_String_printx(char const *label, const UA_String *string);
+void UA_EXPORT UA_String_printx_hex(char const *label, const UA_String *string);
 #endif
 
 /* DateTime */
-UA_DateTime UA_LIBEXPORT UA_DateTime_now();
+UA_DateTime UA_EXPORT UA_DateTime_now();
 typedef struct UA_DateTimeStruct {
     UA_Int16 nanoSec;
     UA_Int16 microSec;
@@ -376,32 +380,32 @@ typedef struct UA_DateTimeStruct {
     UA_Int16 mounth;
     UA_Int16 year;
 } UA_DateTimeStruct;
-UA_DateTimeStruct UA_LIBEXPORT UA_DateTime_toStruct(UA_DateTime time);
-UA_Int32 UA_LIBEXPORT UA_DateTime_toString(UA_DateTime time, UA_String *timeString);
+UA_DateTimeStruct UA_EXPORT UA_DateTime_toStruct(UA_DateTime time);
+UA_Int32 UA_EXPORT UA_DateTime_toString(UA_DateTime time, UA_String *timeString);
 
 /* Guid */
-UA_EQUALITY UA_LIBEXPORT UA_Guid_equal(const UA_Guid *g1, const UA_Guid *g2);
+UA_EQUALITY UA_EXPORT UA_Guid_equal(const UA_Guid *g1, const UA_Guid *g2);
 
 /* ByteString */
-UA_EQUALITY UA_LIBEXPORT UA_ByteString_equal(const UA_ByteString *string1, const UA_ByteString *string2);
-UA_Int32 UA_LIBEXPORT UA_ByteString_newMembers(UA_ByteString *p, UA_Int32 length);
+UA_EQUALITY UA_EXPORT UA_ByteString_equal(const UA_ByteString *string1, const UA_ByteString *string2);
+UA_Int32 UA_EXPORT UA_ByteString_newMembers(UA_ByteString *p, UA_Int32 length);
 #ifdef DEBUG
-void UA_LIBEXPORT UA_ByteString_printf(char *label, const UA_ByteString *string);
-void UA_LIBEXPORT UA_ByteString_printx(char *label, const UA_ByteString *string);
-void UA_LIBEXPORT UA_ByteString_printx_hex(char *label, const UA_ByteString *string);
+void UA_EXPORT UA_ByteString_printf(char *label, const UA_ByteString *string);
+void UA_EXPORT UA_ByteString_printx(char *label, const UA_ByteString *string);
+void UA_EXPORT UA_ByteString_printx_hex(char *label, const UA_ByteString *string);
 #endif
 
 /* NodeId */
-UA_EQUALITY UA_LIBEXPORT UA_NodeId_equal(const UA_NodeId *n1, const UA_NodeId *n2);
-UA_Boolean UA_LIBEXPORT UA_NodeId_isNull(const UA_NodeId *p);
-UA_Boolean UA_LIBEXPORT UA_NodeId_isBasicType(UA_NodeId const *id);
+UA_EQUALITY UA_EXPORT UA_NodeId_equal(const UA_NodeId *n1, const UA_NodeId *n2);
+UA_Boolean UA_EXPORT UA_NodeId_isNull(const UA_NodeId *p);
+UA_Boolean UA_EXPORT UA_NodeId_isBasicType(UA_NodeId const *id);
 
 #define NS0NODEID(NUMERIC_ID)                                                                        \
     (UA_NodeId) {.namespaceIndex = 0, .identifierType = UA_NODEIDTYPE_NUMERIC, .identifier.numeric = \
                      NUMERIC_ID }
 
 /* ExpandedNodeId */
-UA_Boolean UA_LIBEXPORT UA_ExpandedNodeId_isNull(const UA_ExpandedNodeId *p);
+UA_Boolean UA_EXPORT UA_ExpandedNodeId_isNull(const UA_ExpandedNodeId *p);
 
 #define NS0EXPANDEDNODEID(VARIABLE, NUMERIC_ID) do {   \
         VARIABLE.nodeId       = NS0NODEID(NUMERIC_ID); \
@@ -412,9 +416,9 @@ UA_Boolean UA_LIBEXPORT UA_ExpandedNodeId_isNull(const UA_ExpandedNodeId *p);
 #define UA_QUALIFIEDNAME_STATIC(VARIABLE, STRING) do { \
         VARIABLE.namespaceIndex = 0;                   \
         UA_STRING_STATIC(VARIABLE.name, STRING); } while(0)
-UA_Int32 UA_LIBEXPORT UA_QualifiedName_copycstring(char const *src, UA_QualifiedName *dst);
+UA_Int32 UA_EXPORT UA_QualifiedName_copycstring(char const *src, UA_QualifiedName *dst);
 #ifdef DEBUG
-void UA_LIBEXPORT UA_QualifiedName_printf(char const *label, const UA_QualifiedName *qn);
+void UA_EXPORT UA_QualifiedName_printf(char const *label, const UA_QualifiedName *qn);
 #endif
 
 /* LocalizedText */
@@ -422,21 +426,21 @@ void UA_LIBEXPORT UA_QualifiedName_printf(char const *label, const UA_QualifiedN
         UA_STRING_STATIC(VARIABLE.locale, "en");       \
         UA_STRING_STATIC(VARIABLE.text, STRING); } while(0)
 
-UA_Int32 UA_LIBEXPORT UA_LocalizedText_copycstring(char const *src, UA_LocalizedText *dst);
+UA_Int32 UA_EXPORT UA_LocalizedText_copycstring(char const *src, UA_LocalizedText *dst);
 
 /* Variant */
-UA_Int32 UA_LIBEXPORT UA_Variant_copySetValue(UA_Variant *v, const UA_VTable_Entry *vt, const void *value);
-UA_Int32 UA_LIBEXPORT UA_Variant_copySetArray(UA_Variant *v, const UA_VTable_Entry *vt, UA_Int32 arrayLength, const void *array);
+UA_Int32 UA_EXPORT UA_Variant_copySetValue(UA_Variant *v, const UA_VTable_Entry *vt, const void *value);
+UA_Int32 UA_EXPORT UA_Variant_copySetArray(UA_Variant *v, const UA_VTable_Entry *vt, UA_Int32 arrayLength, const void *array);
 
 /* Array operations */
-UA_Int32 UA_LIBEXPORT UA_Array_new(void **p, UA_Int32 noElements, const UA_VTable_Entry *vt);
-void UA_LIBEXPORT UA_Array_init(void *p, UA_Int32 noElements, const UA_VTable_Entry *vt);
-void UA_LIBEXPORT UA_Array_delete(void *p, UA_Int32 noElements, const UA_VTable_Entry *vt);
+UA_Int32 UA_EXPORT UA_Array_new(void **p, UA_Int32 noElements, const UA_VTable_Entry *vt);
+void UA_EXPORT UA_Array_init(void *p, UA_Int32 noElements, const UA_VTable_Entry *vt);
+void UA_EXPORT UA_Array_delete(void *p, UA_Int32 noElements, const UA_VTable_Entry *vt);
 
 /* @brief The destination array is allocated according to noElements. */
-UA_Int32 UA_LIBEXPORT UA_Array_copy(const void *src, UA_Int32 noElements, const UA_VTable_Entry *vt, void **dst);
+UA_Int32 UA_EXPORT UA_Array_copy(const void *src, UA_Int32 noElements, const UA_VTable_Entry *vt, void **dst);
 #ifdef DEBUG
-void UA_LIBEXPORT UA_Array_print(const void *p, UA_Int32 noElements, const UA_VTable_Entry *vt, FILE *stream);
+void UA_EXPORT UA_Array_print(const void *p, UA_Int32 noElements, const UA_VTable_Entry *vt, FILE *stream);
 #endif
 
 /**********/

+ 1 - 1
src/server/ua_services_nodemanagement.c

@@ -166,7 +166,7 @@ static void addNodeFromAttributes(UA_Server *server, UA_Session *session, UA_Add
     }
 
     UA_Node *newNode;
-    const UA_VTable_Entry *newNodeVT;
+    const UA_VTable_Entry *newNodeVT = UA_NULL;
     if(item->nodeClass == UA_NODECLASS_VARIABLE)
         result->statusCode = parseVariableNode(&item->nodeAttributes, &newNode, &newNodeVT);
     else // add more node types here..

+ 2 - 2
src/server/ua_services_view.c

@@ -66,8 +66,8 @@ struct SubRefTypeId {
 };
 SLIST_HEAD(SubRefTypeIdList, SubRefTypeId);
 
-UA_UInt32 walkReferenceTree(UA_NodeStore *ns, const UA_ReferenceTypeNode *current,
-                            struct SubRefTypeIdList *list) {
+static UA_UInt32 walkReferenceTree(UA_NodeStore *ns, const UA_ReferenceTypeNode *current,
+                                   struct SubRefTypeIdList *list) {
     // insert the current referencetype
     struct SubRefTypeId *element;
     UA_alloc((void **)&element, sizeof(struct SubRefTypeId));

+ 6 - 12
src/ua_config.h.in

@@ -6,12 +6,6 @@
 #cmakedefine MSVC
 #cmakedefine WIN32
 
-#ifndef MSVC
-#define INLINE inline
-#else
-#define INLINE __inline
-#endif
-
 /* Visibility */
 #ifdef MSVC
 #define INLINE __inline
@@ -22,21 +16,21 @@
 #if defined(_WIN32) || defined(__CYGWIN__)
   #ifdef open62541_EXPORTS
     #ifdef __GNUC__
-      #define UA_LIBEXPORT __attribute__ ((dllexport))
+      #define UA_EXPORT __attribute__ ((dllexport))
     #else
-      #define UA_LIBEXPORT __declspec(dllexport)
+      #define UA_EXPORT __declspec(dllexport)
     #endif
   #else
     #ifdef __GNUC__
-      #define UA_LIBEXPORT __attribute__ ((dllimport))
+      #define UA_EXPORT __attribute__ ((dllimport))
     #else
-      #define UA_LIBEXPORT __declspec(dllimport)
+      #define UA_EXPORT __declspec(dllimport)
     #endif
   #endif
 #else
   #if __GNUC__ >= 4 || __clang__
-    #define UA_LIBEXPORT __attribute__ ((visibility ("default")))
+    #define UA_EXPORT __attribute__ ((visibility ("default")))
   #else
-    #define UA_LIBEXPORT
+    #define UA_EXPORT
   #endif
 #endif

+ 2 - 2
src/ua_transport.c

@@ -36,8 +36,8 @@ UA_Int32 UA_MessageType_decodeBinary(UA_ByteString const *src, UA_UInt32 *offset
 }
 
 #ifdef DEBUG
-void UA_MessageType_printf(char *label, UA_MessageType *p) {
+void UA_MessageType_print(const UA_MessageType *p, FILE *stream) {
     UA_Byte *b = (UA_Byte *)p;
-    printf("%s{%c%c%c}\n", label, b[2], b[1], b[0]);
+    fprintf(stream, "%c%c%c", b[2], b[1], b[0]);
 }
 #endif

+ 0 - 3
src/ua_transport.h

@@ -27,9 +27,6 @@ enum UA_MessageType {
 };
 UA_TYPE_PROTOTYPES(UA_MessageType)
 UA_TYPE_BINARY_ENCODING(UA_MessageType)
-#ifdef DEBUG
-void UA_MessageType_printf(char *label, UA_MessageType *p);
-#endif
 
 /* All other transport types are auto-generated from a schema definition. */
 

+ 11 - 6
src/ua_types.c

@@ -8,7 +8,7 @@
 #endif
 
 #ifdef DEBUG
-#include <stdio.h>
+#include <inttypes.h>
 #endif
 
 #include "ua_util.h"
@@ -494,7 +494,7 @@ void UA_NodeId_print(const UA_NodeId *p, FILE *stream) {
         break;
     }
     fprintf(stream, ",%u,", p->namespaceIndex);
-    switch(p->identifierType & UA_NODEIDTYPE_MASK) {
+    switch(p->identifierType) {
     case UA_NODEIDTYPE_NUMERIC:
         fprintf(stream, ".identifier.numeric=%u", p->identifier.numeric);
         break;
@@ -909,18 +909,23 @@ UA_Int32 UA_Variant_copySetArray(UA_Variant *v, const UA_VTable_Entry *vt, UA_In
 void UA_Variant_print(const UA_Variant *p, FILE *stream) {
     if(p == UA_NULL || stream == UA_NULL) return;
     UA_UInt32 ns0id = UA_ns0ToVTableIndex(&p->vt->typeId);
+    if(p->storageType == UA_VARIANT_DATASOURCE) {
+        fprintf(stream, "Variant from a Datasource");
+        return;
+    }
     fprintf(stream, "(UA_Variant){/*%s*/", p->vt->name);
     if(p->vt == &UA_[ns0id])
         fprintf(stream, "UA_[%d]", ns0id);
     else
         fprintf(stream, "ERROR (not a builtin type)");
-    UA_Int32_print(&p->arrayLength, stream);
+    UA_Int32_print(&p->storage.data.arrayLength, stream);
     fprintf(stream, ",");
-    UA_Array_print(p->data, p->arrayLength, p->vt, stream);
+    UA_Array_print(p->storage.data.dataPtr, p->storage.data.arrayLength, p->vt, stream);
     fprintf(stream, ",");
-    UA_Int32_print(&p->arrayDimensionsLength, stream);
+    UA_Int32_print(&p->storage.data.arrayDimensionsLength, stream);
     fprintf(stream, ",");
-    UA_Array_print(p->arrayDimensions, p->arrayDimensionsLength, &UA_[UA_INT32], stream);
+    UA_Array_print(p->storage.data.arrayDimensions, p->storage.data.arrayDimensionsLength,
+                   &UA_[UA_INT32], stream);
     fprintf(stream, "}");
 }
 #endif

+ 4 - 0
src/ua_util.h

@@ -39,7 +39,11 @@
 # endif
 #endif
 
+#ifdef DEBUG
 #define UA_assert(ignore) assert(ignore)
+#else
+#define UA_assert(ignore)
+#endif
 
 /* Heap memory functions */
 INLINE UA_Int32 _UA_free(void *ptr, char *pname, char *f, UA_Int32 l) {

+ 1 - 1
tools/generate_namespace.py

@@ -104,7 +104,7 @@ printh('''/**********************************************************
  */
 
 UA_Int32 UA_ns0ToVTableIndex(const UA_NodeId *id);\n
-extern const UA_VTable_Entry *UA_;
+extern const UA_VTable_Entry UA_EXPORT *UA_;
 
 /**
  * @brief the set of possible indices into UA_VTable