server_nodeset.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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/server.h>
  4. #include <open62541/server_config_default.h>
  5. #include <open62541/plugin/log_stdout.h>
  6. #include <signal.h>
  7. #include <stdlib.h>
  8. /* Files example_namespace.h and example_namespace.c are created from server_nodeset.xml in the
  9. * /src_generated directory by CMake */
  10. #include "open62541/ua_namespace_example.h"
  11. #include "open62541/example_nodeids.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_ServerConfig *config = UA_ServerConfig_new_default();
  21. UA_Server *server = UA_Server_new(config);
  22. UA_StatusCode retval;
  23. /* create nodes from nodeset */
  24. if(ua_namespace_example(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. UA_ServerConfig_delete(config);
  39. return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
  40. }