server_nodeset.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 <signal.h>
  4. #include <stdlib.h>
  5. #include "ua_server.h"
  6. #include "ua_log_stdout.h"
  7. #include "ua_config_standard.h"
  8. #include "ua_network_tcp.h"
  9. /* Files nodeset.h and nodeset.c are created from server_nodeset.xml in the
  10. * /src_generated directory by CMake */
  11. #include "nodeset.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. /* initialize the server */
  21. UA_ServerConfig *config = UA_ServerConfig_new_default();
  22. UA_Server *server = UA_Server_new(config);
  23. /* create nodes from nodeset */
  24. if(nodeset(server) != UA_STATUSCODE_GOOD) {
  25. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "Namespace index for generated "
  26. "nodeset does not match. The call to the generated method has to be "
  27. "before any other namespace add calls.");
  28. UA_Server_delete(server);
  29. UA_ServerConfig_delete(config);
  30. return UA_STATUSCODE_BADUNEXPECTEDERROR;
  31. }
  32. UA_StatusCode retval = UA_Server_run(server, &running);
  33. UA_Server_delete(server);
  34. UA_ServerConfig_delete(config);
  35. return (int)retval;
  36. }