Forráskód Böngészése

replace UA_EQUAL struct with simpler UA_Boolean
moved UA_NULL, UA_TRUE, UA_FALSE to ua_util.h

Julius Pfrommer 10 éve
szülő
commit
a7ad2103ca

+ 7 - 7
examples/networklayer_tcp.c

@@ -54,12 +54,12 @@ typedef struct TCPConnectionHandle {
 UA_StatusCode NetworklayerTCP_new(NetworklayerTCP **newlayer, UA_ConnectionConfig localConf,
                                   UA_UInt32 port) {
     *newlayer = malloc(sizeof(NetworklayerTCP));
-    if(*newlayer == UA_NULL)
+    if(*newlayer == NULL)
         return UA_STATUSCODE_BADOUTOFMEMORY;
 	(*newlayer)->localConf = localConf;
 	(*newlayer)->port = port;
 	(*newlayer)->connectionsSize = 0;
-	(*newlayer)->connections = UA_NULL;
+	(*newlayer)->connections = NULL;
 	return UA_STATUSCODE_GOOD;
 }
 
@@ -76,7 +76,7 @@ static UA_StatusCode NetworklayerTCP_remove(NetworklayerTCP *layer, UA_Int32 soc
         return UA_STATUSCODE_BADINTERNALERROR;
 
     if(layer->connections[index].connection.channel)
-        layer->connections[index].connection.channel->connection = UA_NULL;
+        layer->connections[index].connection.channel->connection = NULL;
 
 	UA_Connection_deleteMembers(&layer->connections[index].connection);
 
@@ -95,7 +95,7 @@ void NetworklayerTCP_delete(NetworklayerTCP *layer) {
 	for(UA_UInt32 index = 0;index < layer->connectionsSize;index++) {
 		shutdown(layer->connections[index].sockfd, 2);
         if(layer->connections[index].connection.channel)
-            layer->connections[index].connection.channel->connection = UA_NULL;
+            layer->connections[index].connection.channel->connection = NULL;
         UA_Connection_deleteMembers(&layer->connections[index].connection);
 		CLOSESOCKET(layer->connections[index].sockfd);
 	}
@@ -139,8 +139,8 @@ void writeCallback(TCPConnectionHandle *handle, UA_ByteStringArray gather_buf) {
 		iov[i].iov_len = gather_buf.strings[i].length;
 		total_len += gather_buf.strings[i].length;
 	}
-	struct msghdr message = {.msg_name = UA_NULL, .msg_namelen = 0, .msg_iov = iov,
-							 .msg_iovlen = gather_buf.stringsSize, .msg_control = UA_NULL,
+	struct msghdr message = {.msg_name = NULL, .msg_namelen = 0, .msg_iov = iov,
+							 .msg_iovlen = gather_buf.stringsSize, .msg_control = NULL,
 							 .msg_controllen = 0, .msg_flags = 0};
 	while (nWritten < total_len) {
 		UA_Int32 n = 0;
@@ -303,7 +303,7 @@ UA_StatusCode NetworkLayerTCP_run(NetworklayerTCP *layer, UA_Server *server, str
 	while (*running) {
 		setFDSet(layer);
 		struct timeval tmptv = tv;
-		UA_Int32 resultsize = select(layer->highestfd, &layer->fdset, UA_NULL, UA_NULL, &tmptv);
+		UA_Int32 resultsize = select(layer->highestfd, &layer->fdset, NULL, NULL, &tmptv);
 		if (resultsize <= 0) {
 #ifdef WIN32
 			UA_Int32 err = (resultsize == SOCKET_ERROR) ? WSAGetLastError() : 0;

+ 6 - 16
include/ua_types.h

@@ -21,21 +21,11 @@ extern "C" {
 #endif
 
 #include <stdint.h>
-#include "ua_config.h"
-
 #ifdef DEBUG
 #include <stdio.h>
 #endif
 
-/* For internal use */
-#define UA_NULL ((void *)0)
-#define UA_TRUE (42 == 42)
-#define UA_FALSE (!UA_TRUE)
-
-typedef enum UA_EQUALITY {
-    UA_EQUAL,
-    UA_NOT_EQUAL
-} UA_EQUALITY;
+#include "ua_config.h"
     
 /**
  * @defgroup types Datatypes
@@ -355,14 +345,14 @@ UA_TYPE_PROTOTYPES(UA_DiagnosticInfo)
 UA_TYPE_PROTOTYPES(UA_InvalidType)
 
 /* String */
-#define UA_STRING_NULL (UA_String) {-1, UA_NULL }
+#define UA_STRING_NULL (UA_String) {-1, (UA_Byte*)0 }
 #define UA_STRING_STATIC(VARIABLE, STRING) do { \
         VARIABLE.length = sizeof(STRING)-1;     \
         VARIABLE.data   = (UA_Byte *)STRING; } while(0)
 
 UA_StatusCode UA_EXPORT UA_String_copycstring(char const *src, UA_String *dst);
 UA_StatusCode 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);
+UA_Boolean UA_EXPORT UA_String_equal(const UA_String *string1, const UA_String *string2);
 #ifdef DEBUG
 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);
@@ -386,10 +376,10 @@ UA_DateTimeStruct UA_EXPORT UA_DateTime_toStruct(UA_DateTime time);
 UA_StatusCode UA_EXPORT UA_DateTime_toString(UA_DateTime time, UA_String *timeString);
 
 /* Guid */
-UA_EQUALITY UA_EXPORT UA_Guid_equal(const UA_Guid *g1, const UA_Guid *g2);
+UA_Boolean UA_EXPORT UA_Guid_equal(const UA_Guid *g1, const UA_Guid *g2);
 
 /* ByteString */
-UA_EQUALITY UA_EXPORT UA_ByteString_equal(const UA_ByteString *string1, const UA_ByteString *string2);
+UA_Boolean UA_EXPORT UA_ByteString_equal(const UA_ByteString *string1, const UA_ByteString *string2);
 UA_StatusCode UA_EXPORT UA_ByteString_newMembers(UA_ByteString *p, UA_Int32 length);
 #ifdef DEBUG
 void UA_EXPORT UA_ByteString_printf(char *label, const UA_ByteString *string);
@@ -398,7 +388,7 @@ void UA_EXPORT UA_ByteString_printx_hex(char *label, const UA_ByteString *string
 #endif
 
 /* NodeId */
-UA_EQUALITY UA_EXPORT UA_NodeId_equal(const UA_NodeId *n1, const UA_NodeId *n2);
+UA_Boolean 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);
 

+ 2 - 2
src/server/ua_nodestore.c

@@ -176,7 +176,7 @@ static INLINE UA_StatusCode find_entry(const UA_NodeStore *ns, const UA_NodeId *
         return UA_STATUSCODE_BADINTERNALERROR;
     }
 
-    if(UA_NodeId_equal(&(*e)->nodeId, nodeid) == UA_EQUAL) {
+    if(UA_NodeId_equal(&(*e)->nodeId, nodeid)) {
         *entry = e;
         return UA_STATUSCODE_GOOD;
     }
@@ -194,7 +194,7 @@ static INLINE UA_StatusCode find_entry(const UA_NodeStore *ns, const UA_NodeId *
             return UA_STATUSCODE_BADINTERNALERROR;
         }
 
-        if(UA_NodeId_equal(&(*e)->nodeId, nodeid) == UA_EQUAL) {
+        if(UA_NodeId_equal(&(*e)->nodeId, nodeid)) {
             *entry = e;
             return UA_STATUSCODE_GOOD;
         }

+ 1 - 1
src/server/ua_nodestore_concurrent.c

@@ -146,7 +146,7 @@ static int compare(struct cds_lfht_node *htn, const void *orig) {
     UA_NodeId *origid = (UA_NodeId *)orig;
     UA_NodeId *newid  = &((UA_NodeStore_Entry *)htn)->node.nodeId;   /* The htn is first in the entry structure. */
 
-    return UA_NodeId_equal(newid, origid) == UA_EQUAL;
+    return UA_NodeId_equal(newid, origid);
 }
 
 /* The entry was removed from the hashtable. No more readers can get it. Since

+ 1 - 1
src/server/ua_services_view.c

@@ -64,7 +64,7 @@ static UA_Boolean isRelevantTargetNode(UA_NodeStore *ns, const UA_BrowseDescript
     UA_Boolean isRelevant = returnAll;
     if(!isRelevant) {
         for(UA_UInt32 i = 0;i < relevantRefTypesCount;i++) {
-            if(UA_NodeId_equal(&reference->referenceTypeId, &relevantRefTypes[i]) == UA_EQUAL)
+            if(UA_NodeId_equal(&reference->referenceTypeId, &relevantRefTypes[i]))
                 isRelevant = UA_TRUE;
         }
         if(!isRelevant)

+ 3 - 3
src/server/ua_session_manager.c

@@ -55,7 +55,7 @@ UA_StatusCode UA_SessionManager_getSessionById(UA_SessionManager *sessionManager
 
     struct session_list_entry *current = UA_NULL;
     LIST_FOREACH(current, &sessionManager->sessions, pointers) {
-        if(UA_NodeId_equal(&current->session.sessionId, sessionId) == UA_EQUAL)
+        if(UA_NodeId_equal(&current->session.sessionId, sessionId))
             break;
     }
 
@@ -78,7 +78,7 @@ UA_StatusCode UA_SessionManager_getSessionByToken(UA_SessionManager *sessionMana
 
     struct session_list_entry *current = UA_NULL;
     LIST_FOREACH(current, &sessionManager->sessions, pointers) {
-        if(UA_NodeId_equal(&current->session.authenticationToken, token) == UA_EQUAL)
+        if(UA_NodeId_equal(&current->session.authenticationToken, token))
             break;
     }
 
@@ -122,7 +122,7 @@ UA_StatusCode UA_SessionManager_createSession(UA_SessionManager *sessionManager,
 UA_StatusCode UA_SessionManager_removeSession(UA_SessionManager *sessionManager, UA_NodeId  *sessionId) {
     struct session_list_entry *current = UA_NULL;
     LIST_FOREACH(current, &sessionManager->sessions, pointers) {
-        if(UA_NodeId_equal(&current->session.sessionId, sessionId) == UA_EQUAL)
+        if(UA_NodeId_equal(&current->session.sessionId, sessionId))
             break;
     }
 

+ 1 - 2
src/ua_session.c

@@ -99,8 +99,7 @@ void UA_Session_delete(UA_Session *session) {
 }
 
 UA_Boolean UA_Session_compare(UA_Session *session1, UA_Session *session2) {
-    if(session1 && session2 &&
-       UA_NodeId_equal(&session1->sessionId, &session2->sessionId) == UA_EQUAL)
+    if(session1 && session2 && UA_NodeId_equal(&session1->sessionId, &session2->sessionId))
         return UA_TRUE;
     return UA_FALSE;
 }

+ 13 - 13
src/ua_types.c

@@ -198,15 +198,15 @@ UA_StatusCode UA_String_copyprintf(char const *fmt, UA_String *dst, ...) {
     return UA_STATUSCODE_GOOD;
 }
 
-UA_EQUALITY UA_String_equal(const UA_String *string1, const UA_String *string2) {
+UA_Boolean UA_String_equal(const UA_String *string1, const UA_String *string2) {
     if(string1->length <= 0 && string2->length <= 0)
-        return UA_EQUAL;
+        return UA_TRUE;
     if(string1->length != string2->length)
-        return UA_NOT_EQUAL;
+        return UA_FALSE;
 
     // casts are needed to overcome signed warnings
     UA_Int32 is = strncmp((char const *)string1->data, (char const *)string2->data, string1->length);
-    return (is == 0) ? UA_EQUAL : UA_NOT_EQUAL;
+    return (is == 0) ? UA_TRUE : UA_FALSE;
 }
 
 #ifdef DEBUG
@@ -319,10 +319,10 @@ UA_StatusCode UA_DateTime_toString(UA_DateTime time, UA_String *timeString) {
 UA_TYPE_DELETE_DEFAULT(UA_Guid)
 UA_TYPE_DELETEMEMBERS_NOACTION(UA_Guid)
 
-UA_EQUALITY UA_Guid_equal(const UA_Guid *g1, const UA_Guid *g2) {
+UA_Boolean UA_Guid_equal(const UA_Guid *g1, const UA_Guid *g2) {
     if(memcmp(g1, g2, sizeof(UA_Guid)) == 0)
-        return UA_EQUAL;
-    return UA_NOT_EQUAL;
+        return UA_TRUE;
+    return UA_FALSE;
 }
 
 void UA_Guid_init(UA_Guid *p) {
@@ -347,7 +347,7 @@ void UA_Guid_print(const UA_Guid *p, FILE *stream) {
 
 /* ByteString */
 UA_TYPE_AS(UA_ByteString, UA_String)
-UA_EQUALITY UA_ByteString_equal(const UA_ByteString *string1, const UA_ByteString *string2) {
+UA_Boolean UA_ByteString_equal(const UA_ByteString *string1, const UA_ByteString *string2) {
     return UA_String_equal((const UA_String *)string1, (const UA_String *)string2);
 }
 
@@ -510,16 +510,16 @@ void UA_NodeId_print(const UA_NodeId *p, FILE *stream) {
 }
 #endif
 
-UA_EQUALITY UA_NodeId_equal(const UA_NodeId *n1, const UA_NodeId *n2) {
+UA_Boolean UA_NodeId_equal(const UA_NodeId *n1, const UA_NodeId *n2) {
     if(n1->namespaceIndex != n2->namespaceIndex)
-        return UA_NOT_EQUAL;
+        return UA_FALSE;
 
     switch(n1->identifierType) {
     case UA_NODEIDTYPE_NUMERIC:
         if(n1->identifier.numeric == n2->identifier.numeric)
-            return UA_EQUAL;
+            return UA_TRUE;
         else
-            return UA_NOT_EQUAL;
+            return UA_FALSE;
 
     case UA_NODEIDTYPE_STRING:
         return UA_String_equal(&n1->identifier.string, &n2->identifier.string);
@@ -530,7 +530,7 @@ UA_EQUALITY UA_NodeId_equal(const UA_NodeId *n1, const UA_NodeId *n2) {
     case UA_NODEIDTYPE_BYTESTRING:
         return UA_ByteString_equal(&n1->identifier.byteString, &n2->identifier.byteString);
     }
-    return UA_NOT_EQUAL;
+    return UA_FALSE;
 }
 
 UA_Boolean UA_NodeId_isNull(const UA_NodeId *p) {

+ 4 - 0
src/ua_util.h

@@ -17,6 +17,10 @@
 
 #include "ua_types.h"
 
+#define UA_NULL ((void *)0)
+#define UA_TRUE (42 == 42)
+#define UA_FALSE (!UA_TRUE)
+
 /* Debug macros */
 #define DBG_VERBOSE(expression) // omit debug code
 #define DBG_ERR(expression)     // omit debug code

+ 1 - 1
tests/check_memory.c

@@ -76,7 +76,7 @@ START_TEST(encodeShallYieldDecode) {
 	ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
 
 	// then
-	ck_assert_msg(UA_ByteString_equal(&msg1, &msg2) == 0, "messages differ idx=%d,name=%s", _i, UA_[_i].name);
+	ck_assert_msg(UA_ByteString_equal(&msg1, &msg2) == UA_TRUE, "messages differ idx=%d,name=%s", _i, UA_[_i].name);
 
 	// finally
 	UA_[_i].delete(obj1);