server_repeated_job.c 1.0 KB

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