-
Notifications
You must be signed in to change notification settings - Fork 0
/
EMAClient.cpp
237 lines (212 loc) · 6.39 KB
/
EMAClient.cpp
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#include "EMAClient.h"
#include <iostream>
using namespace thomsonreuters::ema::access;
using namespace thomsonreuters::ema::rdm;
using namespace std;
NIProviderClient::NIProviderClient() :
bConnectionUp(false),
bDumpOutput(false)
{
}
NIProviderClient ::~NIProviderClient()
{
}
bool NIProviderClient::isConnectionUp() const
{
return bConnectionUp;
}
void NIProviderClient::dumpOutput(const bool& flag)
{
this->bDumpOutput = flag;
}
void NIProviderClient::onRefreshMsg(const RefreshMsg& refreshMsg, const OmmProviderEvent& ommEvent)
{
if (refreshMsg.getDomainType() == MMT_LOGIN)
{
cout << endl << "NIProvier OnRefreshMsg Handle: " << ommEvent.getHandle() << " Closure: " << ommEvent.getClosure() << endl;
if (bDumpOutput)
cout << refreshMsg << endl;
if (refreshMsg.getState().getStreamState() == OmmState::OpenEnum)
{
if (refreshMsg.getState().getDataState() == OmmState::OkEnum)
bConnectionUp = true;
else
bConnectionUp = false;
}
else
bConnectionUp = false;
}
}
void NIProviderClient::onStatusMsg(const StatusMsg& statusMsg, const OmmProviderEvent& ommEvent)
{
cout << endl << "NIProviderClient OnStatus Handle: " << ommEvent.getHandle() << " Closure: " << ommEvent.getClosure() << endl;
if (bDumpOutput)
cout << statusMsg << endl;
if (statusMsg.getDomainType() == MMT_LOGIN)
{
if (statusMsg.hasState())
{
if (statusMsg.getState().getStreamState() == OmmState::OpenEnum)
{
if (statusMsg.getState().getDataState() == OmmState::OkEnum)
bConnectionUp = true;
else
bConnectionUp = false;
}
else
bConnectionUp = false;
}
}
}
ConsumerClient::ConsumerClient():
niProvider(0),
pConsumer(0),
handle(0),
pItemList(0),
bDumpOutput(false),
bUsePrefix(false),
prefixString(""),
bConnectionUp(false)
{
}
ConsumerClient::~ConsumerClient()
{
}
bool ConsumerClient::isConnectionUp() const
{
return bConnectionUp;
}
void ConsumerClient::setConsumer(thomsonreuters::ema::access::OmmConsumer& consumer)
{
pConsumer = &consumer;
}
void ConsumerClient::setNIProvider(OmmProvider& provider)
{
niProvider = &provider;
}
void ConsumerClient::setNIProviderClient(NIProviderClient& providerClient)
{
this->niProviderClient = &providerClient;
}
void ConsumerClient::setItemList(ITEMLIST& itemlist)
{
this->pItemList = &itemlist;
}
void ConsumerClient::usePrefix(const bool& bUsePrefix, const std::string prefixString)
{
this->bUsePrefix = bUsePrefix;
this->prefixString = prefixString;
}
void ConsumerClient::dumpOutput(const bool& flag)
{
this->bDumpOutput = flag;
}
void ConsumerClient::setNIPubServiceName(const EmaString& serviceName)
{
defaultNIPubServiceName = serviceName;
}
void ConsumerClient::onRefreshMsg(const RefreshMsg& refreshMsg, const OmmConsumerEvent& ommEvent)
{
try {
if (refreshMsg.getDomainType() == MMT_LOGIN)
{
cout << endl << "Login OnRefreshMsg Handle: " << ommEvent.getHandle() << " Closure: " << (const char *)(ommEvent.getClosure()) << endl;
if (bDumpOutput)
cout << refreshMsg << endl;
if (refreshMsg.getState().getStreamState() == OmmState::OpenEnum)
{
if (refreshMsg.getState().getDataState() == OmmState::OkEnum)
bConnectionUp = true;
else
bConnectionUp = false;
}
else
bConnectionUp = false;
}
if (refreshMsg.getDomainType() == MMT_MARKET_PRICE)
{
cout << endl << "Market Price OnRefreshMsg Handle: " << ommEvent.getHandle() << " ItemName " << refreshMsg.getName().c_str() << endl;
if (bDumpOutput)
cout << refreshMsg << endl;
if (niProviderClient->isConnectionUp())
{
ITEMLIST::iterator it;
it = pItemList->find(refreshMsg.getName().c_str());
if (it != pItemList->end())
{
string pubItemName = "";
if (bUsePrefix)
pubItemName = prefixString;
pubItemName.append((*it).first);
UInt64 pubHandle = (*it).second.NiPubHandle;
RefreshMsg refresh;
cout << "Publish Refresh message for Item "<<pubItemName.c_str()<<" to Non Interactive provider service..." << endl;
niProvider->submit(refresh.clear().serviceName(defaultNIPubServiceName).name(pubItemName.c_str()).domainType(MMT_MARKET_PRICE)
.state(OmmState::OpenEnum, OmmState::OkEnum, OmmState::NoneEnum, "UnSolicited Refresh Completed").complete(true)
.payload(refreshMsg.getPayload().getFieldList()), pubHandle);
}
}
}
}
catch (OmmException& ex)
{
cout<< ex <<std::endl;
}
}
void ConsumerClient::onUpdateMsg(const UpdateMsg& updateMsg, const OmmConsumerEvent& ommEvent)
{
try{
if (updateMsg.getDomainType() == MMT_MARKET_PRICE)
{
cout << endl << "Market Price OnUpdateMsg Handle: " << ommEvent.getHandle() << " ItemName: " << updateMsg.getName().c_str() << endl;
if (bDumpOutput)
cout << updateMsg << endl;
if (niProviderClient->isConnectionUp())
{
ITEMLIST::iterator it;
it = pItemList->find(updateMsg.getName().c_str());
if (it != pItemList->end())
{
string pubItemName = "";
if (bUsePrefix)
pubItemName = prefixString;
pubItemName.append((*it).first);
UInt64 pubHandle = (*it).second.NiPubHandle;
UpdateMsg update;
cout << "Publish Update message for Item " << pubItemName.c_str() << " to Non Interactive provider service..." << endl;
niProvider->submit(update.clear().serviceName(defaultNIPubServiceName).name(pubItemName.c_str())
.payload(updateMsg.getPayload().getFieldList()), pubHandle);
}
}
}
}
catch (OmmException& ex)
{
cout << ex << std::endl;
}
}
void ConsumerClient::onStatusMsg(const StatusMsg& statusMsg, const OmmConsumerEvent& ommEvent)
{
if (statusMsg.getDomainType() == MMT_LOGIN)
{
cout << endl << "Login OnStatusMsg Handle: " << ommEvent.getHandle() << " Closure: " << (char *)ommEvent.getClosure() << endl;
cout << statusMsg << endl;
if (statusMsg.hasState())
{
if (statusMsg.getState().getStreamState() == OmmState::OpenEnum)
{
if (statusMsg.getState().getDataState() == OmmState::OkEnum)
bConnectionUp = true;
else
bConnectionUp = false;
}
else
bConnectionUp = false;
}
}
if (statusMsg.getDomainType() == MMT_MARKET_PRICE)
{
cout << endl << "Market Price OnStatusMsg Handle: " << ommEvent.getHandle() << " Closure: " << (char *)ommEvent.getClosure() << endl;
cout << statusMsg << endl;
}
}