diff --git a/examples/server_method.c b/examples/server_method.c index e8668b7e3d5..03459babceb 100644 --- a/examples/server_method.c +++ b/examples/server_method.c @@ -3,8 +3,10 @@ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */ +#include +#include + #ifdef UA_NO_AMALGAMATION -# include # include "ua_types.h" # include "ua_server.h" # include "logger_stdout.h" @@ -13,11 +15,6 @@ # include "open62541.h" #endif -#include -#include -#include -#include - UA_Boolean running = UA_TRUE; UA_Logger logger; @@ -29,24 +26,25 @@ static UA_StatusCode helloWorldMethod(const UA_NodeId objectId, const UA_Variant memcpy(&tmp.data[tmp.length], inputStr->data, inputStr->length); tmp.length += inputStr->length; } - UA_Variant_setScalar(output, &tmp, &UA_TYPES[UA_TYPES_STRING]); + UA_Variant_setScalarCopy(output, &tmp, &UA_TYPES[UA_TYPES_STRING]); + UA_String_deleteMembers(&tmp); UA_LOG_INFO(logger, UA_LOGCATEGORY_SERVER, "Hello World was called"); return UA_STATUSCODE_GOOD; } static void stopHandler(int sign) { - UA_LOG_INFO(logger, UA_LOGCATEGORY_SERVER, "Received Ctrl-C"); - running = 0; + UA_LOG_INFO(logger, UA_LOGCATEGORY_SERVER, "received ctrl-c"); + running = 0; } int main(int argc, char** argv) { - signal(SIGINT, stopHandler); /* catches ctrl-c */ + signal(SIGINT, stopHandler); /* catches ctrl-c */ /* initialize the server */ UA_Server *server = UA_Server_new(UA_ServerConfig_standard); logger = Logger_Stdout_new(); UA_Server_setLogger(server, logger); - UA_Server_addNetworkLayer(server, ServerNetworkLayerTCP_new(UA_ConnectionConfig_standard, 16664)); + UA_Server_addNetworkLayer(server, ServerNetworkLayerTCP_new(UA_ConnectionConfig_standard, 16664)); /* add the method node with the callback */ UA_Argument inputArguments; @@ -67,14 +65,14 @@ int main(int argc, char** argv) { outputArguments.name = UA_STRING("MyOutput"); outputArguments.valueRank = -1; - UA_Server_addMethodNode(server, UA_QUALIFIEDNAME(1,"ping"), UA_NODEID_NUMERIC(1,62541), + UA_Server_addMethodNode(server, UA_QUALIFIEDNAME(1, "hello world"), UA_NODEID_NUMERIC(1,62541), UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), &helloWorldMethod, 1, &inputArguments, 1, &outputArguments); /* start server */ - UA_StatusCode retval = UA_Server_run(server, 1, &running); //blocks until running=false + UA_StatusCode retval = UA_Server_run(server, 1, &running); //blocks until running=false - /* ctrl-c received -> clean up */ - UA_Server_delete(server); - return retval; + /* ctrl-c received -> clean up */ + UA_Server_delete(server); + return retval; } diff --git a/examples/server_repeated_job.c b/examples/server_repeated_job.c index 7e4e81c9267..46f2ed3e54b 100644 --- a/examples/server_repeated_job.c +++ b/examples/server_repeated_job.c @@ -2,12 +2,8 @@ * 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 -#include -#include + #include -#include // errno, EINTR -#include #ifdef UA_NO_AMALGAMATION # include "ua_types.h" @@ -22,8 +18,8 @@ UA_Boolean running = 1; UA_Logger logger; static void stopHandler(int sign) { - printf("Received Ctrl-C\n"); - running = 0; + UA_LOG_INFO(logger, UA_LOGCATEGORY_SERVER, "received ctrl-c"); + running = 0; } static void testCallback(UA_Server *server, void *data) { @@ -31,19 +27,19 @@ static void testCallback(UA_Server *server, void *data) { } int main(int argc, char** argv) { - signal(SIGINT, stopHandler); /* catches ctrl-c */ + signal(SIGINT, stopHandler); /* catches ctrl-c */ - UA_Server *server = UA_Server_new(UA_ServerConfig_standard); + UA_Server *server = UA_Server_new(UA_ServerConfig_standard); logger = Logger_Stdout_new(); UA_Server_setLogger(server, logger); UA_Server_addNetworkLayer(server, ServerNetworkLayerTCP_new(UA_ConnectionConfig_standard, 16664)); - /* add a repeated job to the server */ + /* add a repeated job to the server */ UA_Job job = {.type = UA_JOBTYPE_METHODCALL, .job.methodCall = {.method = testCallback, .data = NULL} }; UA_Server_addRepeatedJob(server, job, 2000, NULL); // call every 2 sec UA_StatusCode retval = UA_Server_run(server, 1, &running); - UA_Server_delete(server); - return retval; + UA_Server_delete(server); + return retval; } diff --git a/examples/server_variable.c b/examples/server_variable.c index 39e22936f10..e602dc53360 100644 --- a/examples/server_variable.c +++ b/examples/server_variable.c @@ -2,12 +2,8 @@ * 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 -#include -#include + #include -#include // errno, EINTR -#include #ifdef UA_NO_AMALGAMATION # include "ua_types.h" @@ -22,19 +18,19 @@ UA_Boolean running = 1; UA_Logger logger; static void stopHandler(int sign) { - printf("Received Ctrl-C\n"); - running = 0; + UA_LOG_INFO(logger, UA_LOGCATEGORY_SERVER, "received ctrl-c"); + running = 0; } int main(int argc, char** argv) { - signal(SIGINT, stopHandler); /* catches ctrl-c */ + signal(SIGINT, stopHandler); /* catches ctrl-c */ - UA_Server *server = UA_Server_new(UA_ServerConfig_standard); + UA_Server *server = UA_Server_new(UA_ServerConfig_standard); logger = Logger_Stdout_new(); UA_Server_setLogger(server, logger); UA_Server_addNetworkLayer(server, ServerNetworkLayerTCP_new(UA_ConnectionConfig_standard, 16664)); - /* add a variable node to the adresspace */ + /* add a variable node to the adresspace */ UA_Variant *myIntegerVariant = UA_Variant_new(); UA_Int32 myInteger = 42; UA_Variant_setScalarCopy(myIntegerVariant, &myInteger, &UA_TYPES[UA_TYPES_INT32]); @@ -46,7 +42,7 @@ int main(int argc, char** argv) { myIntegerNodeId, parentNodeId, parentReferenceNodeId); UA_StatusCode retval = UA_Server_run(server, 1, &running); - UA_Server_delete(server); + UA_Server_delete(server); - return retval; + return retval; } diff --git a/include/ua_types.h b/include/ua_types.h index cd108c2f37a..beed7a7d2b8 100644 --- a/include/ua_types.h +++ b/include/ua_types.h @@ -23,6 +23,7 @@ extern "C" { #include #include #include +#include #include "ua_config.h" /** @brief A two-state logical value (true or false). */