Browse Source

fix udp, c++ server

Julius Pfrommer 9 years ago
parent
commit
5f393b5309

+ 1 - 1
examples/networklayer_tcp.c

@@ -596,7 +596,7 @@ UA_ClientNetworkLayer ClientNetworkLayerTCP_new(UA_ConnectionConfig conf) {
     layer.nlHandle = tcplayer;
     layer.connect = (UA_StatusCode (*)(const UA_String, void**)) ClientNetworkLayerTCP_connect;
     layer.disconnect = (void (*)(void*)) ClientNetworkLayerTCP_disconnect;
-    layer.delete = (void (*)(void*)) ClientNetworkLayerTCP_delete;
+    layer.destroy = (void (*)(void*)) ClientNetworkLayerTCP_delete;
     layer.send = (UA_StatusCode (*)(void*, UA_ByteStringArray)) ClientNetworkLayerTCP_send;
     layer.awaitResponse = (UA_StatusCode (*)(void*, UA_ByteString *, UA_UInt32))ClientNetworkLayerTCP_awaitResponse;
     return layer;

+ 12 - 16
examples/server.cpp

@@ -4,21 +4,18 @@
  */
 #include <iostream>
 
-// provided by the open62541 lib
-#include "ua_server.h"
-
-// provided by the user, implementations available in the /examples folder
-#include "logger_stdout.h"
-#include "networklayer_tcp.h"
+#ifdef NOT_AMALGATED
+# include "ua_server.h"
+# include "logger_stdout.h"
+# include "networklayer_tcp.h"
+#else
+# include "open62541.h"
+#endif
 
 /**
  * Build Instructions (Linux)
- *
- * To build this C++ server, first compile the open62541 library. Then, compile the network layer and logging with a C compiler.
- * - gcc -std=c99 -c networklayer_tcp.c -I../include -I../build/src_generated
- * - gcc -std=c99 -c logger_stdout.c -I../include -I../build/src_generated
- * Lastly, compile and link the C++ server with
- * - g++ server.cpp networklayer_tcp.o logger_stdout.o ../build/libopen62541.a -I../include -I../build/src_generated -o server
+ * - gcc -std=c99 -c open62541.c
+ * - g++ server.cpp open62541.o -o server
  */
 
 using namespace std;
@@ -32,11 +29,10 @@ int main()
     UA_Variant *myIntegerVariant = UA_Variant_new();
     UA_Int32 myInteger = 42;
     UA_Variant_setScalarCopy(myIntegerVariant, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
-    UA_QualifiedName myIntegerName;
-    UA_QUALIFIEDNAME_ASSIGN(myIntegerName, "the answer");
+    UA_QualifiedName myIntegerName = UA_QUALIFIEDNAME(1, "the answer");
     UA_NodeId myIntegerNodeId = UA_NODEID_NULL; /* assign a random free nodeid */
-    UA_NodeId parentNodeId = UA_NODEID_STATIC(0, UA_NS0ID_OBJECTSFOLDER);
-    UA_NodeId parentReferenceNodeId = UA_NODEID_STATIC(0, UA_NS0ID_ORGANIZES);
+    UA_NodeId parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
+    UA_NodeId parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
     UA_Server_addVariableNode(server, myIntegerVariant, myIntegerName,
                               myIntegerNodeId, parentNodeId, parentReferenceNodeId);
 

+ 1 - 2
examples/server_udp.c

@@ -33,8 +33,7 @@ int main(int argc, char** argv) {
     UA_Variant *myIntegerVariant = UA_Variant_new();
     UA_Int32 myInteger = 42;
     UA_Variant_setScalarCopy(myIntegerVariant, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
-    UA_QualifiedName myIntegerName;
-    UA_QUALIFIEDNAME_ASSIGN(myIntegerName, "the answer");
+    UA_QualifiedName myIntegerName = UA_QUALIFIEDNAME(1, "the answer");
     UA_NodeId myIntegerNodeId = UA_NODEID_NULL; /* assign a random free nodeid */
     UA_NodeId parentNodeId = UA_NODEID_STATIC(0, UA_NS0ID_OBJECTSFOLDER);
     UA_NodeId parentReferenceNodeId = UA_NODEID_STATIC(0, UA_NS0ID_ORGANIZES);

+ 1 - 1
include/ua_client.h

@@ -19,7 +19,7 @@ typedef struct {
 
     UA_StatusCode (*connect)(const UA_String endpointUrl, void **resultHandle);
     void (*disconnect)(void *handle);
-    void (*delete)(void *handle);
+    void (*destroy)(void *handle);
     UA_StatusCode (*send)(void *handle, UA_ByteStringArray gather_buf);
     // the response buffer exists on the heap. the size shall correspond the the connection settings
     UA_StatusCode (*awaitResponse)(void *handle, UA_ByteString *response, UA_UInt32 timeout);

+ 7 - 3
include/ua_server.h

@@ -213,6 +213,12 @@ void UA_EXPORT UA_Server_addNetworkLayer(UA_Server *server, UA_ServerNetworkLaye
 
 /** @} */
 
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#ifndef __cplusplus /* the external nodestore does not work with c++ so far */
+
 /**
  * @ingroup nodestore
  *
@@ -283,8 +289,6 @@ typedef struct UA_ExternalNodeStore {
 
 /** @} */
 
-#ifdef __cplusplus
-} // extern "C"
-#endif
+#endif /* external nodestore */
 
 #endif /* UA_SERVER_H_ */

+ 20 - 0
include/ua_types.h

@@ -373,6 +373,7 @@ UA_Boolean UA_EXPORT UA_NodeId_equal(const UA_NodeId *n1, const UA_NodeId *n2);
 /** Is the nodeid a null-nodeid? */
 UA_Boolean UA_EXPORT UA_NodeId_isNull(const UA_NodeId *p);
 
+#ifndef __cplusplus
 #define UA_NODEID_NUMERIC(NS_INDEX, NUMERICID) (UA_NodeId) {           \
         .namespaceIndex = NS_INDEX,                                    \
         .identifierType = UA_NODEIDTYPE_NUMERIC,                       \
@@ -402,6 +403,25 @@ UA_Boolean UA_EXPORT UA_NodeId_isNull(const UA_NodeId *p);
         .namespaceIndex = NS_INDEX,                                    \
         .identifierType = UA_NODEIDTYPE_BYTESTRING,                    \
         .identifier.byteString = UA_STRING_ALLOC(CHARS) }
+#else
+#define UA_NODEID_NUMERIC(NS_INDEX, NUMERICID) (UA_NodeId) {    \
+        NS_INDEX, UA_NodeId::UA_NODEIDTYPE_NUMERIC, NUMERICID }
+
+#define UA_NODEID_STRING(NS_INDEX, CHARS) (const UA_NodeId) {           \
+        NS_INDEX, UA_NodeId::UA_NODEIDTYPE_STRING, UA_STRING(CHARS) }
+
+#define UA_NODEID_STRING_ALLOC(NS_INDEX, CHARS) (const UA_NodeId) {     \
+        NS_INDEX, UA_NodeId::UA_NODEIDTYPE_STRING, UA_STRING_ALLOC(CHARS) }
+
+#define UA_NODEID_GUID(NS_INDEX, GUID) (UA_NodeId) {    \
+        NS_INDEX, UA_NodeId::UA_NODEIDTYPE_GUID, GUID }
+
+#define UA_NODEID_BYTESTRING(NS_INDEX, CHARS) (const UA_NodeId) {       \
+        NS_INDEX, UA_NodeId::UA_NODEIDTYPE_BYTESTRING, UA_STRING(CHARS) }
+
+#define UA_NODEID_BYTESTRING_ALLOC(NS_INDEX, CHARS) (const UA_NodeId) { \
+        NS_INDEX, UA_NodeId::UA_NODEIDTYPE_BYTESTRING, UA_STRING_ALLOC(CHARS) }
+#endif
 
 #define UA_NODEID_NULL UA_NODEID_NUMERIC(0,0)
 

+ 1 - 1
src/client/ua_client.c

@@ -46,7 +46,7 @@ UA_Client * UA_Client_new(void) {
 }
 
 void UA_Client_delete(UA_Client* client){
-    client->networkLayer.delete(client->networkLayer.nlHandle);
+    client->networkLayer.destroy(client->networkLayer.nlHandle);
     UA_String_deleteMembers(&client->endpointUrl);
     // client->connection