server_nodeset.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  3. * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
  4. */
  5. #include <signal.h>
  6. #include <stdlib.h>
  7. #ifdef UA_NO_AMALGAMATION
  8. # include "ua_types.h"
  9. # include "ua_server.h"
  10. # include "logger_stdout.h"
  11. # include "networklayer_tcp.h"
  12. #else
  13. # include "open62541.h"
  14. #endif
  15. /* files nodeset.h and nodeset.c are created from server_nodeset.xml in the /src_generated directory by CMake */
  16. #include "nodeset.h"
  17. UA_Boolean running = UA_TRUE;
  18. UA_Logger logger;
  19. static void stopHandler(int sign) {
  20. UA_LOG_INFO(logger, UA_LOGCATEGORY_SERVER, "received ctrl-c");
  21. running = 0;
  22. }
  23. int main(int argc, char** argv) {
  24. signal(SIGINT, stopHandler); /* catches ctrl-c */
  25. /* initialize the server */
  26. UA_Server *server = UA_Server_new(UA_ServerConfig_standard);
  27. logger = Logger_Stdout_new();
  28. UA_Server_setLogger(server, logger);
  29. UA_Server_addNetworkLayer(server, ServerNetworkLayerTCP_new(UA_ConnectionConfig_standard, 16664));
  30. /* create nodes from nodeset */
  31. nodeset(server);
  32. /* start server */
  33. UA_StatusCode retval = UA_Server_run(server, 1, &running); //blocks until running=false
  34. /* ctrl-c received -> clean up */
  35. UA_Server_delete(server);
  36. return retval;
  37. }