server_nodeset.c 1.8 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 <ua_server.h>
  4. #include <ua_config_default.h>
  5. #include <ua_log_stdout.h>
  6. #include <signal.h>
  7. /* Files example_namespace.h and example_namespace.c are created from server_nodeset.xml in the
  8. * /src_generated directory by CMake */
  9. #include "ua_namespace_example.h"
  10. #include "example_nodeids.h"
  11. UA_Boolean running = true;
  12. static void stopHandler(int sign) {
  13. UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "received ctrl-c");
  14. running = false;
  15. }
  16. int main(int argc, char** argv) {
  17. signal(SIGINT, stopHandler);
  18. signal(SIGTERM, stopHandler);
  19. UA_ServerConfig *config = UA_ServerConfig_new_default();
  20. UA_Server *server = UA_Server_new(config);
  21. UA_StatusCode retval;
  22. /* create nodes from nodeset */
  23. if(ua_namespace_example(server) != UA_STATUSCODE_GOOD) {
  24. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "Could not add the example nodeset. "
  25. "Check previous output for any error.");
  26. retval = UA_STATUSCODE_BADUNEXPECTEDERROR;
  27. } else {
  28. // Do some additional stuff with the nodes
  29. // this will just get the namespace index, since it is already added to the server
  30. UA_UInt16 nsIdx = UA_Server_addNamespace(server, "http://yourorganisation.org/test/");
  31. UA_NodeId testInstanceId = UA_NODEID_NUMERIC(nsIdx, UA_EXAMPLE_NSID_TESTINSTANCE);
  32. UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "The testInstance has ns=%d;id=%d",
  33. testInstanceId.namespaceIndex, testInstanceId.identifier.numeric);
  34. retval = UA_Server_run(server, &running);
  35. }
  36. UA_Server_delete(server);
  37. UA_ServerConfig_delete(config);
  38. return (int)retval;
  39. }