server_repeated_job.c 995 B

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