~alan-griffiths/mir/fix-1654023

« back to all changes in this revision

Viewing changes to include/server/mir/time/alarm_factory.h

  • Committer: Daniel van Vugt
  • Date: 2015-04-28 07:54:10 UTC
  • mfrom: (2517 development-branch)
  • mto: This revision was merged to the branch mainline in revision 2673.
  • Revision ID: daniel.van.vugt@canonical.com-20150428075410-rwskshfuar7voesp
Merge latest trunk and fix conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright © 2014 Canonical Ltd.
 
2
 * Copyright © 2014-2015 Canonical Ltd.
3
3
 *
4
4
 * This program is free software: you can redistribute it and/or modify it
5
5
 * under the terms of the GNU General Public License version 3,
14
14
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15
15
 *
16
16
 * Authored by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
 
17
 *              Alberto Aguirre <alberto.aguirre@canonical.com>
17
18
 */
18
19
 
19
20
 
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_
22
23
 
23
24
#include "mir/time/alarm.h"
24
25
 
28
29
 
29
30
namespace mir
30
31
{
 
32
class LockableCallback;
 
33
 
31
34
namespace time
32
35
{
33
36
 
34
37
class Alarm;
35
 
 
36
 
class Timer
 
38
class AlarmFactory
37
39
{
38
40
public:
39
 
    Timer() = default;
40
 
    virtual ~Timer() = default;
41
 
    /**
42
 
     * \brief Create an Alarm that calls the callback after the specified delay
43
 
     *
44
 
     * \param delay     Time from now, in milliseconds, that the callback will fire
45
 
     * \param callback  Function to call when the Alarm signals
46
 
     *
47
 
     * \return A handle to an Alarm that will fire after delay ms.
48
 
     */
49
 
    virtual std::unique_ptr<Alarm> notify_in(std::chrono::milliseconds delay,
50
 
                                             std::function<void()> callback) = 0;
51
 
    /**
52
 
     * \brief Create an Alarm that calls the callback at the specified time
53
 
     *
54
 
     * \param time_point Time point when the alarm should be triggered
55
 
     * \param callback  Function to call when the Alarm signals
56
 
     *
57
 
     * \return A handle to an Alarm that will fire after delay ms.
58
 
     */
59
 
    virtual std::unique_ptr<Alarm> notify_at(Timestamp time_point,
60
 
                                             std::function<void()> callback) = 0;
61
 
    /**
62
 
     * \brief Create an Alarm that will not fire until scheduled
63
 
     *
64
 
     * \param callback  Function to call when the Alarm signals
65
 
     *
66
 
     * \return A handle to an Alarm that can later be scheduled
67
 
     */
68
 
    virtual std::unique_ptr<Alarm> create_alarm(std::function<void()> callback) = 0;
69
 
 
70
 
    Timer(Timer const&) = delete;
71
 
    Timer& operator=(Timer const&) = delete;
 
41
    virtual ~AlarmFactory() = default;
 
42
    /**
 
43
     * \brief Create an Alarm that will not fire until scheduled
 
44
     *
 
45
     * \param callback  Function to call when the Alarm signals
 
46
     *
 
47
     * \return A handle to an Alarm that can later be scheduled
 
48
     */
 
49
    virtual std::unique_ptr<Alarm> create_alarm(std::function<void()> const& callback) = 0;
 
50
 
 
51
    /**
 
52
     * \brief Create an Alarm that will not fire until scheduled
 
53
     *
 
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.
 
61
     *
 
62
     * \param callback Function to call when the Alarm signals
 
63
     * \return A handle to an Alarm that can later be scheduled
 
64
     */
 
65
    virtual std::unique_ptr<Alarm> create_alarm(std::shared_ptr<LockableCallback> const& callback) = 0;
 
66
 
 
67
protected:
 
68
    AlarmFactory() = default;
 
69
    AlarmFactory(AlarmFactory const&) = delete;
 
70
    AlarmFactory& operator=(AlarmFactory const&) = delete;
72
71
};
73
72
 
74
73
}
75
74
}
76
75
 
77
 
#endif // MIR_TIME_TIMER_H_
 
76
#endif // MIR_TIME_ALARM_FACTORY_H_