server_nodeset_powerlink.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. #ifdef UA_ENABLE_AMALGAMATION
  4. #include "open62541.h"
  5. #else
  6. #include "ua_server.h"
  7. #include "ua_log_stdout.h"
  8. #include "ua_config_default.h"
  9. #endif
  10. #include <signal.h>
  11. /* Files example_namespace.h and example_namespace.c are created from server_nodeset.xml in the
  12. * /src_generated directory by CMake */
  13. #include "ua_namespace_di.h"
  14. #include "ua_namespace_powerlink.h"
  15. UA_Boolean running = true;
  16. static void stopHandler(int sign) {
  17. UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "received ctrl-c");
  18. running = false;
  19. }
  20. int main(int argc, char** argv) {
  21. signal(SIGINT, stopHandler);
  22. signal(SIGTERM, stopHandler);
  23. UA_ServerConfig *config = UA_ServerConfig_new_default();
  24. UA_Server *server = UA_Server_new(config);
  25. /* create nodes from nodeset */
  26. UA_StatusCode retval = ua_namespace_di(server);
  27. if(retval != UA_STATUSCODE_GOOD) {
  28. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "Adding the DI namespace failed. Please check previous error output.");
  29. UA_Server_delete(server);
  30. UA_ServerConfig_delete(config);
  31. return (int)UA_STATUSCODE_BADUNEXPECTEDERROR;
  32. }
  33. retval |= ua_namespace_powerlink(server);
  34. if(retval != UA_STATUSCODE_GOOD) {
  35. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "Adding the Powerlink namespace failed. Please check previous error output.");
  36. UA_Server_delete(server);
  37. UA_ServerConfig_delete(config);
  38. return (int)UA_STATUSCODE_BADUNEXPECTEDERROR;
  39. }
  40. retval = UA_Server_run(server, &running);
  41. UA_Server_delete(server);
  42. UA_ServerConfig_delete(config);
  43. return (int)retval;
  44. }