iFun Engine API  1.0.0-b2936
Great Technology for Great Games
 All Classes Files Functions Variables Typedefs Macros
timer.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2015 iFunFactory Inc. All Rights Reserved.
2 //
3 // This work is confidential and proprietary to iFunFactory Inc. and
4 // must not be used, disclosed, copied, or distributed without the prior
5 // consent of iFunFactory Inc.
6 
9 #ifndef INCLUDE_FUNAPI_TIME_TIMER_H_
10 #define INCLUDE_FUNAPI_TIME_TIMER_H_
11 
12 #include <boost/function.hpp>
13 #include <boost/thread/thread_time.hpp>
14 #include <boost/utility.hpp>
16 #include <funapi/system/event.h>
17 #include <funapi/time/wall_clock.h>
18 #include <funapi/types.h>
19 
20 
21 namespace fun {
22 
23 
24 extern const EventTag kTimerEventTag;
25 
26 
28 class Timer : public Component {
29  public:
31  typedef uint64_t Id;
32 
34  typedef function<void (const Id &, const WallClock::Value &)> Handler;
35 
37  static bool Install(const fun::ArgumentMap &arguments);
38  static bool Uninstall();
39 
45  static Id ExpireAt(
46  const WallClock::Value &abs_time,
47  const Handler &handler,
48  const EventTag &tag = kTimerEventTag) ASSERT_NO_ROLLBACK;
49 
55  static Id ExpireAfter(
56  const WallClock::Duration &rel_time,
57  const Handler &handler,
58  const EventTag &tag = kTimerEventTag) ASSERT_NO_ROLLBACK;
59 
65  static Id ExpireRepeatedly(
66  const WallClock::Duration &interval,
67  const Handler &handler,
68  const EventTag &tag = kTimerEventTag) ASSERT_NO_ROLLBACK;
69 
73  static void Cancel(const Id &timer_id) ASSERT_NO_ROLLBACK;
74 
76  static const Id kInvalidTimerId;
77 };
78 
79 } // namespace fun
80 
81 #endif // INCLUDE_FUNAPI_TIME_TIMER_H_
Clock roughly representing wall clock.
Definition: wall_clock.h:27
ArgumentMap class manages application-specific run-time arguments.
Definition: argument_map.h:23
Timer singleton.
Definition: timer.h:28
static Id ExpireRepeatedly(const WallClock::Duration &interval, const Handler &handler, const EventTag &tag=kTimerEventTag) ASSERT_NO_ROLLBACK
Sets a timer that will be fired repeatedly.
Base class for any service in Funapi.
Definition: component.h:19
static const Id kInvalidTimerId
invalid timer id.
Definition: timer.h:76
static Id ExpireAfter(const WallClock::Duration &rel_time, const Handler &handler, const EventTag &tag=kTimerEventTag) ASSERT_NO_ROLLBACK
Sets a timer that will be fired in relative time T.
static void Cancel(const Id &timer_id) ASSERT_NO_ROLLBACK
Cancel the given timer.
static Id ExpireAt(const WallClock::Value &abs_time, const Handler &handler, const EventTag &tag=kTimerEventTag) ASSERT_NO_ROLLBACK
Sets a timer that will be fired at an absolute time T.
function< void(const Id &, const WallClock::Value &)> Handler
Handler that is called when a timer gets fired.
Definition: timer.h:34
static bool Install(const fun::ArgumentMap &arguments)
Called by the Funapi framework.
uint64_t Id
Id to identify timers.
Definition: timer.h:31