iFun Engine API  1.0.0-b6053
Great Technology for Great Games
timer.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2020 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 FUNAPI_DLL_VISIBILITY extern const EventTag kTimerEventTag;
25 
26 
28 class FUNAPI_DLL_VISIBILITY 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_
ArgumentMap class manages application-specific run-time arguments.
Definition: argument_map.h:23
Timer singleton.
Definition: timer.h:28
Base class for any service in Funapi.
Definition: component.h:20
static const Id kInvalidTimerId
invalid timer id.
Definition: timer.h:76
Definition: json.h:18
function< void(const Id &, const WallClock::Value &)> Handler
Handler that is called when a timer gets fired.
Definition: timer.h:34
Uuid EventTag
Event Tag.
Definition: event.h:30
uint64_t Id
Id to identify timers.
Definition: timer.h:31