server_nodeset.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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_Logger logger = Logger_Stdout;
  18. UA_Boolean running = true;
  19. static void stopHandler(int sign) {
  20. UA_LOG_INFO(logger, UA_LOGCATEGORY_SERVER, "received ctrl-c");
  21. running = false;
  22. }
  23. int main(int argc, char** argv) {
  24. signal(SIGINT, stopHandler); /* catches ctrl-c */
  25. /* initialize the server */
  26. UA_ServerConfig config = UA_ServerConfig_standard;
  27. UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664);
  28. config.logger = Logger_Stdout;
  29. config.networkLayers = &nl;
  30. config.networkLayersSize = 1;
  31. UA_Server *server = UA_Server_new(config);
  32. /* create nodes from nodeset */
  33. nodeset(server);
  34. /* start server */
  35. UA_StatusCode retval = UA_Server_run(server, &running); //UA_blocks until running=false
  36. /* ctrl-c received -> clean up */
  37. UA_Server_delete(server);
  38. nl.deleteMembers(&nl);
  39. return (int)retval;
  40. }