-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTeller.h
More file actions
77 lines (65 loc) · 1.79 KB
/
Teller.h
File metadata and controls
77 lines (65 loc) · 1.79 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* Teller.h
*
* The Teller object services customers--serves as a thread-safe
* wrapper for removing objects from the customer queue.
*
*/
#ifndef TELLER_H_
#define TELLER_H_
#include <vector>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <queue.h>
#include <unistd.h>
#include <time.h>
#include "Constants.h"
#include "Customer.h"
#include "TimerSys.h"
#include "Metrics.h"
extern Metrics* metrics;
class Teller {
public:
/**
* Function: Constructor
* Description: Initializes the teller object to be capable of handling customers.
* The teller also has a reference to the system time and uses it to
* handle time-related events in the system.
*/
Teller(Queue* queue, int tellerNumber, TimerSys* t); // Constructor
/**
* Function: Destructor
* Description: Called when the class is being destroyed/discarded.
*/
virtual ~Teller();
/**
* Function: startWorking
* Description: Tell the teller to start working. Will initiate a thread
* representing the teller that will try to help customers.
*/
void startWorking();
/**
* Function: stopWorking
* Description: Will waiting until queue is empty, then quit by stopping thread.
**/
void stopWorking();
protected:
/**
* Function: helpCustomers
* Description: Help customers waiting in the queue Keeps helping customers
* until bank is closed AND there are no more customers Each
* customer requires between 30 seconds and 7 minutes to
* complete their transaction.
*/
void helpCustomers();
private:
static void * TellerRunFunction(void * This) {((Teller *)This)->helpCustomers(); return NULL;}
pthread_t thread;
Queue *customerQueue;
bool open;
bool done;
int tellerNum;
TimerSys* timer;
};
#endif /* TELLER_H_ */