server_repeated_job.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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_standard;
  18. UA_ServerNetworkLayer nl =
  19. UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664);
  20. config.networkLayers = &nl;
  21. config.networkLayersSize = 1;
  22. UA_Server *server = UA_Server_new(config);
  23. /* add a repeated job to the server */
  24. UA_Job job;
  25. job.type = UA_JOBTYPE_METHODCALL;
  26. job.job.methodCall.data = NULL;
  27. job.job.methodCall.method = testCallback;
  28. UA_Server_addRepeatedJob(server, job, 2000, NULL); /* call every 2 sec */
  29. UA_Server_run(server, &running);
  30. UA_Server_delete(server);
  31. nl.deleteMembers(&nl);
  32. return 0;
  33. }