server_nodeset.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 = Logger_Stdout;
  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. UA_Server_setLogger(server, logger);
  28. UA_Server_addNetworkLayer(server, ServerNetworkLayerTCP_new(UA_ConnectionConfig_standard, 16664));
  29. /* create nodes from nodeset */
  30. nodeset(server);
  31. /* start server */
  32. UA_StatusCode retval = UA_Server_run(server, 1, &running); //blocks until running=false
  33. /* ctrl-c received -> clean up */
  34. UA_Server_delete(server);
  35. return retval;
  36. }