本文整理汇总了C++中Topic::service方法的典型用法代码示例。如果您正苦于以下问题:C++ Topic::service方法的具体用法?C++ Topic::service怎么用?C++ Topic::service使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Topic
的用法示例。
在下文中一共展示了Topic::service方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: processEvent
bool MyEventHandler::processEvent(const Event& event, ProviderSession* session)
{
if (event.eventType() == Event::SESSION_STATUS) {
printMessages(event);
MessageIterator iter(event);
while (iter.next()) {
Message msg = iter.message();
if (msg.messageType() == SESSION_TERMINATED) {
g_running = false;
}
}
}
else if (event.eventType() == Event::TOPIC_STATUS) {
TopicList topicList;
MessageIterator iter(event);
while (iter.next()) {
Message msg = iter.message();
std::cout << msg << std::endl;
if (msg.messageType() == TOPIC_SUBSCRIBED) {
std::string topicStr = msg.getElementAsString("topic");
MutexGuard guard(&g_mutex);
MyStreams::iterator it = g_streams.find(topicStr);
if (it == g_streams.end()) {
// TopicList knows how to add an entry based on a
// TOPIC_SUBSCRIBED message.
topicList.add(msg);
it = (g_streams.insert(MyStreams::value_type(
topicStr,
new MyStream(topicStr)))).first;
}
it->second->setSubscribedState(true);
if (it->second->isAvailable()) {
++g_availableTopicCount;
}
}
else if (msg.messageType() == TOPIC_UNSUBSCRIBED) {
std::string topicStr = msg.getElementAsString("topic");
MutexGuard guard(&g_mutex);
MyStreams::iterator it = g_streams.find(topicStr);
if (it == g_streams.end()) {
// we should never be coming here. TOPIC_UNSUBSCRIBED can
// not come before a TOPIC_SUBSCRIBED or TOPIC_CREATED
continue;
}
if (it->second->isAvailable()) {
--g_availableTopicCount;
}
it->second->setSubscribedState(false);
}
else if (msg.messageType() == TOPIC_CREATED) {
std::string topicStr = msg.getElementAsString("topic");
MutexGuard guard(&g_mutex);
MyStreams::iterator it = g_streams.find(topicStr);
if (it == g_streams.end()) {
it = (g_streams.insert(MyStreams::value_type(
topicStr,
new MyStream(topicStr)))).first;
}
try {
Topic topic = session->getTopic(msg);
it->second->setTopic(topic);
} catch (blpapi::Exception &e) {
std::cerr
<< "Exception in Session::getTopic(): "
<< e.description()
<< std::endl;
continue;
}
if (it->second->isAvailable()) {
++g_availableTopicCount;
}
}
else if (msg.messageType() == TOPIC_RECAP) {
// Here we send a recap in response to a Recap request.
try {
std::string topicStr = msg.getElementAsString("topic");
MyStreams::iterator it = g_streams.find(topicStr);
MutexGuard guard(&g_mutex);
if (it == g_streams.end() || !it->second->isAvailable()) {
continue;
}
Topic topic = session->getTopic(msg);
Service service = topic.service();
CorrelationId recapCid = msg.correlationId();
Event recapEvent = service.createPublishEvent();
EventFormatter eventFormatter(recapEvent);
eventFormatter.appendRecapMessage(topic, &recapCid);
eventFormatter.setElement("numRows", 25);
eventFormatter.setElement("numCols", 80);
eventFormatter.pushElement("rowUpdate");
for (int i = 1; i < 6; ++i) {
eventFormatter.appendElement();
eventFormatter.setElement("rowNum", i);
eventFormatter.pushElement("spanUpdate");
eventFormatter.appendElement();
eventFormatter.setElement("startCol", 1);
eventFormatter.setElement("length", 10);
eventFormatter.setElement("text", "RECAP");
eventFormatter.popElement();
//.........这里部分代码省略.........