-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrtc_mock.cpp
More file actions
53 lines (46 loc) · 1.45 KB
/
rtc_mock.cpp
File metadata and controls
53 lines (46 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "irtc.hpp"
#include <map>
#include <string>
#include <utility>
namespace {
struct MockRTCImpl : MockRTC {
MockRTCImpl(std::string_view adj) : m_clock(IRTC::parse_adjfile(adj)) {}
rtc_time get_time() const override { return m_tm; }
void set_wakeup(rtc_time const &time) override {
// TODO check time for past
m_wakeup.time = time;
m_wakeup.enabled = 1;
m_wakeup.pending = 0;
}
rtc_wkalrm get_wakeup() const override { return m_wakeup; }
void clear_wakeup() override {}
Clock type() const noexcept override { return m_clock; }
void set_time(rtc_time const &time) override { m_tm = time; }
void wakeup_occured() override {
if (!m_wakeup.enabled) {
throw std::logic_error("rtc wakeup was not armed");
}
m_wakeup.pending = 1;
}
std::string_view name() const noexcept override { return "mock"; }
bool notify_listener(IntegrationInfo const &) const noexcept final {
// nothing to do here;
return true;
}
bool unnotify_listener(IntegrationInfo const &) const noexcept final {
// no thing to do here;
return true;
}
private:
rtc_time m_tm{};
rtc_wkalrm m_wakeup{};
Clock m_clock{};
};
} // namespace
std::unique_ptr<MockRTC> MockRTC::get(std::string_view name,
std::string_view adj) {
return std::make_unique<MockRTCImpl>(adj);
}
std::unique_ptr<IRTC> IRTC::get(std::string_view name, std::string_view adj) {
return std::make_unique<MockRTCImpl>(adj);
}