本文整理汇总了C++中JoynrMessage::getHeaderExpiryDate方法的典型用法代码示例。如果您正苦于以下问题:C++ JoynrMessage::getHeaderExpiryDate方法的具体用法?C++ JoynrMessage::getHeaderExpiryDate怎么用?C++ JoynrMessage::getHeaderExpiryDate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JoynrMessage
的用法示例。
在下文中一共展示了JoynrMessage::getHeaderExpiryDate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QString
TEST_F(JoynrMessageFactoryTest, createRequest){
JoynrMessage joynrMessage = messageFactory.createRequest(
senderID,
receiverID,
qos,
request
);
//warning if prepareRequest needs to long this assert will fail as it compares absolute timestamps
QDateTime expectedExpiryDate = QDateTime::currentDateTime().addMSecs(qos.getTtl());
QDateTime expiryDate = joynrMessage.getHeaderExpiryDate();
EXPECT_NEAR(expectedExpiryDate.toMSecsSinceEpoch(), expiryDate.toMSecsSinceEpoch(), 100.);
LOG_DEBUG(logger,
QString("expiryDate: %1 [%2]")
.arg(expiryDate.toString())
.arg(expiryDate.toMSecsSinceEpoch()));
LOG_DEBUG(logger,
QString("expectedExpiryDate: %1 [%2]")
.arg(expectedExpiryDate.toString())
.arg(expectedExpiryDate.toMSecsSinceEpoch()));
checkParticipantIDs(joynrMessage);
checkRequest(joynrMessage);
EXPECT_QSTREQ(JoynrMessage::VALUE_MESSAGE_TYPE_REQUEST, joynrMessage.getType());
}
示例2: handleRequestReceived
void Dispatcher::handleRequestReceived(const JoynrMessage& message)
{
std::string senderId = message.getHeaderFrom();
std::string receiverId = message.getHeaderTo();
// json request
// lookup necessary data
std::string jsonRequest = message.getPayload();
std::shared_ptr<RequestCaller> caller = requestCallerDirectory.lookup(receiverId);
if (caller == nullptr) {
JOYNR_LOG_ERROR(
logger,
"caller not found in the RequestCallerDirectory for receiverId {}, ignoring",
receiverId);
return;
}
std::string interfaceName = caller->getInterfaceName();
// Get the request interpreter that has been registered with this interface name
std::shared_ptr<IRequestInterpreter> requestInterpreter =
InterfaceRegistrar::instance().getRequestInterpreter(interfaceName);
// deserialize json
try {
Request request = JsonSerializer::deserialize<Request>(jsonRequest);
std::string requestReplyId = request.getRequestReplyId();
JoynrTimePoint requestExpiryDate = message.getHeaderExpiryDate();
std::function<void(std::vector<Variant>)> onSuccess =
[requestReplyId, requestExpiryDate, this, senderId, receiverId](
std::vector<Variant> returnValueVar) {
Reply reply;
reply.setRequestReplyId(requestReplyId);
reply.setResponse(std::move(returnValueVar));
// send reply back to the original sender (ie. sender and receiver ids are reversed
// on
// purpose)
JOYNR_LOG_DEBUG(logger,
"Got reply from RequestInterpreter for requestReplyId {}",
requestReplyId);
JoynrTimePoint now = std::chrono::time_point_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now());
std::int64_t ttl = std::chrono::duration_cast<std::chrono::milliseconds>(
requestExpiryDate - now).count();
messageSender->sendReply(receiverId, // receiver of the request is sender of reply
senderId, // sender of request is receiver of reply
MessagingQos(ttl),
reply);
};
std::function<void(const exceptions::JoynrException&)> onError =
[requestReplyId, requestExpiryDate, this, senderId, receiverId](
const exceptions::JoynrException& exception) {
Reply reply;
reply.setRequestReplyId(requestReplyId);
reply.setError(joynr::exceptions::JoynrExceptionUtil::createVariant(exception));
JOYNR_LOG_DEBUG(logger,
"Got error reply from RequestInterpreter for requestReplyId {}",
requestReplyId);
JoynrTimePoint now = std::chrono::time_point_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now());
std::int64_t ttl = std::chrono::duration_cast<std::chrono::milliseconds>(
requestExpiryDate - now).count();
messageSender->sendReply(receiverId, // receiver of the request is sender of reply
senderId, // sender of request is receiver of reply
MessagingQos(ttl),
reply);
};
// execute request
requestInterpreter->execute(caller,
request.getMethodName(),
request.getParams(),
request.getParamDatatypes(),
onSuccess,
onError);
} catch (const std::invalid_argument& e) {
JOYNR_LOG_ERROR(logger,
"Unable to deserialize request object from: {} - error: {}",
jsonRequest,
e.what());
return;
}
}
示例3: handleRequestReceived
void Dispatcher::handleRequestReceived(const JoynrMessage& message)
{
std::string senderId = message.getHeaderFrom().toStdString();
std::string receiverId = message.getHeaderTo().toStdString();
// json request
// lookup necessary data
QByteArray jsonRequest = message.getPayload();
QSharedPointer<RequestCaller> caller = requestCallerDirectory.lookup(receiverId);
if (caller == NULL) {
LOG_ERROR(logger,
"caller not found in the RequestCallerDirectory for receiverId " +
QString::fromStdString(receiverId) + ", ignoring");
return;
}
std::string interfaceName = caller->getInterfaceName();
// Get the request interpreter that has been registered with this interface name
QSharedPointer<IRequestInterpreter> requestInterpreter =
InterfaceRegistrar::instance().getRequestInterpreter(interfaceName);
// deserialize json
Request* request = JsonSerializer::deserialize<Request>(jsonRequest);
if (request == Q_NULLPTR) {
LOG_ERROR(logger,
QString("Unable to deserialize request object from: %1")
.arg(QString::fromUtf8(jsonRequest)));
return;
}
QString requestReplyId = request->getRequestReplyId();
qint64 requestExpiryDate = message.getHeaderExpiryDate().toMSecsSinceEpoch();
std::function<void(const QList<QVariant>&)> callbackFct =
[requestReplyId, requestExpiryDate, this, senderId, receiverId](
const QList<QVariant>& returnValueQVar) {
Reply reply;
reply.setRequestReplyId(requestReplyId);
reply.setResponse(returnValueQVar);
// send reply back to the original sender (ie. sender and receiver ids are reversed
// on
// purpose)
LOG_DEBUG(logger,
QString("Got reply from RequestInterpreter for requestReplyId %1")
.arg(requestReplyId));
qint64 ttl = requestExpiryDate - QDateTime::currentMSecsSinceEpoch();
messageSender->sendReply(receiverId, // receiver of the request is sender of reply
senderId, // sender of request is receiver of reply
MessagingQos(ttl),
reply);
};
// execute request
requestInterpreter->execute(caller,
request->getMethodName(),
request->getParams(),
request->getParamDatatypes(),
callbackFct);
delete request;
}