/** * @file Timer.h * @author apio (cloudapio.eu) * @brief Millisecond-precision timer. * * @copyright Copyright (c) 2024, the Luna authors. * */ #pragma once #include #include #include #include namespace os { class EventLoop; class Timer : LinkedListNode { public: static Result> create_singleshot(unsigned int milliseconds, Action&& action); static Result> create_repeating(unsigned int milliseconds, Action&& action); void restart(); void reset(unsigned int milliseconds); void stop(); ~Timer(); private: timer_t m_timerid { -1 }; bool m_repeating; bool m_stopped { false }; struct timespec m_interval; Action m_action; void check_if_should_invoke_action(); void readd_if_necessary(); Timer() = default; friend class EventLoop; }; }