14
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
* Authored by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
17
* Alberto Aguirre <alberto.aguirre@canonical.com>
20
#ifndef MIR_TIME_TIMER_H_
21
#define MIR_TIME_TIMER_H_
21
#ifndef MIR_TIME_ALARM_FACTORY_H_
22
#define MIR_TIME_ALARM_FACTORY_H_
23
24
#include "mir/time/alarm.h"
32
class LockableCallback;
40
virtual ~Timer() = default;
42
* \brief Create an Alarm that calls the callback after the specified delay
44
* \param delay Time from now, in milliseconds, that the callback will fire
45
* \param callback Function to call when the Alarm signals
47
* \return A handle to an Alarm that will fire after delay ms.
49
virtual std::unique_ptr<Alarm> notify_in(std::chrono::milliseconds delay,
50
std::function<void()> callback) = 0;
52
* \brief Create an Alarm that calls the callback at the specified time
54
* \param time_point Time point when the alarm should be triggered
55
* \param callback Function to call when the Alarm signals
57
* \return A handle to an Alarm that will fire after delay ms.
59
virtual std::unique_ptr<Alarm> notify_at(Timestamp time_point,
60
std::function<void()> callback) = 0;
62
* \brief Create an Alarm that will not fire until scheduled
64
* \param callback Function to call when the Alarm signals
66
* \return A handle to an Alarm that can later be scheduled
68
virtual std::unique_ptr<Alarm> create_alarm(std::function<void()> callback) = 0;
70
Timer(Timer const&) = delete;
71
Timer& operator=(Timer const&) = delete;
41
virtual ~AlarmFactory() = default;
43
* \brief Create an Alarm that will not fire until scheduled
45
* \param callback Function to call when the Alarm signals
47
* \return A handle to an Alarm that can later be scheduled
49
virtual std::unique_ptr<Alarm> create_alarm(std::function<void()> const& callback) = 0;
52
* \brief Create an Alarm that will not fire until scheduled
54
* A LockableCallback allows the user to preserve lock ordering
55
* in situations where Alarm methods need to be called under external lock
56
* and the callback implementation needs to run code protected by the same
57
* lock. An alarm implementation may have internal locks of its own, which
58
* maybe acquired during callback dispatching; to preserve lock ordering
59
* LockableCallback::lock is invoked during callback dispatch before
60
* any internal locks are acquired.
62
* \param callback Function to call when the Alarm signals
63
* \return A handle to an Alarm that can later be scheduled
65
virtual std::unique_ptr<Alarm> create_alarm(std::shared_ptr<LockableCallback> const& callback) = 0;
68
AlarmFactory() = default;
69
AlarmFactory(AlarmFactory const&) = delete;
70
AlarmFactory& operator=(AlarmFactory const&) = delete;
77
#endif // MIR_TIME_TIMER_H_
76
#endif // MIR_TIME_ALARM_FACTORY_H_