本文整理汇总了C++中EventQueue::nextEvent方法的典型用法代码示例。如果您正苦于以下问题:C++ EventQueue::nextEvent方法的具体用法?C++ EventQueue::nextEvent怎么用?C++ EventQueue::nextEvent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventQueue
的用法示例。
在下文中一共展示了EventQueue::nextEvent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: authorize
bool authorize(const Service& authService,
Identity *providerIdentity,
ProviderSession *session,
const CorrelationId& cid)
{
{
MutexGuard guard(&g_lock);
g_authorizationStatus[cid] = WAITING;
}
EventQueue tokenEventQueue;
session->generateToken(CorrelationId(), &tokenEventQueue);
std::string token;
Event event = tokenEventQueue.nextEvent();
if (event.eventType() == Event::TOKEN_STATUS ||
event.eventType() == Event::REQUEST_STATUS) {
MessageIterator iter(event);
while (iter.next()) {
Message msg = iter.message();
{
MutexGuard guard(&g_lock);
msg.print(std::cout);
}
if (msg.messageType() == TOKEN_SUCCESS) {
token = msg.getElementAsString(TOKEN);
}
else if (msg.messageType() == TOKEN_FAILURE) {
break;
}
}
}
if (token.length() == 0) {
MutexGuard guard(&g_lock);
std::cout << "Failed to get token" << std::endl;
return false;
}
Request authRequest = authService.createAuthorizationRequest();
authRequest.set(TOKEN, token.c_str());
session->sendAuthorizationRequest(
authRequest,
providerIdentity,
cid);
time_t startTime = time(0);
const int WAIT_TIME_SECONDS = 10;
while (true) {
{
MutexGuard guard(&g_lock);
if (WAITING != g_authorizationStatus[cid]) {
return AUTHORIZED == g_authorizationStatus[cid];
}
}
time_t endTime = time(0);
if (endTime - startTime > WAIT_TIME_SECONDS) {
return false;
}
SLEEP(1);
}
}
示例2: authorizeUsers
bool authorizeUsers()
{
Service authService = d_session->getService(APIAUTH_SVC);
bool is_any_user_authorized = false;
// Authorize each of the users
d_identities.reserve(d_tokens.size());
for (size_t i = 0; i < d_tokens.size(); ++i) {
d_identities.push_back(d_session->createIdentity());
Request authRequest = authService.createAuthorizationRequest();
authRequest.set("token", d_tokens[i].c_str());
CorrelationId correlator(&d_tokens[i]);
EventQueue eventQueue;
d_session->sendAuthorizationRequest(authRequest,
&d_identities[i], correlator, &eventQueue);
Event event = eventQueue.nextEvent();
if (event.eventType() == Event::RESPONSE ||
event.eventType() == Event::REQUEST_STATUS) {
MessageIterator msgIter(event);
while (msgIter.next()) {
Message msg = msgIter.message();
if (msg.messageType() == AUTHORIZATION_SUCCESS) {
std::cout << "User #" << (i+1)
<< " authorization success"
<< std::endl;
is_any_user_authorized = true;
}
else {
std::cout << "User #" << (i+1)
<< " authorization failed"
<< std::endl;
printEvent(event);
}
}
}
}
return is_any_user_authorized;
}
示例3: clientRun
void clientRun(Session *requesterSession)
{
Session& session = *requesterSession;
std::cout << "Client is starting------" << std::endl;
if (!session.start()) {
std::cerr <<"Failed to start client session." << std::endl;
return;
}
Identity identity = session.createIdentity();
if (!d_authOptions.empty()) {
bool isAuthorized = false;
const char* authServiceName = "//blp/apiauth";
if (session.openService(authServiceName)) {
Service authService = session.getService(authServiceName);
isAuthorized = authorize(authService, &identity,
&session, CorrelationId((void *)"cauth"));
}
if (!isAuthorized) {
std::cerr << "No authorization" << std::endl;
return;
}
}
if (!session.openService(d_service.c_str())) {
std::cerr <<"Failed to open " << d_service << std::endl;
return;
}
Service service = session.getService(d_service.c_str());
Request request = service.createRequest("ReferenceDataRequest");
// append securities to request
// Add securities to request
Element securities = request.getElement("securities");
for (size_t i = 0; i < d_securities.size(); ++i) {
securities.appendValue(d_securities[i].c_str());
}
// Add fields to request
Element fields = request.getElement("fields");
for (size_t i = 0; i < d_fields.size(); ++i) {
fields.appendValue(d_fields[i].c_str());
}
request.set("timestamp", getTimestamp());
{
MutexGuard guard(&g_mutex);
std::cout << "Sending Request: " << request << std::endl;
}
EventQueue eventQueue;
session.sendRequest(request, identity,
CorrelationId((void *)"AddRequest"), &eventQueue);
while (true) {
Event event = eventQueue.nextEvent();
std::cout << std::endl << "Client received an event" << std::endl;
MessageIterator msgIter(event);
while (msgIter.next()) {
Message msg = msgIter.message();
MutexGuard guard(&g_mutex);
if (event.eventType() == Event::RESPONSE) {
if (msg.hasElement("timestamp")) {
double responseTime = msg.getElementAsFloat64(
"timestamp");
std::cout << "Response latency = "
<< getTimestamp() - responseTime
<< std::endl;
}
}
msg.print(std::cout) << std::endl;
}
if (event.eventType() == Event::RESPONSE) {
break;
}
}
}
示例4: authenticateWithApp
Identity* authenticateWithApp(SEXP con_) {
Identity* identity_p = 0;
// via Rcpp Attributes we get a try/catch block with error propagation to R "for free"
Session* session =
reinterpret_cast<Session*>(checkExternalPointer(con_, "blpapi::Session*"));
// setup authorization service
std::string service("//blp/apiauth");
// authorize
if (session->openService(service.c_str())) {
Service authService = session->getService(service.c_str());
CorrelationId correlation_id(10);
std::string token;
EventQueue tokenEventQueue;
session->generateToken(correlation_id, &tokenEventQueue);
Event event = tokenEventQueue.nextEvent();
//
// get token for session
//
if(event.eventType() == Event::TOKEN_STATUS ||
event.eventType() == Event::REQUEST_STATUS) {
MessageIterator msgIter(event);
while(msgIter.next()) {
Message msg = msgIter.message();
if (msg.messageType() == "TokenGenerationSuccess") {
token = msg.getElementAsString("token");
} else if(msg.messageType() == "TokenGenerationFailure") {
Rcpp::stop("Failed to generate token");
}
}
}
//
// begin authorization
//
if(!token.empty()) {
Request authRequest = authService.createAuthorizationRequest();
authRequest.set("token", token.c_str());
identity_p = new Identity(session->createIdentity());
session->sendAuthorizationRequest(authRequest, identity_p);
// parse messages
bool message_found = false;
while(!message_found) {
Event event = session->nextEvent(100000);
if (event.eventType() == Event::RESPONSE ||
event.eventType() == Event::REQUEST_STATUS ||
event.eventType() == Event::PARTIAL_RESPONSE) {
MessageIterator msgIter(event);
while (msgIter.next()) {
Message msg = msgIter.message();
if (msg.messageType() == "AuthorizationSuccess") {
message_found = true;
} else {
Rcpp::stop(">>> Failed to Authorize");
}
}
} else if(event.eventType() == Event::TIMEOUT) {
Rcpp::stop("Timed out trying to authorize");
}
}
} else {
Rcpp::stop("Generated token was empty");
}
}
return identity_p;
}