本文整理汇总了C++中SubscriptionRequest::setSubscribeToName方法的典型用法代码示例。如果您正苦于以下问题:C++ SubscriptionRequest::setSubscribeToName方法的具体用法?C++ SubscriptionRequest::setSubscribeToName怎么用?C++ SubscriptionRequest::setSubscribeToName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SubscriptionRequest
的用法示例。
在下文中一共展示了SubscriptionRequest::setSubscribeToName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: semaphore
/**
* Trigger: The dispatcher receives a SubscriptionRequest.
* Expected: The PublicationManager creates a PublisherRunnable and polls
* the MockCaller for the attribute.
*/
TEST_F(SubscriptionTest, receive_subscriptionRequestAndPollAttribute) {
// Use a semaphore to count and wait on calls to the mockRequestCaller
Semaphore semaphore(0);
EXPECT_CALL(*mockRequestCaller, getLocation(_,_))
.WillRepeatedly(
DoAll(
Invoke(mockRequestCaller.get(), &MockTestRequestCaller::invokeLocationOnSuccessFct),
ReleaseSemaphore(&semaphore)));
std::string attributeName = "Location";
Variant subscriptionQos = Variant::make<OnChangeWithKeepAliveSubscriptionQos>(OnChangeWithKeepAliveSubscriptionQos(
500, // validity_ms
1000, // minInterval_ms
2000, // maxInterval_ms
1000 // alertInterval_ms
));
std::string subscriptionId = "SubscriptionID";
SubscriptionRequest subscriptionRequest;
subscriptionRequest.setSubscriptionId(subscriptionId);
subscriptionRequest.setSubscribeToName(attributeName);
subscriptionRequest.setQos(subscriptionQos);
JoynrMessage msg = messageFactory.createSubscriptionRequest(
proxyParticipantId,
providerParticipantId,
qos,
subscriptionRequest);
dispatcher.addRequestCaller(providerParticipantId, mockRequestCaller);
dispatcher.receive(msg);
// Wait for a call to be made to the mockRequestCaller
ASSERT_TRUE(semaphore.waitFor(std::chrono::seconds(1)));
}
示例2: semaphore
/**
* Precondition: A provider is registered and there is at least one subscription for it.
* Trigger: A subscription stop message is received
* Expected: The PublicationManager stops the publications for this provider
*/
TEST_F(SubscriptionTest, stopMessage_stopsPublications) {
qRegisterMetaType<QtOnChangeWithKeepAliveSubscriptionQos>("QtOnChangeWithKeepAliveSubscriptionQos");
qRegisterMetaType<SubscriptionRequest>("SubscriptionRequest");
// Use a semaphore to count and wait on calls to the mockRequestCaller
QSemaphore semaphore(0);
EXPECT_CALL(*mockRequestCaller, getLocation(_))
.WillRepeatedly(
DoAll(
Invoke(mockRequestCaller.data(), &MockTestRequestCaller::invokeOnSuccessFct),
ReleaseSemaphore(&semaphore)));
dispatcher.addRequestCaller(providerParticipantId, mockRequestCaller);
QString attributeName = "Location";
auto subscriptionQos = QSharedPointer<QtSubscriptionQos>(new QtOnChangeWithKeepAliveSubscriptionQos(
1200, // validity_ms
10, // minInterval_ms
100, // maxInterval_ms
1100 // alertInterval_ms
));
QString subscriptionId = "SubscriptionID";
SubscriptionRequest subscriptionRequest;
subscriptionRequest.setSubscriptionId(subscriptionId);
subscriptionRequest.setSubscribeToName(attributeName);
subscriptionRequest.setQos(subscriptionQos);
JoynrMessage msg = messageFactory.createSubscriptionRequest(
QString::fromStdString(proxyParticipantId),
QString::fromStdString(providerParticipantId),
qos,
subscriptionRequest);
// first received message with subscription request
dispatcher.receive(msg);
// wait for two requests from the subscription
ASSERT_TRUE(semaphore.tryAcquire(2, 1000));
SubscriptionStop subscriptionStop;
subscriptionStop.setSubscriptionId(subscriptionRequest.getSubscriptionId());
// receive a subscription stop message
msg = messageFactory.createSubscriptionStop(
QString::fromStdString(proxyParticipantId),
QString::fromStdString(providerParticipantId),
qos,
subscriptionStop);
dispatcher.receive(msg);
// assert that less than 2 requests happen in the next 300 milliseconds
ASSERT_FALSE(semaphore.tryAcquire(2, 300));
}
示例3: while
void ClassDeserializerImpl<SubscriptionRequest>::deserialize(
SubscriptionRequest& subscriptionRequest,
IObject& o)
{
while (o.hasNextField()) {
IField& field = o.nextField();
if (field.name() == "subscriptionId") {
subscriptionRequest.setSubscriptionId(field.value());
}
if (field.name() == "subscribedToName") {
subscriptionRequest.setSubscribeToName(field.value());
}
if (field.name() == "qos") {
Variant qos = convertVariant(field.value());
subscriptionRequest.setQos(qos);
}
}
}
示例4: registerSubscription
void SubscriptionManager::registerSubscription(
const std::string& subscribeToName,
std::shared_ptr<ISubscriptionCallback> subscriptionCaller,
const Variant& qosVariant,
SubscriptionRequest& subscriptionRequest)
{
// Register the subscription
std::string subscriptionId = subscriptionRequest.getSubscriptionId();
JOYNR_LOG_DEBUG(logger, "Subscription registered. ID={}", subscriptionId);
if (subscriptions.contains(subscriptionId)) {
// pre-existing subscription: remove it first from the internal data structure
unregisterSubscription(subscriptionId);
}
std::int64_t now = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch()).count();
subscriptionRequest.setQos(qosVariant);
const SubscriptionQos* qos = subscriptionRequest.getSubscriptionQosPtr();
if (qos->getExpiryDateMs() != SubscriptionQos::NO_EXPIRY_DATE() &&
qos->getExpiryDateMs() < now) {
throw std::invalid_argument("Subscription ExpiryDate " +
std::to_string(qos->getExpiryDateMs()) + " in the past. Now: " +
std::to_string(now));
}
auto subscription = std::make_shared<Subscription>(subscriptionCaller);
subscriptions.insert(subscriptionId, subscription);
{
std::lock_guard<std::recursive_mutex> subscriptionLocker(subscription->mutex);
if (SubscriptionUtil::getAlertInterval(qosVariant) > 0 &&
SubscriptionUtil::getPeriodicPublicationInterval(qosVariant) > 0) {
JOYNR_LOG_DEBUG(logger, "Will notify if updates are missed.");
std::int64_t alertAfterInterval = SubscriptionUtil::getAlertInterval(qosVariant);
JoynrTimePoint expiryDate(std::chrono::milliseconds(qos->getExpiryDateMs()));
if (qos->getExpiryDateMs() == SubscriptionQos::NO_EXPIRY_DATE()) {
expiryDate = JoynrTimePoint(
std::chrono::milliseconds(std::numeric_limits<std::int64_t>::max()));
}
std::int64_t periodicPublicationInterval =
SubscriptionUtil::getPeriodicPublicationInterval(qosVariant);
subscription->missedPublicationRunnableHandle = missedPublicationScheduler->schedule(
new MissedPublicationRunnable(expiryDate,
periodicPublicationInterval,
subscriptionId,
subscription,
*this,
alertAfterInterval),
std::chrono::milliseconds(alertAfterInterval));
} else if (qos->getExpiryDateMs() != SubscriptionQos::NO_EXPIRY_DATE()) {
std::int64_t now = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch()).count();
subscription->subscriptionEndRunnableHandle = missedPublicationScheduler->schedule(
new SubscriptionEndRunnable(subscriptionId, *this),
std::chrono::milliseconds(qos->getExpiryDateMs() - now));
}
}
subscriptionRequest.setSubscriptionId(subscriptionId);
subscriptionRequest.setSubscribeToName(subscribeToName);
}