Browse Source

First files compiling as cxx

Julius Pfrommer 8 years ago
parent
commit
abc3716e07
6 changed files with 53 additions and 53 deletions
  1. 1 1
      deps/pcg_basic.h
  2. 11 7
      include/ua_types.h
  3. 12 12
      src/client/ua_client.c
  4. 1 1
      src/ua_connection.c
  5. 19 23
      src/ua_types.c
  6. 9 9
      src/ua_types_encoding_binary.c

+ 1 - 1
deps/pcg_basic.h

@@ -24,7 +24,7 @@
 #ifndef PCG_BASIC_H_INCLUDED
 #define PCG_BASIC_H_INCLUDED 1
 
-#include <stdint.h>
+#include "ms_stdint.h"
 
 #if __cplusplus
 extern "C" {

+ 11 - 7
include/ua_types.h

@@ -509,15 +509,17 @@ typedef struct UA_NumericRange UA_NumericRange;
 
 #define UA_EMPTY_ARRAY_SENTINEL ((void*)0x01)
 
-typedef struct {
-    const UA_DataType *type;      /* The data type description */
-    enum {
+typedef enum {
         UA_VARIANT_DATA,          /* The data has the same lifecycle as the
                                      variant */
         UA_VARIANT_DATA_NODELETE, /* The data is "borrowed" by the variant and
                                      shall not be deleted at the end of the
                                      variant's lifecycle. */
-    } storageType;
+} UA_VariantStorageType;
+
+typedef struct {
+    const UA_DataType *type;      /* The data type description */
+    UA_VariantStorageType storageType;
     size_t arrayLength;           /* The number of elements in the data array */
     void *data;                   /* Points to the scalar or array data */
     size_t arrayDimensionsSize;   /* The number of dimensions */
@@ -653,8 +655,7 @@ UA_Variant_setRangeCopy(UA_Variant *v, const void *array,
  * unknown to the receiver. See the section on :ref:`generic-types` on how types
  * are described. If the received data type is unkown, the encoded string and
  * target NodeId is stored instead of the decoded value. */
-typedef struct {
-    enum {
+typedef enum {
         UA_EXTENSIONOBJECT_ENCODED_NOBODY     = 0,
         UA_EXTENSIONOBJECT_ENCODED_BYTESTRING = 1,
         UA_EXTENSIONOBJECT_ENCODED_XML        = 2,
@@ -662,7 +663,10 @@ typedef struct {
         UA_EXTENSIONOBJECT_DECODED_NODELETE   = 4 /* Don't delete the content
                                                      together with the
                                                      ExtensionObject */
-    } encoding;
+} UA_ExtensionObjectEncoding;
+
+typedef struct {
+    UA_ExtensionObjectEncoding encoding;
     union {
         struct {
             UA_NodeId typeId;   /* The nodeid of the datatype */

+ 12 - 12
src/client/ua_client.c

@@ -38,9 +38,9 @@ static void UA_Client_init(UA_Client* client, UA_ClientConfig config) {
     memset(client, 0, sizeof(UA_Client));
 
     client->state = UA_CLIENTSTATE_READY;
-    client->connection = UA_malloc(sizeof(UA_Connection));
+    client->connection = (UA_Connection*)UA_malloc(sizeof(UA_Connection));
     memset(client->connection, 0, sizeof(UA_Connection));
-    client->channel = UA_malloc(sizeof(UA_SecureChannel));
+    client->channel = (UA_SecureChannel*)UA_malloc(sizeof(UA_SecureChannel));
     UA_SecureChannel_init(client->channel);
     client->channel->connection = client->connection;
     client->authenticationMethod = UA_CLIENTAUTHENTICATION_NONE;
@@ -52,7 +52,7 @@ static void UA_Client_init(UA_Client* client, UA_ClientConfig config) {
 }
 
 UA_Client * UA_Client_new(UA_ClientConfig config) {
-    UA_Client *client = UA_calloc(1, sizeof(UA_Client));
+    UA_Client *client = (UA_Client*)UA_calloc(1, sizeof(UA_Client));
     if(!client)
         return NULL;
 
@@ -367,14 +367,14 @@ static UA_StatusCode ActivateSession(UA_Client *client) {
 
     //manual ExtensionObject encoding of the identityToken
     if(client->authenticationMethod == UA_CLIENTAUTHENTICATION_NONE) {
-        UA_AnonymousIdentityToken* identityToken = UA_malloc(sizeof(UA_AnonymousIdentityToken));
+        UA_AnonymousIdentityToken* identityToken = UA_AnonymousIdentityToken_new();
         UA_AnonymousIdentityToken_init(identityToken);
         UA_String_copy(&client->token.policyId, &identityToken->policyId);
         request.userIdentityToken.encoding = UA_EXTENSIONOBJECT_DECODED;
         request.userIdentityToken.content.decoded.type = &UA_TYPES[UA_TYPES_ANONYMOUSIDENTITYTOKEN];
         request.userIdentityToken.content.decoded.data = identityToken;
     } else {
-        UA_UserNameIdentityToken* identityToken = UA_malloc(sizeof(UA_UserNameIdentityToken));
+        UA_UserNameIdentityToken* identityToken = UA_UserNameIdentityToken_new();
         UA_UserNameIdentityToken_init(identityToken);
         UA_String_copy(&client->token.policyId, &identityToken->policyId);
         UA_String_copy(&client->username, &identityToken->userName);
@@ -718,6 +718,11 @@ static void
 processServiceResponse(struct ResponseDescription *rd, UA_SecureChannel *channel,
                        UA_MessageType messageType, UA_UInt32 requestId,
                        UA_ByteString *message) {
+	const UA_NodeId expectedNodeId =
+        UA_NODEID_NUMERIC(0, rd->responseType->binaryEncodingId);
+    const UA_NodeId serviceFaultNodeId =
+        UA_NODEID_NUMERIC(0, UA_TYPES[UA_TYPES_SERVICEFAULT].binaryEncodingId);
+
     UA_StatusCode retval = UA_STATUSCODE_GOOD;
     UA_ResponseHeader *respHeader = (UA_ResponseHeader*)rd->response;
     rd->processed = true;
@@ -741,10 +746,6 @@ processServiceResponse(struct ResponseDescription *rd, UA_SecureChannel *channel
     }
 
     /* Check that the response type matches */
-    const UA_NodeId expectedNodeId =
-        UA_NODEID_NUMERIC(0, rd->responseType->binaryEncodingId);
-    const UA_NodeId serviceFaultNodeId =
-        UA_NODEID_NUMERIC(0, UA_TYPES[UA_TYPES_SERVICEFAULT].binaryEncodingId);
     size_t offset = 0;
     UA_NodeId responseId;
     retval = UA_NodeId_decodeBinary(message, &offset, &responseId);
@@ -799,7 +800,7 @@ __UA_Client_Service(UA_Client *client, const void *r, const UA_DataType *request
 
     /* Handling request parameters */
     //here const *r is 'violated'
-    UA_RequestHeader *request = (void*)(uintptr_t)r;
+    UA_RequestHeader *request = (UA_RequestHeader*)(uintptr_t)r;
     UA_NodeId_copy(&client->authenticationToken, &request->authenticationToken);
     request->timestamp = UA_DateTime_now();
     request->requestHandle = ++client->requestHandle;
@@ -821,8 +822,7 @@ __UA_Client_Service(UA_Client *client, const void *r, const UA_DataType *request
 
     /* Prepare the response and the structure we give into processServiceResponse */
     UA_init(response, responseType);
-    struct ResponseDescription rd = (struct ResponseDescription){
-        client, false, requestId, response, responseType};
+    struct ResponseDescription rd = {client, false, requestId, response, responseType};
 
     /* Retrieve the response */
     UA_DateTime maxDate = UA_DateTime_nowMonotonic() + (client->config.timeout * UA_MSEC_TO_DATETIME);

+ 1 - 1
src/ua_connection.c

@@ -18,7 +18,7 @@ UA_Connection_completeMessages(UA_Connection *connection, UA_ByteString * UA_RES
      * After this block, connection->incompleteMessage is always empty. */
     if(connection->incompleteMessage.length > 0) {
         size_t length = connection->incompleteMessage.length + message->length;
-        UA_Byte *data = UA_realloc(connection->incompleteMessage.data, length);
+        UA_Byte *data = (UA_Byte*)UA_realloc(connection->incompleteMessage.data, length);
         if(!data) {
             retval = UA_STATUSCODE_BADOUTOFMEMORY;
             goto cleanup;

+ 19 - 23
src/ua_types.c

@@ -13,16 +13,13 @@
  * UA_DataType structure. The UA_DataType structures as well as all non-builtin
  * datatypes are autogenerated. */
 
-/* Static definition of NULL type instances */
-const UA_String UA_STRING_NULL = {.length = 0, .data = NULL };
-const UA_ByteString UA_BYTESTRING_NULL = {.length = 0, .data = NULL };
-const UA_Guid UA_GUID_NULL = {.data1 = 0, .data2 = 0, .data3 = 0,
-                              .data4 = {0,0,0,0,0,0,0,0}};
-const UA_NodeId UA_NODEID_NULL = {0, UA_NODEIDTYPE_NUMERIC, {0}};
-const UA_ExpandedNodeId UA_EXPANDEDNODEID_NULL = {
-       .nodeId = {.namespaceIndex = 0, .identifierType = UA_NODEIDTYPE_NUMERIC,
-                  .identifier.numeric = 0 },
-       .namespaceUri = {.length = 0, .data = NULL}, .serverIndex = 0 };
+/* Global definition of NULL type instances. These are always zeroed out, as
+ * mandated by the C/C++ standard for global values with no initializer. */
+const UA_String UA_STRING_NULL;
+const UA_ByteString UA_BYTESTRING_NULL;
+const UA_Guid UA_GUID_NULL;
+const UA_NodeId UA_NODEID_NULL;
+const UA_ExpandedNodeId UA_EXPANDEDNODEID_NULL;
 
 /* TODO: The standard-defined types are ordered. See if binary search is more
  * efficient. */
@@ -63,11 +60,11 @@ UA_String_fromChars(char const src[]) {
     UA_String str = UA_STRING_NULL;
     size_t length = strlen(src);
     if(length > 0) {
-        str.data = UA_malloc(length);
+        str.data = (UA_Byte*)UA_malloc(length);
         if(!str.data)
             return str;
     } else {
-        str.data = UA_EMPTY_ARRAY_SENTINEL;
+        str.data = (UA_Byte*)UA_EMPTY_ARRAY_SENTINEL;
     }
     memcpy(str.data, src, length);
     str.length = length;
@@ -124,7 +121,7 @@ UA_String
 UA_DateTime_toString(UA_DateTime t) {
     UA_String str = UA_STRING_NULL;
     // length of the string is 31 (plus \0 at the end)
-    if(!(str.data = UA_malloc(32)))
+    if(!(str.data = (UA_Byte*)UA_malloc(32)))
         return str;
     str.length = 31;
     UA_DateTimeStruct tSt = UA_DateTime_toStruct(t);
@@ -182,7 +179,7 @@ UA_ByteString_allocBuffer(UA_ByteString *bs, size_t length) {
     UA_ByteString_init(bs);
     if(length == 0)
         return UA_STATUSCODE_GOOD;
-    if(!(bs->data = UA_malloc(length)))
+    if(!(bs->data = (UA_Byte*)UA_malloc(length)))
         return UA_STATUSCODE_BADOUTOFMEMORY;
     bs->length = length;
     return UA_STATUSCODE_GOOD;
@@ -386,16 +383,16 @@ UA_Variant_setScalar(UA_Variant *v, void * UA_RESTRICT p,
 UA_StatusCode
 UA_Variant_setScalarCopy(UA_Variant *v, const void *p,
                          const UA_DataType *type) {
-    void *new = UA_malloc(type->memSize);
-    if(!new)
+    void *n = UA_malloc(type->memSize);
+    if(!n)
         return UA_STATUSCODE_BADOUTOFMEMORY;
-    UA_StatusCode retval = UA_copy(p, new, type);
+    UA_StatusCode retval = UA_copy(p, n, type);
     if(retval != UA_STATUSCODE_GOOD) {
-        UA_free(new);
+        UA_free(n);
         //cppcheck-suppress memleak
         return retval;
     }
-    UA_Variant_setScalar(v, new, type);
+    UA_Variant_setScalar(v, n, type);
     //cppcheck-suppress memleak
     return UA_STATUSCODE_GOOD;
 }
@@ -524,8 +521,7 @@ UA_Variant_copyRange(const UA_Variant *orig_src, UA_Variant *dst,
      * with in the "scalar" type that may define an array by itself (string,
      * variant, ...). */
     UA_NumericRange thisrange, nextrange;
-    UA_NumericRangeDimension scalarThisDimension = (UA_NumericRangeDimension){
-        .min = 0, .max = 0}; /* a single entry */
+    UA_NumericRangeDimension scalarThisDimension = {0,0}; /* a single entry */
     if(isScalar) {
         /* Replace scalar src with array of length 1 */
         arraySrc = *src;
@@ -629,7 +625,7 @@ UA_Variant_copyRange(const UA_Variant *orig_src, UA_Variant *dst,
     dst->arrayLength = count;
     if(src->arrayDimensionsSize > 0) {
         dst->arrayDimensions =
-            UA_Array_new(thisrange.dimensionsSize, &UA_TYPES[UA_TYPES_UINT32]);
+            (UA_UInt32*)UA_Array_new(thisrange.dimensionsSize, &UA_TYPES[UA_TYPES_UINT32]);
         if(!dst->arrayDimensions) {
             Variant_deletemembers(dst, NULL);
             return UA_STATUSCODE_BADOUTOFMEMORY;
@@ -751,7 +747,7 @@ DiagnosticInfo_copy(UA_DiagnosticInfo const *src, UA_DiagnosticInfo *dst,
     if(src->hasAdditionalInfo)
        retval = UA_String_copy(&src->additionalInfo, &dst->additionalInfo);
     if(src->hasInnerDiagnosticInfo && src->innerDiagnosticInfo) {
-        dst->innerDiagnosticInfo = UA_malloc(sizeof(UA_DiagnosticInfo));
+        dst->innerDiagnosticInfo = (UA_DiagnosticInfo*)UA_malloc(sizeof(UA_DiagnosticInfo));
         if(dst->innerDiagnosticInfo) {
             retval |= DiagnosticInfo_copy(src->innerDiagnosticInfo,
                                           dst->innerDiagnosticInfo, NULL);

+ 9 - 9
src/ua_types_encoding_binary.c

@@ -40,13 +40,13 @@
 
 /* Jumptables for de-/encoding and computing the buffer length */
 typedef UA_StatusCode (*UA_encodeBinarySignature)(const void *UA_RESTRICT src, const UA_DataType *type);
-static const UA_encodeBinarySignature encodeBinaryJumpTable[UA_BUILTIN_TYPES_COUNT + 1];
+extern const UA_encodeBinarySignature encodeBinaryJumpTable[UA_BUILTIN_TYPES_COUNT + 1];
 
 typedef UA_StatusCode (*UA_decodeBinarySignature)(void *UA_RESTRICT dst, const UA_DataType *type);
-static const UA_decodeBinarySignature decodeBinaryJumpTable[UA_BUILTIN_TYPES_COUNT + 1];
+extern const UA_decodeBinarySignature decodeBinaryJumpTable[UA_BUILTIN_TYPES_COUNT + 1];
 
 typedef size_t (*UA_calcSizeBinarySignature)(const void *UA_RESTRICT p, const UA_DataType *contenttype);
-static const UA_calcSizeBinarySignature calcSizeBinaryJumpTable[UA_BUILTIN_TYPES_COUNT + 1];
+extern const UA_calcSizeBinarySignature calcSizeBinaryJumpTable[UA_BUILTIN_TYPES_COUNT + 1];
 
 /* We give pointers to the current position and the last position in the buffer
    instead of a string with an offset. */
@@ -831,11 +831,11 @@ ExtensionObject_decodeBinary(UA_ExtensionObject *dst, const UA_DataType *_) {
     }
 
     if(encoding == UA_EXTENSIONOBJECT_ENCODED_NOBODY) {
-        dst->encoding = encoding;
+        dst->encoding = (UA_ExtensionObjectEncoding)encoding;
         dst->content.encoded.typeId = typeId;
         dst->content.encoded.body = UA_BYTESTRING_NULL;
     } else if(encoding == UA_EXTENSIONOBJECT_ENCODED_XML) {
-        dst->encoding = encoding;
+        dst->encoding = (UA_ExtensionObjectEncoding)encoding;
         dst->content.encoded.typeId = typeId;
         retval = ByteString_decodeBinary(&dst->content.encoded.body);
     } else {
@@ -1140,7 +1140,7 @@ DiagnosticInfo_decodeBinary(UA_DiagnosticInfo *dst, const UA_DataType *_) {
     }
     if(encodingMask & 0x40) {
         /* innerDiagnosticInfo is allocated on the heap */
-        dst->innerDiagnosticInfo = UA_calloc(1, sizeof(UA_DiagnosticInfo));
+        dst->innerDiagnosticInfo = (UA_DiagnosticInfo*)UA_calloc(1, sizeof(UA_DiagnosticInfo));
         if(!dst->innerDiagnosticInfo)
             return UA_STATUSCODE_BADOUTOFMEMORY;
         dst->hasInnerDiagnosticInfo = true;
@@ -1159,7 +1159,7 @@ UA_encodeBinaryInternal(const void *src, const UA_DataType *type);
 static UA_StatusCode
 UA_decodeBinaryInternal(void *dst, const UA_DataType *type);
 
-static const UA_encodeBinarySignature encodeBinaryJumpTable[UA_BUILTIN_TYPES_COUNT + 1] = {
+const UA_encodeBinarySignature encodeBinaryJumpTable[UA_BUILTIN_TYPES_COUNT + 1] = {
     (UA_encodeBinarySignature)Boolean_encodeBinary,
     (UA_encodeBinarySignature)Byte_encodeBinary, // SByte
     (UA_encodeBinarySignature)Byte_encodeBinary,
@@ -1244,7 +1244,7 @@ UA_encodeBinary(const void *src, const UA_DataType *type,
     return retval;
 }
 
-static const UA_decodeBinarySignature decodeBinaryJumpTable[UA_BUILTIN_TYPES_COUNT + 1] = {
+const UA_decodeBinarySignature decodeBinaryJumpTable[UA_BUILTIN_TYPES_COUNT + 1] = {
     (UA_decodeBinarySignature)Boolean_decodeBinary,
     (UA_decodeBinarySignature)Byte_decodeBinary, // SByte
     (UA_decodeBinarySignature)Byte_decodeBinary,
@@ -1514,7 +1514,7 @@ DiagnosticInfo_calcSizeBinary(const UA_DiagnosticInfo *src, UA_DataType *_) {
     return s;
 }
 
-static const UA_calcSizeBinarySignature calcSizeBinaryJumpTable[UA_BUILTIN_TYPES_COUNT + 1] = {
+const UA_calcSizeBinarySignature calcSizeBinaryJumpTable[UA_BUILTIN_TYPES_COUNT + 1] = {
     (UA_calcSizeBinarySignature)calcSizeBinaryMemSize, // Boolean
     (UA_calcSizeBinarySignature)calcSizeBinaryMemSize, // Byte
     (UA_calcSizeBinarySignature)calcSizeBinaryMemSize,