server_repeated_job.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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 <ua_server.h>
  4. #include <ua_config_default.h>
  5. #include <ua_log_stdout.h>
  6. #include <signal.h>
  7. #include <stdlib.h>
  8. static void
  9. testCallback(UA_Server *server, void *data) {
  10. UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "testcallback");
  11. }
  12. UA_Boolean running = true;
  13. static void stopHandler(int sign) {
  14. UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "received ctrl-c");
  15. running = false;
  16. }
  17. int main(void) {
  18. signal(SIGINT, stopHandler);
  19. signal(SIGTERM, stopHandler);
  20. UA_ServerConfig *config = UA_ServerConfig_new_default();
  21. UA_Server *server = UA_Server_new(config);
  22. /* Add a repeated callback to the server */
  23. UA_Server_addRepeatedCallback(server, testCallback, NULL, 2000, NULL); /* call every 2 sec */
  24. UA_StatusCode retval = UA_Server_run(server, &running);
  25. UA_Server_delete(server);
  26. UA_ServerConfig_delete(config);
  27. return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
  28. }