-
Notifications
You must be signed in to change notification settings - Fork 0
/
interfaceMachine.ixx
134 lines (132 loc) · 4.21 KB
/
interfaceMachine.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
module;
export module interfaceMachine;
import <mutex>;
import <memory>;
import <string>;
import <iostream>;
//#include <folly/Format.h>
import receiver;
import withdraw;
import dispatcher;
import sender;
import TemplateDispatcher;
using namespace messaging;
export namespace messaging
{
struct interfaceMachine
{
std::mutex iom;
receiver incoming;
void done()
{
get_sender().send(messaging::close_queue());
}
void run()
{
try
{
for (;;)
{
incoming.wait()
.handle<issue_money>(
[&](issue_money const& msg)
{
{
std::lock_guard<std::mutex> lk(iom);
std::cout << "Issuing " << std::to_string(msg.amount) << "\r\n";
}
}
)
.handle<display_insufficient_funds>(
[&](display_insufficient_funds const& msg)
{
{
std::lock_guard<std::mutex> lk(iom);
std::cout << "Insufficient funds" << std::endl;
}
}
)
.handle<display_enter_pin>(
[&](display_enter_pin const& msg)
{
{
std::lock_guard<std::mutex> lk(iom);
std::cout
<< "Please enter your PIN (0-9)"
<< std::endl;
}
}
)
.handle<display_enter_card>(
[&](display_enter_card const& msg)
{
{
std::lock_guard<std::mutex> lk(iom);
std::cout << "Please enter your card (I)"
<< std::endl;
}
}
)
.handle<display_balance>(
[&](display_balance const& msg)
{
{
std::lock_guard<std::mutex> lk(iom);
std::cout
<< "The balance of your account is "
<< msg.amount << std::endl;
}
}
)
.handle<display_withdrawal_options>(
[&](display_withdrawal_options const& msg)
{
{
std::lock_guard<std::mutex> lk(iom);
std::cout << "Withdraw 50? (w)" << std::endl;
std::cout << "Display Balance? (b)"
<< std::endl;
std::cout << "Cancel? (c)" << std::endl;
}
}
)
.handle<display_withdrawal_cancelled>(
[&](display_withdrawal_cancelled const& msg)
{
{
std::lock_guard<std::mutex> lk(iom);
std::cout << "Withdrawal cancelled"
<< std::endl;
}
}
)
.handle<display_pin_incorrect_message>(
[&](display_pin_incorrect_message const& msg)
{
{
std::lock_guard<std::mutex> lk(iom);
std::cout << "PIN incorrect" << std::endl;
}
}
)
.handle<eject_card>(
[&](eject_card const& msg)
{
{
std::lock_guard<std::mutex> lk(iom);
std::cout << "Ejecting card" << std::endl;
}
}
);
}
}
catch (close_queue&)
{
}
}
sender get_sender()
{
return incoming;
}
};
}