Ver código fonte

split examples per-feature

Julius Pfrommer 9 anos atrás
pai
commit
58b17a6112

+ 18 - 27
CMakeLists.txt

@@ -71,22 +71,17 @@ else()
 endif()
 
 ## extensions
-option(EXTENSION_STATELESS "Enable stateless extension" OFF)
 option(EXTENSION_UDP "Enable udp extension" OFF)
-
 if(EXTENSION_UDP)
 	set(EXTENSION_STATELESS ON)
 	message(STATUS "Extensions: enabling udp")
 	add_definitions(-DEXTENSION_UDP)
 endif()
 
+option(EXTENSION_STATELESS "Enable stateless extension" OFF)
 if(EXTENSION_STATELESS)
 	message(STATUS "Extensions: enabling stateless")
 	add_definitions(-DEXTENSION_STATELESS)
-	add_executable(statelessClient $<TARGET_OBJECTS:open62541-objects> examples/statelessClient.c)
-    if(MULTITHREADING)
-        target_link_libraries(statelessClient urcu-cds urcu urcu-common pthread)
-    endif()
 endif()
 
 add_library(open62541-objects OBJECT ${lib_sources})
@@ -143,35 +138,31 @@ if(CLIENT)
 	add_definitions( -DBENCHMARK=1 )
     # the client is built directly with the .o files as it currently uses
     # internal functions that are not exported to the shared lib.
-	add_executable(exampleClient $<TARGET_OBJECTS:open62541-objects> examples/opcuaClient.c)
+	add_executable(exampleClient $<TARGET_OBJECTS:open62541-objects> examples/client.c)
     if(MULTITHREADING)
         target_link_libraries(exampleClient urcu-cds urcu urcu-common pthread)
     endif()
+    if(EXTENSION_STATELESS)
+        add_executable(statelessClient $<TARGET_OBJECTS:open62541-objects> examples/client_stateless.c)
+        if(MULTITHREADING)
+            target_link_libraries(statelessClient urcu-cds urcu urcu-common pthread)
+        endif()
+    endif()
 endif()
 
 # build example server
 option(EXAMPLESERVER "Build a test server" OFF)
 if(EXAMPLESERVER)
-set(server_sources examples/networklayer_tcp.c examples/logger_stdout.c)
-if(EXTENSION_UDP)
-	list(APPEND server_sources examples/networklayer_udp.c)
-endif()
-add_executable(exampleServer examples/opcuaServer.c ${server_sources} ${exported_headers} ${generated_headers})
-add_executable(exampleServerDataSource examples/opcuaServerDataSource.c ${server_sources}
-                                       ${exported_headers} ${generated_headers})
-target_link_libraries(exampleServer open62541)
-target_link_libraries(exampleServerDataSource open62541)
-if(WIN32)
-    target_link_libraries(exampleServer ws2_32)
-    target_link_libraries(exampleServerDataSource ws2_32)
-else()
-    target_link_libraries(exampleServer rt)
-    target_link_libraries(exampleServerDataSource rt)
-endif(WIN32)
-if(MULTITHREADING)
-    target_link_libraries(exampleServer urcu-cds urcu urcu-common pthread)
-    target_link_libraries(exampleServerDataSource urcu-cds urcu urcu-common pthread)
-endif()
+    add_executable(exampleServer examples/server.c examples/networklayer_tcp.c examples/logger_stdout.c ${exported_headers} ${generated_headers})
+    target_link_libraries(exampleServer open62541)
+    if(WIN32)
+        target_link_libraries(exampleServer ws2_32)
+    else()
+        target_link_libraries(exampleServer rt)
+    endif()
+    if(MULTITHREADING)
+        target_link_libraries(exampleServer urcu-cds urcu urcu-common pthread)
+    endif()
 endif()
 
 ## self-signed certificates

+ 0 - 60
examples/api-design/check_server-api.c

