server_testnodeset.c 1.7 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 <open62541/client_config_default.h>
  5. #include <open62541/client_highlevel.h>
  6. #include <open62541/plugin/log_stdout.h>
  7. #include <open62541/server.h>
  8. #include <open62541/server_config_default.h>
  9. #include "open62541/namespace_testnodeset_generated.h"
  10. #include <signal.h>
  11. #include <stdlib.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_Server *server = UA_Server_new();
  23. UA_ServerConfig *config = UA_Server_getConfig(server);
  24. UA_ServerConfig_setDefault(config);
  25. config->customDataTypes = &customTypesArray;
  26. UA_StatusCode retval;
  27. /* create nodes from nodeset */
  28. if(namespace_testnodeset_generated(server) != UA_STATUSCODE_GOOD) {
  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. } else {
  34. UA_Variant out;
  35. UA_Variant_init(&out);
  36. UA_Server_readValue(server, UA_NODEID_NUMERIC(2, 10002), &out);
  37. UA_Point *p = (UA_Point *)out.data;
  38. printf("point 2d x: %f y: %f \n", p->x, p->y);
  39. retval = UA_Server_run(server, &running);
  40. }
  41. UA_Server_delete(server);
  42. return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
  43. }