idle_timeout.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #pragma once
  2. #include <inttypes.h>
  3. #include <stdbool.h>
  4. typedef struct IdleTimeoutContext IdleTimeoutContext;
  5. typedef bool (*IDLE_TIMEOUT_CALLBACK)(void* context);
  6. /**
  7. * @brief Initializes a new instance of IDLE timeout
  8. * @param timeout_sec IDLE timeout in seconds
  9. * @param on_idle_callback callback function to trigger when IDLE timeout happened
  10. * @param on_idle_callback_context callback function context
  11. * @return IDLE timeout context
  12. */
  13. IdleTimeoutContext* idle_timeout_alloc(
  14. uint16_t timeout_sec,
  15. IDLE_TIMEOUT_CALLBACK on_idle_callback,
  16. void* on_idle_callback_context);
  17. /**
  18. * @brief Starts IDLE timeout
  19. * @param context IDLE timeout context
  20. */
  21. void idle_timeout_start(IdleTimeoutContext* context);
  22. /**
  23. * @brief Stops IDLE timeout
  24. * @param context IDLE timeout context
  25. */
  26. void idle_timeout_stop(IdleTimeoutContext* context);
  27. /**
  28. * @brief Pauses IDLE timeout
  29. * @param context IDLE timeout context
  30. */
  31. void idle_timeout_pause(IdleTimeoutContext* context);
  32. /**
  33. * @brief Resumes paused IDLE timeout
  34. * @param context IDLE timeout context
  35. */
  36. void idle_timeout_resume(IdleTimeoutContext* context);
  37. /**
  38. * @brief Reports activity to IDLE timeout
  39. * @param context IDLE timeout context
  40. */
  41. void idle_timeout_report_activity(IdleTimeoutContext* context);
  42. /**
  43. * @brief Disposes IDLE timeout and releases all the resources
  44. * @param context IDLE timeout context
  45. */
  46. void idle_timeout_free(IdleTimeoutContext* context);