/
driver.cpp
45 lines (36 loc) · 897 Bytes
/
driver.cpp
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
#include <driver.hpp>
namespace atm
{
// https://bugs.llvm.org/show_bug.cgi?id=23728
// clang-format off
driver::driver() {
m_interface.display_enter_card();
}
void driver::card_inserted(const std::string& account) {
m_account = account;
m_machine.handle(c_event_insert(), *this);
}
void driver::digit_pressed(char digit) {
m_pass << digit;
m_machine.handle(c_event_digit(), *this);
}
void driver::balance_pressed() {
m_machine.handle(c_event_balance(), *this);
}
void driver::withdraw_pressed(unsigned amount) {
m_amount = amount;
m_machine.handle(c_event_withdraw(), *this);
}
void driver::cancel_pressed() {
auto m1 = m_interface.display_cancelled();
m1.wait();
auto m2 = m_interface.eject_card();
m_amount = 0;
m_pass.str("");
m_account.clear();
m_machine.reset();
m2.wait();
m_interface.display_enter_card();
}
// clang-format on
} // namespace atm