server_testnodeset.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 <open62541/server.h>
  5. #include <open62541/server_config_default.h>
  6. #include <open62541/client_highlevel.h>
  7. #include <open62541/client_config_default.h>
  8. #include <open62541/plugin/log_stdout.h>
  9. #include <signal.h>
  10. #include <stdlib.h>
  11. #include "open62541/ua_namespace_testnodeset.h"
  12. UA_Boolean running = true;
  13. UA_DataTypeArray customTypesArray = { NULL, UA_TYPES_TESTNODESET_COUNT, UA_TYPES_TESTNODESET};
  14. static void stopHandler(int sign) {
  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. 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. } else {
  33. UA_Variant out;
  34. UA_Variant_init(&out);
  35. UA_Server_readValue(server, UA_NODEID_NUMERIC(2, 10002), &out);
  36. UA_Point *p = (UA_Point *)out.data;
  37. printf("point 2d x: %f y: %f \n", p->x, p->y);
  38. retval = UA_Server_run(server, &running);
  39. }
  40. UA_Server_delete(server);
  41. UA_ServerConfig_delete(config);
  42. return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
  43. }