-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCNode.h
72 lines (56 loc) · 1.88 KB
/
CNode.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
62
63
64
65
66
67
68
69
70
71
72
#ifndef RING_CNODE_H
#define RING_CNODE_H
#include "CUnit.h"
#include "loggers.h"
#include <condition_variable>
#include <mutex>
#include <string>
#include <vector>
#include <queue>
namespace RING
{
class CNode
{
public:
CNode(unsigned p_nodeId,
const std::shared_ptr<CLoggerBase>& p_logger,
const std::string& p_rightSkeletonAddress,
const std::string& p_leftSkeletonAddress,
const CUnit::SNeighbour& p_rightNeighbour,
const CUnit::SNeighbour& p_leftNeighbour);
void StartSkeleton();
void StartStub();
void RunHDAEagerLE();
void ReceiveMessage(CUnit::EMessageType p_type, unsigned p_nodeId, EDirection p_direction);
~CNode();
private:
enum class EState
{
Candidate,
Defeated,
Leader,
Terminated
};
struct SMessage
{
CUnit::EMessageType m_type;
unsigned m_nodeId;
// FIXME new structs with visitor pattern, because it is only for LeaderElected type
EDirection m_toDirection;
};
void Run();
void SendNodeIdMessage(unsigned p_nodeId, EDirection p_direction);
void SendLeaderElectedMessage(unsigned p_nodeId, EDirection p_direction);
CUnit& GetUnit(EDirection p_direction);
const unsigned m_nodeId;
CUnit m_rightUnit;
CUnit m_leftUnit;
EState m_state = EState::Candidate;
std::queue<SMessage> m_queue;
std::mutex m_mutex;
std::condition_variable m_conVariable;
std::vector<std::unique_ptr<std::thread>> m_senderThreads;
std::thread m_thread;
};
}
#endif