server_nodeset.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  2. * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
  3. #include <open62541/plugin/log_stdout.h>
  4. #include <open62541/server.h>
  5. #include <open62541/server_config_default.h>
  6. /* Files example_namespace.h and example_namespace.c are created from server_nodeset.xml in the
  7. * /src_generated directory by CMake */
  8. #include "open62541/example_nodeids.h"
  9. #include "open62541/namespace_example_generated.h"
  10. #include <signal.h>
  11. #include <stdlib.h>
  12. UA_Boolean running = true;
  13. static void stopHandler(int sign) {
  14. UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "received ctrl-c");
  15. running = false;
  16. }
  17. int main(int argc, char** argv) {
  18. signal(SIGINT, stopHandler);
  19. signal(SIGTERM, stopHandler);
  20. UA_Server *server = UA_Server_new();
  21. UA_ServerConfig_setDefault(UA_Server_getConfig(server));
  22. UA_StatusCode retval;
  23. /* create nodes from nodeset */
  24. if(namespace_example_generated(server) != UA_STATUSCODE_GOOD) {
  25. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "Could not add the example nodeset. "
  26. "Check previous output for any error.");
  27. retval = UA_STATUSCODE_BADUNEXPECTEDERROR;
  28. } else {
  29. // Do some additional stuff with the nodes
  30. // this will just get the namespace index, since it is already added to the server
  31. UA_UInt16 nsIdx = UA_Server_addNamespace(server, "http://yourorganisation.org/test/");
  32. UA_NodeId testInstanceId = UA_NODEID_NUMERIC(nsIdx, UA_EXAMPLE_NSID_TESTINSTANCE);
  33. UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "The testInstance has ns=%d;id=%d",
  34. testInstanceId.namespaceIndex, testInstanceId.identifier.numeric);
  35. retval = UA_Server_run(server, &running);
  36. }
  37. UA_Server_delete(server);
  38. return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
  39. }