-
Notifications
You must be signed in to change notification settings - Fork 0
/
bankMachine.ixx
83 lines (83 loc) · 1.86 KB
/
bankMachine.ixx
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
module;
export module bankMachine;
import receiver;
import dispatcher;
import withdraw;
import sender;
using namespace messaging;
export namespace messaging
{
class bank_machine
{
receiver incoming;
unsigned balance;
public:
bank_machine() :
balance(199)
{}
void done()
{
get_sender().send(close_queue());
}
void run()
{
try
{
for (;;)
{
incoming.wait()
.handle<verify_pin>(
[&](verify_pin const& msg)
{
if (msg.pin == "1937")
{
msg.atm_queue.send(pin_verified());
}
else
{
msg.atm_queue.send(pin_incorrect());
}
}
)
.handle<withdraw>(
[&](withdraw const& msg)
{
if (balance >= msg.amount)
{
msg.atm_queue.send(withdraw_ok());
balance -= msg.amount;
}
else
{
msg.atm_queue.send(withdraw_denied());
}
}
)
.handle<get_balance>(
[&](get_balance const& msg)
{
msg.atm_queue.send(::balance(balance));
}
)
.handle<withdrawal_processed>(
[&](withdrawal_processed const& msg)
{
}
)
.handle<cancel_withdrawal>(
[&](cancel_withdrawal const& msg)
{
}
);
}
}
catch (messaging::close_queue const&)
{
}
}
sender get_sender()
{
return incoming;
}
};
}