server_nodeset_powerlink.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 <open62541/plugin/log_stdout.h>
  7. #include <open62541/server.h>
  8. #include <open62541/server_config_default.h>
  9. #endif
  10. #include "open62541/namespace_di_generated.h"
  11. #include "open62541/namespace_powerlink_generated.h"
  12. #include <signal.h>
  13. #include <stdlib.h>
  14. UA_Boolean running = true;
  15. static void stopHandler(int sign) {
  16. UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "received ctrl-c");
  17. running = false;
  18. }
  19. int main(int argc, char** argv) {
  20. signal(SIGINT, stopHandler);
  21. signal(SIGTERM, stopHandler);
  22. UA_ServerConfig *config = UA_ServerConfig_new_default();
  23. UA_Server *server = UA_Server_new(config);
  24. /* create nodes from nodeset */
  25. UA_StatusCode retval = namespace_di_generated(server);
  26. if(retval != UA_STATUSCODE_GOOD) {
  27. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "Adding the DI namespace failed. Please check previous error output.");
  28. UA_Server_delete(server);
  29. UA_ServerConfig_delete(config);
  30. return EXIT_FAILURE;
  31. }
  32. retval |= namespace_powerlink_generated(server);
  33. if(retval != UA_STATUSCODE_GOOD) {
  34. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "Adding the Powerlink namespace failed. Please check previous error output.");
  35. UA_Server_delete(server);
  36. UA_ServerConfig_delete(config);
  37. return EXIT_FAILURE;
  38. }
  39. retval = UA_Server_run(server, &running);
  40. UA_Server_delete(server);
  41. UA_ServerConfig_delete(config);
  42. return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
  43. }