Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
FakeClock.hxx
Go to the documentation of this file.
1
36#ifndef _OS_FAKECLOCK_HXX_
37#define _OS_FAKECLOCK_HXX_
38
39#include "executor/Executor.hxx"
40#include "os/os.h"
41#include "utils/Singleton.hxx"
42
45{
46protected:
48 FakeClockContent(long long t)
49 : lastTime_(t)
50 {
51 }
52
53 long long lastTime_;
54};
55
62class FakeClock : private FakeClockContent, public Singleton<FakeClock>
63{
64public:
65 FakeClock()
67 {
68 }
69
72 void advance(long long nsec)
73 {
74 lastTime_ += nsec;
75 // Wakes up all executors. This will cause them to evaluate if their
76 // timers have something expired.
78 while (current)
79 {
80 current->add(new CallbackExecutable([]() {}));
81 current = current->link_next();
82 }
83 }
84
86 long long get_time_nsec()
87 {
88 return lastTime_++;
89 }
90
91private:
92};
93
94#endif // _OS_FAKECLOCK_HXX_
A notifiable class that calls a particular function object once when it is invoked,...
This class implements an execution of tasks pulled off an input queue.
Definition Executor.hxx:64
virtual void add(Executable *action, unsigned priority=UINT_MAX)=0
Send a message to this Executor's queue.
Class that injects a fake progression of time for unit tests.
Definition FakeClock.hxx:63
long long get_time_nsec()
Definition FakeClock.hxx:86
void advance(long long nsec)
Advances the time returned by os_get_time_monotonic().
Definition FakeClock.hxx:72
static ExecutorBase * link_head()
Singleton class.
Definition Singleton.hxx:65
long long os_get_time_monotonic(void)
Get the monotonic time since the system started.
Definition os.c:571
Stores the private variables of a fake clock.
Definition FakeClock.hxx:45
FakeClockContent(long long t)
Definition FakeClock.hxx:48