server_nodeset.c 1.7 KB

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