ua_timer.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. *
  5. * Copyright 2017, 2018 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
  6. * Copyright 2017 (c) Stefan Profanter, fortiss GmbH
  7. */
  8. #ifndef UA_TIMER_H_
  9. #define UA_TIMER_H_
  10. #include "ua_util_internal.h"
  11. #include "ua_workqueue.h"
  12. #include "ziptree.h"
  13. _UA_BEGIN_DECLS
  14. struct UA_TimerEntry;
  15. typedef struct UA_TimerEntry UA_TimerEntry;
  16. ZIP_HEAD(UA_TimerZip, UA_TimerEntry);
  17. typedef struct UA_TimerZip UA_TimerZip;
  18. ZIP_HEAD(UA_TimerIdZip, UA_TimerEntry);
  19. typedef struct UA_TimerIdZip UA_TimerIdZip;
  20. /* Only for a single thread. Protect by a mutex if required. */
  21. typedef struct {
  22. UA_TimerZip root; /* The root of the time-sorted zip tree */
  23. UA_TimerIdZip idRoot; /* The root of the id-sorted zip tree */
  24. UA_UInt64 idCounter;
  25. } UA_Timer;
  26. void UA_Timer_init(UA_Timer *t);
  27. UA_StatusCode
  28. UA_Timer_addTimedCallback(UA_Timer *t, UA_ApplicationCallback callback,
  29. void *application, void *data, UA_DateTime date,
  30. UA_UInt64 *callbackId);
  31. UA_StatusCode
  32. UA_Timer_addRepeatedCallback(UA_Timer *t, UA_ApplicationCallback callback,
  33. void *application, void *data, UA_Double interval_ms,
  34. UA_UInt64 *callbackId);
  35. /* Change the callback interval. If this is called from within the callback. The
  36. * adjustment is made during the next _process call. */
  37. UA_StatusCode
  38. UA_Timer_changeRepeatedCallbackInterval(UA_Timer *t, UA_UInt64 callbackId,
  39. UA_Double interval_ms);
  40. void
  41. UA_Timer_removeCallback(UA_Timer *t, UA_UInt64 callbackId);
  42. /* Process (dispatch) the repeated callbacks that have timed out. Returns the
  43. * timestamp of the next scheduled repeated callback. Not thread-safe.
  44. * Application is a pointer to the client / server environment for the callback.
  45. * Dispatched is set to true when at least one callback was run / dispatched. */
  46. typedef void
  47. (*UA_TimerExecutionCallback)(void *executionApplication, UA_ApplicationCallback cb,
  48. void *callbackApplication, void *data);
  49. UA_DateTime
  50. UA_Timer_process(UA_Timer *t, UA_DateTime nowMonotonic,
  51. UA_TimerExecutionCallback executionCallback,
  52. void *executionApplication);
  53. void UA_Timer_deleteMembers(UA_Timer *t);
  54. _UA_END_DECLS
  55. #endif /* UA_TIMER_H_ */