-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatcardoffice.h
executable file
·57 lines (44 loc) · 1.59 KB
/
watcardoffice.h
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
#pragma once
#include "watcard.h"
#include "bank.h"
#include "printer.h"
#include <vector>
#include <queue>
_Task WATCardOffice {
struct Job { // marshalled arguments and return future
// Args
const unsigned int sid;
const unsigned int amount;
WATCard * existingCard;
WATCard::FWATCard result; // return future
// Ctor for "transfer" job
Job( unsigned int sid, unsigned int amount, WATCard * existingCard)
: sid{sid}, amount{amount}, existingCard(existingCard) {}
// Ctor for "create" job
Job( unsigned int sid, unsigned int amount) : Job{sid, amount, nullptr} {}
};
_Task Courier {
void main();
WATCardOffice & office;
Bank & bank;
Printer & printer;
int id;
public:
Courier( WATCardOffice & office, Bank & bank, Printer & printer, int id )
: office(office), bank(bank), printer{printer}, id{id} {}
}; // communicates with bank
void main() override;
Printer & printer;
Bank & bank;
unsigned int numCouriers;
uCondition jobsAreAvailable;
std::queue<Job*> jobQueue;
public:
_Event Lost {}; // lost WATCard
WATCardOffice( Printer & prt, Bank & bank, unsigned int numCouriers );
WATCard::FWATCard create( unsigned int sid, unsigned int amount )
__attribute__(( warn_unused_result ));
WATCard::FWATCard transfer( unsigned int sid, unsigned int amount, WATCard * card )
__attribute__(( warn_unused_result ));
Job * requestWork() __attribute__(( warn_unused_result ));
};