-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptionMulticastBase.h
More file actions
187 lines (154 loc) · 5.75 KB
/
Copy pathExceptionMulticastBase.h
File metadata and controls
187 lines (154 loc) · 5.75 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#ifndef MicroMiddleware_ExceptionMulticastBase_h_IS_INCLUDED
#define MicroMiddleware_ExceptionMulticastBase_h_IS_INCLUDED
#include<string>
#include"MicroMiddleware/IncludeExtLibs.h"
#include"MicroMiddleware/Net/IPPublisher.h"
#include"MicroMiddleware/Net/IPSubscriberListener.h"
#include"MicroMiddleware/NetObjects/HostInformation.h"
#include"MicroMiddleware/MiddlewareException.h"
#include"MicroMiddleware/RmiInterface.h"
#include"MicroMiddleware/Export.h"
namespace MicroMiddleware
{
// -------------------------------------------------------
// The shared data
// -------------------------------------------------------
class DLL_STATE ExceptionMessage : public RmiObjectBase
{
public:
ExceptionMessage()
{}
ExceptionMessage(const HostInformation &hostInfo, const string &d, string stamp, MiddlewareException::ExceptionDescription ex = MiddlewareException::GENERAL_EXCEPTION)
: hostInformation(hostInfo)
, message(d)
, timeStamp(stamp)
, exceptionDescription(ex)
{}
~ExceptionMessage()
{}
virtual void Write(NetworkLib::SerializeWriter *writer)
{
hostInformation.Write(writer);
writer->WriteString(timeStamp);
writer->WriteString(message);
writer->WriteInt32((int)exceptionDescription);
}
virtual void Read(NetworkLib::SerializeReader *reader)
{
hostInformation.Read(reader);
timeStamp = reader->ReadString();
message = reader->ReadString();
exceptionDescription = (MiddlewareException::ExceptionDescription)reader->ReadInt32();
}
void SetHostInformation(const HostInformation &hostInfo) { hostInformation = hostInfo; }
void SetMessage(const string &d) { message = d; }
void SetTimeStamp(const string stamp) { timeStamp = stamp; }
void SetExceptionDescription(MiddlewareException::ExceptionDescription ex) { exceptionDescription = ex; }
HostInformation GetHostInformation() const { return hostInformation; }
string GetComponentName() const { return hostInformation.GetComponentName(); }
string GetMessage() const { return message; }
string GetTimeStamp() const { return timeStamp; }
MiddlewareException::ExceptionDescription GetExceptionDescription() const { return exceptionDescription; }
friend std::ostream& operator<<(std::ostream &ostr, const ExceptionMessage &msg)
{
ostr << "-- " << msg.GetExceptionDescription() << " in " << msg.GetComponentName() << " --" << endl;
ostr << "Local timestamp: \t" << msg.GetTimeStamp() << endl;
ostr << "Component information: \t" << msg.GetHostInformation() << endl;
ostr << "Message details: \t" << msg.GetMessage() << endl;
return ostr;
}
private:
HostInformation hostInformation;
string message;
string timeStamp;
MiddlewareException::ExceptionDescription exceptionDescription;
};
// -------------------------------------------------------
// Publisher Interface
// -------------------------------------------------------
class DLL_STATE ExceptionMulticastInterface : public RmiInterface
{
public:
ExceptionMulticastInterface() { }
~ExceptionMulticastInterface() { }
enum MethodID {
Method_PostException = 11
};
enum InterfaceId
{
ExceptionMulticastInterfaceId = 8
};
virtual int GetInterfaceId() const { return ExceptionMulticastInterface::ExceptionMulticastInterfaceId; }
/**
* Posts (multicasts) the ExceptionMessage to a default multicast address and port.
*
* @param exceptionMessage Contains the HostInformation of the component where the exception occured,
* and a message that describes the exception.
*/
virtual void PostException(ExceptionMessage &exceptionMessage) = 0;
};
// -------------------------------------------------------
// Proxy - Publisher class
// -------------------------------------------------------
class DLL_STATE ExceptionMulticastPublisher : virtual public IPPublisher, virtual public ExceptionMulticastInterface
{
public:
IPPUBLISHER_COMMON(ExceptionMulticastPublisher);
virtual void PostException(ExceptionMessage &exceptionMessage)
{
BeginMarshal(ExceptionMulticastInterface::Method_PostException);
exceptionMessage.Write(GetSocketWriter());
EndMarshal();
}
};
// -------------------------------------------------------
// Stub - Subscriber class
// -------------------------------------------------------
class DLL_STATE ExceptionMulticastSubscriber : public IPSubscriberListener
{
public:
ExceptionMulticastSubscriber(InterfaceHandle handle, ExceptionMulticastInterface* testInt, bool autoStart)
: IPSubscriberListener(handle, autoStart)
, testInterface(testInt)
{ }
virtual ~ExceptionMulticastSubscriber() {}
virtual void RMInvocation(int methodId, RmiBase* stubClient)
{
switch(methodId)
{
case ExceptionMulticastInterface::Method_PostException:
{
ExceptionMessage exceptionMessage;
exceptionMessage.Read(stubClient->GetSocketReader());
stubClient->EndUnmarshal();
testInterface->PostException(exceptionMessage);
break;
}
default:
IPSubscriberListener::RMInvocation(methodId, stubClient);
break;
}
}
private:
ExceptionMulticastInterface *testInterface;
};
/**
* @brief Multicast exception when a middleware exception occurs.
*/
class DLL_STATE ExceptionMulticast
{
public:
static void PostException(const std::string &message, MiddlewareException::ExceptionDescription ex = MiddlewareException::GENERAL_EXCEPTION);
static InterfaceHandle GetMulticastHandle() { return ExceptionMulticast::multicastHandle; }
private:
ExceptionMulticast();
~ExceptionMulticast();
static ExceptionMulticast* GetExceptionMulticast();
ExceptionMulticastPublisher* GetExceptionPublisher() { return exceptionPublisher; }
private:
static ExceptionMulticast *exceptionMulticast;
static InterfaceHandle multicastHandle;
ExceptionMulticastPublisher *exceptionPublisher;
};
} // namespace MicroMiddleware
#endif // ExceptionMulticastBase_h_IS_INCLUDED