server_nodeset.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. if (nodeset(server) != UA_STATUSCODE_GOOD) {
  32. UA_LOG_ERROR(logger, UA_LOGCATEGORY_SERVER, "Namespace index for generated nodeset does not match. The call to the generated method has to be before any other namespace add calls.");
  33. UA_Server_delete(server);
  34. nl.deleteMembers(&nl);
  35. return (int)UA_STATUSCODE_BADUNEXPECTEDERROR;
  36. }
  37. /* start server */
  38. UA_StatusCode retval = UA_Server_run(server, &running); //UA_blocks until running=false
  39. /* ctrl-c received -> clean up */
  40. UA_Server_delete(server);
  41. nl.deleteMembers(&nl);
  42. return (int)retval;
  43. }