-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServiceManager.h
More file actions
165 lines (134 loc) · 4.83 KB
/
Copy pathServiceManager.h
File metadata and controls
165 lines (134 loc) · 4.83 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#ifndef ServiceManager_ServiceManager_IsIncluded
#define ServiceManager_ServiceManager_IsIncluded
#include<map>
#include<list>
#include<sstream>
#include<fstream>
#include "ServiceManager/IncludeExtLibs.h"
namespace ServiceManagerSpace
{
// --------------------------------------------------------
// struct ServiceManagerConfig
// --------------------------------------------------------
struct ServiceManagerConfig
{
static int serviceManagerPort;
static string hostInformationFile;
};
class ServiceManagerUI;
// --------------------------------------------------------
// class ServiceManager
// --------------------------------------------------------
/**
* Class ServiceManager keeps track of the available services in each system.
* It monitors the running state of each service, which is either ONLINE or OFFLINE.
*/
class ServiceManager : public ServiceManagerInterface, public Thread
{
private:
typedef map<string, HostInformation> MapHostInformation;
typedef map<string, int> MapAliveCheck;
typedef list<string> ListAddresses;
//typedef std::map<string, HostInformation> MapServiceNameHostInformation;
typedef std::set<string> SetServiceName;
MapHostInformation mapHostInformation;
ListAddresses multicastAddresses;
ListAddresses usedMulticastAddresses;
static int portNumberAssigner;
Mutex updateLock;
MapAliveCheck mapAliveCheck;
int timeCounter;
bool stopServiceManager;
ServiceManagerUI *serviceManagerUI;
ofstream outFile;
string fileName;
private:
void cmdPrintHostInformation(ostream &ostr);
private:
inline void Quit() { MutexLocker lock(&updateLock); stopServiceManager = true; }
private:
void initServiceManager();
void serviceRegistration(HostInformation &info);
void publisherOnline(HostInformation &info);
void publisherOffline(HostInformation &info);
void hostOnline(HostInformation &info);
void hostOffline(HostInformation &info);
HostInformation* findHostInformation(const HostInformation &info);
void removeHostInformation(const HostInformation &info);
void parseHostInformationFromDisc(string &filename);
void recycleMulticastAddress(const string &multicastAddress);
void usedMulticastAddress(const string &multicastAddress);
public:
/**
* Constructor for ServiceManager.
*
* @param name The ServiceManager name is only used by Component class.
*/
ServiceManager(const string &name);
/**
* Shuts down ServiceManager.
*/
virtual ~ServiceManager(void);
/**
* Allows ServiceManagerUI to access private functions in ServiceManager.
*/
friend class ServiceManagerUI;
/**
* Returns InterfaceHandle for SystemManager.
*
* @return InterfaceHandle The SystemManager's InterfaceHandle (Port, Host).
*/
inline virtual InterfaceHandle GetInterfaceHandle() { return InterfaceHandle(ServiceManagerConfig::serviceManagerPort, MicroMiddleware::MiddlewareSettings::GetHostName()); }
/**
* Main thread-loop for the ServiceManager.
* Maintains a list of running services in the system.
*/
virtual void run();
/**
* Registers the service given by HostInformation in the ServiceManager.
*
* @param info HostInformation includes the component descriptions.
* @return Updated HostInformation.
*/
virtual HostInformation ServiceRegistration(HostInformation info);
/**
* Registers or unregisters services in the ServiceManager.
*/
virtual void ServiceRegistration(MapHostInformation &mapServices);
/**
* Retrieve HostInformation about a service identified by serviceName.
*
* @param serviceName The name of the component (service) to retrieve HostInformation.
* @return HostInformation about the serviceName.
*/
virtual HostInformation GetServiceInformation(string serviceName);
/**
* Called by all component services to inform the ServiceManager that it is connected/disconnected.
* The serviceName is used if the caller requires information whether a service is currently online.
*
* @param info The (callers) service' HostInformation.
* @param serviceName Name of a service that the caller is inquiring whether it is online or not.
* @return serviceName's HostInformation.
*/
virtual HostInformation AliveChecker(HostInformation info, string serviceName);
/**
* Called by ServiceConnectionManager to register service, and retrieve information about services.
*/
virtual MapHostInformation AliveChecker(MapHostInformation &mapService, SetServiceName &setNames);
/**
* Shuts down the ServiceManager.
*/
virtual void ShutDown();
/**
* Clears Offline Services.
*/
virtual void ClearServices();
/**
* Returns all service information in the ServiceManager in a map (string, HostInformation).
*
* @return Map containing all service information.
*/
virtual map<string, HostInformation> GetAllServiceInformation();
};
} // namespace ServiceManagerSpace
#endif // ServiceManager_ServiceManager_IsIncluded