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