server_testnodeset.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. */
  4. #include <ua_client_highlevel.h>
  5. #include <ua_config_default.h>
  6. #include <ua_log_stdout.h>
  7. #include <ua_server.h>
  8. #include <signal.h>
  9. #include <stdlib.h>
  10. #include "ua_namespace_testnodeset.h"
  11. UA_Boolean running = true;
  12. UA_DataTypeArray customTypesArray = { NULL, UA_TYPES_TESTNODESET_COUNT, UA_TYPES_TESTNODESET};
  13. static void stopHandler(int sign)
  14. {
  15. UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "received ctrl-c");
  16. running = false;
  17. }
  18. int main(int argc, char **argv)
  19. {
  20. signal(SIGINT, stopHandler);
  21. signal(SIGTERM, stopHandler);
  22. UA_ServerConfig *config = UA_ServerConfig_new_default();
  23. config->customDataTypes = &customTypesArray;
  24. UA_Server *server = UA_Server_new(config);
  25. UA_StatusCode retval;
  26. /* create nodes from nodeset */
  27. if (ua_namespace_testnodeset(server) != UA_STATUSCODE_GOOD)
  28. {
  29. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
  30. "Could not add the example nodeset. "
  31. "Check previous output for any error.");
  32. retval = UA_STATUSCODE_BADUNEXPECTEDERROR;
  33. }
  34. else
  35. {
  36. UA_Variant out;
  37. UA_Variant_init(&out);
  38. UA_Server_readValue(server, UA_NODEID_NUMERIC(2, 10002), &out);
  39. UA_Point *p = (UA_Point *)out.data;
  40. printf("point 2d x: %f y: %f \n", p->x, p->y);
  41. retval = UA_Server_run(server, &running);
  42. }
  43. UA_Server_delete(server);
  44. UA_ServerConfig_delete(config);
  45. return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
  46. }