server_nodeset.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 "open62541.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. UA_Boolean running = true;
  9. static void stopHandler(int sign) {
  10. UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "received ctrl-c");
  11. running = false;
  12. }
  13. int main(int argc, char** argv) {
  14. signal(SIGINT, stopHandler);
  15. signal(SIGTERM, stopHandler);
  16. UA_ServerConfig *config = UA_ServerConfig_new_default();
  17. UA_Server *server = UA_Server_new(config);
  18. /* create nodes from nodeset */
  19. if(example_nodeset(server) != UA_STATUSCODE_GOOD) {
  20. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "Namespace index for generated "
  21. "nodeset does not match. The call to the generated method has to be "
  22. "before any other namespace add calls.");
  23. UA_Server_delete(server);
  24. UA_ServerConfig_delete(config);
  25. return (int)UA_STATUSCODE_BADUNEXPECTEDERROR;
  26. }
  27. UA_StatusCode retval = UA_Server_run(server, &running);
  28. UA_Server_delete(server);
  29. UA_ServerConfig_delete(config);
  30. return (int)retval;
  31. }