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 <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 callback to the server */
  24. UA_Server_addRepeatedCallback(server, testCallback, NULL, 2000, NULL); /* call every 2 sec */
  25. UA_Server_run(server, &running);
  26. UA_Server_delete(server);
  27. nl.deleteMembers(&nl);
  28. return 0;
  29. }