-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGroupManagerConnection.h
90 lines (65 loc) · 2.4 KB
/
GroupManagerConnection.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
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifndef MembershipManager_GroupManagerConnection_h_IsIncluded
#define MembershipManager_GroupManagerConnection_h_IsIncluded
#include "MembershipManager/IncludeExtLibs.h"
using namespace std;
// --------------------------------------------------------
// struct GroupManagerConnectionConfig
// --------------------------------------------------------
struct GroupManagerConnectionConfig
{
static int groupManagerPort;
};
// --------------------------------------------------------
// class GroupManagerConnection
// --------------------------------------------------------
/**
* Class GroupManagerConnection logs in the component.
*/
class GroupManagerConnection : protected Thread
{
public:
GroupManagerConnection(const HostInformation &info, const InterfaceHandle &handle, const string &groupName, bool autoStart = false);
virtual ~GroupManagerConnection();
GroupInformation WaitForGroupChange(GroupInformation &currGroupInfo);
map<string, GroupInformation> GetAllGroupInformation();
bool JoinGroup();
void LeaveGroup();
bool IsInGroup();
bool StopConnection(bool wait = true);
bool StartConnection(bool wait = false);
public:
inline void WaitForTermination() { Thread::wait(); }
inline GroupInformation GetGroupInformation() { MutexLocker lock(&classMutex_); return groupInformation_; }
inline HostInformation GetHostInformation() { MutexLocker lock(&classMutex_); return myHostInformation_; }
inline void lock() { classMutex_.lock(); }
inline void unlock() { classMutex_.unlock(); }
inline void wakeAll() { classCondition_.wakeAll(); }
inline bool wait() { return classCondition_.wait(&classMutex_); }
inline bool lockedAndUnlockedWait(int64 ms)
{
lock();
bool wokenUp = classCondition_.wait(&classMutex_, ms);
unlock();
return wokenUp;
}
private:
virtual void run();
bool joinGroup();
void leaveGroup();
void connectToGroupManager(bool waitForConnection = true);
private:
inline bool runThread() { MutexLocker lock(&classMutex_); return runThread_; }
inline bool automaticLogin() { MutexLocker lock(&classMutex_); return automaticJoin_; }
private:
bool runThread_;
bool isInGroup_;
bool automaticJoin_;
GroupManagerClient *groupManagerClient_;
HostInformation myHostInformation_;
InterfaceHandle groupManagerHandle_;
string groupName_;
GroupInformation groupInformation_;
Mutex classMutex_;
WaitCondition classCondition_;
};
#endif