server_nodeset.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. #include "open62541.h"
  6. /* Files nodeset.h and nodeset.c are created from server_nodeset.xml in the
  7. * /src_generated directory by CMake */
  8. #include "nodeset.h"
  9. UA_Boolean running = true;
  10. static void stopHandler(int sign) {
  11. UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "received ctrl-c");
  12. running = false;
  13. }
  14. int main(int argc, char** argv) {
  15. signal(SIGINT, stopHandler); /* catches ctrl-c */
  16. /* initialize the server */
  17. UA_ServerConfig config = UA_ServerConfig_standard;
  18. UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664);
  19. config.networkLayers = &nl;
  20. config.networkLayersSize = 1;
  21. UA_Server *server = UA_Server_new(config);
  22. /* create nodes from nodeset */
  23. if (nodeset(server) != UA_STATUSCODE_GOOD) {
  24. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "Namespace index for generated "
  25. "nodeset does not match. The call to the generated method has to be "
  26. "before any other namespace add calls.");
  27. UA_Server_delete(server);
  28. nl.deleteMembers(&nl);
  29. return (int)UA_STATUSCODE_BADUNEXPECTEDERROR;
  30. }
  31. /* start server */
  32. UA_StatusCode retval = UA_Server_run(server, &running);
  33. /* ctrl-c received -> clean up */
  34. UA_Server_delete(server);
  35. nl.deleteMembers(&nl);
  36. return (int)retval;
  37. }