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
44
struct
FakeClockContent
45
{
46
protected
:
48
FakeClockContent
(
long
long
t)
49
: lastTime_(t)
50
{
51
}
52
53
long
long
lastTime_;
54
};
55
62
class
FakeClock
:
private
FakeClockContent
,
public
Singleton
<FakeClock>
63
{
64
public
:
65
FakeClock
()
66
:
FakeClockContent
(
os_get_time_monotonic
())
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.
77
ExecutorBase
*current =
ExecutorBase::link_head
();
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
91
private
:
92
};
93
94
#endif
// _OS_FAKECLOCK_HXX_
Executor.hxx
Singleton.hxx
CallbackExecutable
A notifiable class that calls a particular function object once when it is invoked,...
Definition
Executable.hxx:72
ExecutorBase
This class implements an execution of tasks pulled off an input queue.
Definition
Executor.hxx:64
ExecutorBase::add
virtual void add(Executable *action, unsigned priority=UINT_MAX)=0
Send a message to this Executor's queue.
FakeClock
Class that injects a fake progression of time for unit tests.
Definition
FakeClock.hxx:63
FakeClock::get_time_nsec
long long get_time_nsec()
Definition
FakeClock.hxx:86
FakeClock::advance
void advance(long long nsec)
Advances the time returned by os_get_time_monotonic().
Definition
FakeClock.hxx:72
LinkedObject::link_next
T * link_next()
Definition
LinkedObject.hxx:88
LinkedObject< ExecutorBase >::link_head
static ExecutorBase * link_head()
Definition
LinkedObject.hxx:94
Singleton
Singleton class.
Definition
Singleton.hxx:65
os_get_time_monotonic
long long os_get_time_monotonic(void)
Get the monotonic time since the system started.
Definition
os.c:571
os.h
FakeClockContent
Stores the private variables of a fake clock.
Definition
FakeClock.hxx:45
FakeClockContent::FakeClockContent
FakeClockContent(long long t)
Definition
FakeClock.hxx:48
src
os
FakeClock.hxx
Generated on Sun Feb 2 2025 21:18:14 for Open Model Railroad Network (OpenMRN) by
1.9.8