server_nodeset.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 <stdlib.h>
  5. #ifdef UA_NO_AMALGAMATION
  6. # include "ua_types.h"
  7. # include "ua_server.h"
  8. # include "ua_config_standard.h"
  9. # include "ua_network_tcp.h"
  10. # include "ua_log_stdout.h"
  11. #else
  12. # include "open62541.h"
  13. #endif
  14. /* files nodeset.h and nodeset.c are created from server_nodeset.xml in the /src_generated directory by CMake */
  15. #include "nodeset.h"
  16. UA_Logger logger = UA_Log_Stdout;
  17. UA_Boolean running = true;
  18. static void stopHandler(int sign) {
  19. UA_LOG_INFO(logger, UA_LOGCATEGORY_SERVER, "received ctrl-c");
  20. running = false;
  21. }
  22. int main(int argc, char** argv) {
  23. signal(SIGINT, stopHandler); /* catches ctrl-c */
  24. /* initialize the server */
  25. UA_ServerConfig config = UA_ServerConfig_standard;
  26. UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664);
  27. config.networkLayers = &nl;
  28. config.networkLayersSize = 1;
  29. UA_Server *server = UA_Server_new(config);
  30. /* create nodes from nodeset */
  31. nodeset(server);
  32. /* start server */
  33. UA_StatusCode retval = UA_Server_run(server, &running); //UA_blocks until running=false
  34. /* ctrl-c received -> clean up */
  35. UA_Server_delete(server);
  36. nl.deleteMembers(&nl);
  37. return (int)retval;
  38. }