@@ -1,60 +0,0 @@
-#include "open62541.h"
-#include "open62541-server.h"
-#include "check.h"
-
-START_TEST(addingVariableNodeTwiceShallRedirectPointer) {
-	//GIVEN
-	UA_Int32 myInteger = 0, otherInteger = 0;
-	UA_NodeId myIntegerNode = {1, UA_NODEIDTYPE_NUMERIC, 50};
-
-	//WHEN
-	UA_Application_addVariableNode(application, &myIntegerNode, UA_INT32, &myInteger);
-	UA_Application_addVariableNode(application, &myIntegerNode, UA_INT32, &otherInteger);
-
-	//THEN
-	ck_assert_ptr_eq(otherInteger,UA_Application_getVariableNodeAppPtr(application, &myIntegerNode);
-}
-END_TEST
-
-START_TEST(addingDifferentVariableNodesWithSameMemoryShallResultInTwoViewsOnOneMemoryLocation) {
-	//GIVEN
-	UA_Int32 myInteger = 0;
-	UA_NodeId myIntegerNode = {1, UA_NODEIDTYPE_NUMERIC, 50};
-	UA_NodeId otherIntegerNode = {1, UA_NODEIDTYPE_NUMERIC, 51};
-
-	//WHEN
-	UA_Application_addVariableNode(application, &myIntegerNode, UA_INT32, &myInteger);
-	UA_Application_addVariableNode(application, &otherIntegerNode, UA_INT32, &myInteger);
-
-	//THEN
-	ck_assert_ptr_eq(myInteger,UA_Application_getVariableNodeAppPtr(application, &myIntegerNode);
-	ck_assert_ptr_eq(myInteger,UA_Application_getVariableNodeAppPtr(application, &otherIntegerNode);
-}
-END_TEST
-
-Suite *testSuite_builtin(void) {
-	Suite *s = suite_create("Test api");
-
-	TCase *tc_ns0 = tcase_create("populating namespaces");
-	tcase_add_test(tc_ns0, addingVariableNodeTwiceShallRedirectPointer);
-	tcase_add_test(tc_ns0, addingDifferentVariableNodesWithSameMemoryShallResultInTwoViewsOnOneMemoryLocation);
-	suite_add_tcase(s, tc_ns0);
-
-	return s;
-}
-
-
-int main(void) {
-	int      number_failed = 0;
-	Suite   *s;
-	SRunner *sr;
-
-	s  = testSuite_builtin();
-	sr = srunner_create(s);
-	//srunner_set_fork_status(sr, CK_NOFORK);
-	srunner_run_all(sr, CK_NORMAL);
-	number_failed += srunner_ntests_failed(sr);
-	srunner_free(sr);
-
-	return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
-}

+ 0 - 4
examples/api-design/open62541-ns0-pico.h

@@ -1,4 +0,0 @@
-#include "ua_namespace.h"
-
-Namespace UA_NamespaceZero_Static;_
-

+ 0 - 19
examples/api-design/open62541-server.h

@@ -1,19 +0,0 @@
-#include "open62541.h"
-
-struct UA_NetworkLayer;
-typedef struct UA_NetworkLayer UA_NetworkLayer;
-
-struct UA_Application;
-typedef struct UA_Application UA_Application;
-
-typedef struct UA_ServerConfiguration {
-	UA_String certificatePublic;
-	UA_String certificatePrivate;
-	UA_Networklayer *networklayer;
-} UA_ServerConfiguration;
-
-typedef struct UA_Server {
-	UA_ServerConfiguration configuration;
-	UA_Int32 applicationsSize;
-	UA_Application *applications;
-} UA_Server;

+ 0 - 1
examples/api-design/open62541-tcp.h

@@ -1 +0,0 @@
-#include "../networklayer.h"

+ 0 - 2
examples/api-design/open62541.h

@@ -1,2 +0,0 @@
-#include "ua_types.h"
-#include "ua_application.h"

+ 0 - 45
examples/api-design/server.c

@@ -1,45 +0,0 @@
-#include "open62541.h"
-#include "open62541-server.h"
-#include "open62541-tcp.h"
-
-#include "open62541-ns0-pico.h" // UA_NamespaceZero_Static
-
-#define PORT 1234
-#define MAX_CONNECTIONS 1024
-
-int main(int argc, char ** argv) {
-	// Set up UA_Application
-	UA_Application *application;
-	UA_Application_new(&application);
-
-	// Set up namespace Zero and typical application parameters
-	UA_Application_addNamespace(application, 0, &UA_NamespaceZero_Static);
-
-	UA_ApplicationDescription *applicationDescription;
-	UA_Application_new(&applicationDescription);
-	UA_ApplicationDescription_setApplicationName("Application");
-	UA_ApplicationDescription_setApplicationUri("http://open62541.org/api-design/");
-	UA_Application_setVariableNodeNS0(application, UA_APPLICATIONDESCRIPTION_NS0, applicationDescription);
-
-	// Set up application specific namespace
-	UA_Application_addNamespace(application, 1, UA_NULL);
-
-	UA_Int32 myInteger = 0;
-	UA_NodeId myIntegerNode = {1, UA_NODEIDTYPE_NUMERIC, 50};
-	UA_Application_addVariableNode(application, &myIntegerNode, UA_INT32, &myInteger);
-
-	// Set up server with network layer and add application
-	UA_Server *server;
-	UA_Server_new(&server);
-	UA_TcpNetworkLayer_new(&server.configuration.networklayer, PORT, MAX_CONNECTIONS);
-	UA_Server_addApplication(server, application);
-
-	// Run server
-	UA_Server_start(server);
-
-	// Clean up (? first server then application ?)
-	UA_Server_delete(server);
-	UA_Application_delete(application);
-
-	return 0;
-}

examples/opcuaClient.c → examples/client.c


examples/statelessClient.c → examples/client_stateless.c


examples/opcuaServer.c → examples/server.c


+ 4 - 8
examples/opcuaServerDataSource.c

@@ -8,7 +8,6 @@
 #include <stdio.h>
 #include <stdlib.h> 
 #include <signal.h>
-#include <errno.h> // errno, EINTR
 
 // provided by the open62541 lib
 #include "ua_server.h"
@@ -34,10 +33,6 @@ static void releaseTimeData(const void *handle, UA_VariantData* data) {
     UA_DateTime_delete((UA_DateTime*)data->dataPtr);
 }
 
-static void destroyTimeDataSource(const void *handle) {
-    return;
-}
-
 UA_Boolean running = 1;
 
 static void stopHandler(int sign) {
@@ -55,9 +50,10 @@ int main(int argc, char** argv) {
     UA_Variant *myDateTimeVariant = UA_Variant_new();
     myDateTimeVariant->storageType = UA_VARIANT_DATASOURCE;
     myDateTimeVariant->storage.datasource = (UA_VariantDataSource)
-        {.handle = UA_NULL, .read = readTimeData, .release = releaseTimeData,
-         .write = (UA_StatusCode (*)(const void*, const UA_VariantData*))UA_NULL,
-         .destroy = destroyTimeDataSource};
+        {.handle = UA_NULL,
+         .read = readTimeData,
+         .release = releaseTimeData,
+         .write = (UA_StatusCode (*)(const void*, const UA_VariantData*))UA_NULL};
     myDateTimeVariant->type = &UA_TYPES[UA_TYPES_DATETIME];
     myDateTimeVariant->typeId = UA_NODEID_STATIC(UA_TYPES_IDS[UA_TYPES_DATETIME],0);
     UA_QualifiedName myDateTimeName;

+ 48 - 0
examples/server_udp.c

@@ -0,0 +1,48 @@
+/*
+ * This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
+ */
+#include <time.h>
+#include "ua_types.h"
+
+#include <stdio.h>
+#include <stdlib.h> 
+#include <signal.h>
+#include <errno.h> // errno, EINTR
+
+// 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_udp.h"
+
+UA_Boolean running = 1;
+
+static void stopHandler(int sign) {
+    printf("Received Ctrl-C\n");
+	running = 0;
+}
+
+int main(int argc, char** argv) {
+	signal(SIGINT, stopHandler); /* catches ctrl-c */
+
+	UA_Server *server = UA_Server_new();
+    UA_Server_addNetworkLayer(server, ServerNetworkLayerUDP_new(UA_ConnectionConfig_standard, 16664));
+
+	// add a variable node to the adresspace
+    UA_Int32 *myInteger = UA_Int32_new();
+    *myInteger = 42;
+    UA_Variant *myIntegerVariant = UA_Variant_new();
+    UA_Variant_setValue(myIntegerVariant, myInteger, UA_TYPES_INT32);
+    UA_QualifiedName myIntegerName;
+    UA_QUALIFIEDNAME_ASSIGN(myIntegerName, "the answer");
+    UA_Server_addVariableNode(server, myIntegerVariant, &UA_NODEID_NULL, &myIntegerName,
+                              &UA_NODEID_STATIC(UA_NS0ID_OBJECTSFOLDER,0),
+                              &UA_NODEID_STATIC(UA_NS0ID_ORGANIZES,0));
+
+    UA_StatusCode retval = UA_Server_run(server, 1, &running);
+	UA_Server_delete(server);
+
+	return retval;
+}

+ 2 - 4
include/ua_types.h

@@ -86,7 +86,7 @@ typedef uint16_t UA_UInt16;
 /** @brief An integer value between -2 147 483 648 and 2 147 483 647. */
 typedef int32_t UA_Int32;
 #define UA_INT32_MAX 2147483647
-#define UA_INT32_MIN 2147483648
+#define UA_INT32_MIN -2147483648
 
 /** @brief An integer value between 0 and 429 4967 295. */
 typedef uint32_t UA_UInt32;
@@ -96,7 +96,7 @@ typedef uint32_t UA_UInt32;
 /** @brief An integer value between -10 223 372 036 854 775 808 and 9 223 372 036 854 775 807 */
 typedef int64_t UA_Int64;
 #define UA_INT64_MAX 9223372036854775807
-#define UA_INT64_MIN 9223372036854775808
+#define UA_INT64_MIN -9223372036854775808
 
 /** @brief An integer value between 0 and 18 446 744 073 709 551 615. */
 typedef uint64_t UA_UInt64;
@@ -209,7 +209,6 @@ typedef struct {
     UA_StatusCode (*read)(const void *handle, UA_VariantData *data);
     void (*release)(const void *handle, UA_VariantData *data);
     UA_StatusCode (*write)(const void *handle, const UA_VariantData *data);
-    void (*destroy)(const void *handle);
 } UA_VariantDataSource;
 
 struct UA_DataType;
@@ -386,7 +385,6 @@ UA_Boolean UA_EXPORT UA_ExpandedNodeId_isNull(const UA_ExpandedNodeId *p);
 
 /* QualifiedName */
 UA_StatusCode UA_EXPORT UA_QualifiedName_copycstring(char const *src, UA_QualifiedName *dst);
-void UA_EXPORT UA_QualifiedName_printf(char const *label, const UA_QualifiedName *qn);
 #define UA_QUALIFIEDNAME_ASSIGN(VARIABLE, STRING) do {          \
         VARIABLE.namespaceIndex = 0;                            \
         UA_STRING_ASSIGN(VARIABLE.name, STRING); } while(0)

+ 0 - 2
src/ua_types.c

@@ -590,8 +590,6 @@ void UA_Variant_deleteMembers(UA_Variant *p) {
             UA_free(p->storage.data.arrayDimensions);
             p->storage.data.arrayDimensions = UA_NULL;
         }
-    } else if(p->storageType == UA_VARIANT_DATASOURCE) {
-        p->storage.datasource.destroy(p->storage.datasource.handle);
     }
 }