-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.h
62 lines (51 loc) · 1.39 KB
/
worker.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
58
59
60
61
#pragma once
#include <vector>
#include <memory>
#include <deque>
#include "request.h"
typedef enum {WAITING, RUNNING, STOPPED, ENDED} TState;
using std::vector;
using std::shared_ptr;
using std::deque;
class BaseWorker {
public:
void* Handle();
BaseWorker() {State = WAITING;}
void ClearRequests() {Requests.clear();}
virtual void HandleRequest();
virtual void HandleOtherRequests();
virtual void Calculate();
size_t NeighboursCount(size_t x, size_t y);
virtual void TakeRequests() = 0;
virtual void SendCalculations() = 0;
virtual void ReceiveCalculations() = 0;
virtual void SendFinalReport() = 0;
virtual void CollabSync() = 0;
virtual void SyncWithMaster() = 0;
virtual ~BaseWorker() = default;
vector<vector<int>> Field;
vector<vector<int>> OldField;
size_t IterNumber;
size_t IterCount;
unsigned Height, Width;
unsigned Id;
TState State;
deque<BaseRequest> Requests;
};
struct LocalWorkerData
{
vector<vector<int>>* SrcField;
vector<int>* SendFieldTop;
vector<int>* SendFieldBottom;
vector<int>* ReceiveFieldTop;
vector<int>* ReceiveFieldBottom;
};
class LocalWorker : public virtual BaseWorker, public LocalWorkerData
{
public:
LocalWorker()=default;
LocalWorker(unsigned number, LocalWorkerData localData);
virtual void ReceiveCalculations() override;
virtual void SendCalculations() override;
virtual void SendFinalReport() override;
};