本文整理汇总了C++中Subscriber::assignListener方法的典型用法代码示例。如果您正苦于以下问题:C++ Subscriber::assignListener方法的具体用法?C++ Subscriber::assignListener怎么用?C++ Subscriber::assignListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subscriber
的用法示例。
在下文中一共展示了Subscriber::assignListener方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
pub2->write((void*)&tp2);
if(pub1->getHistoryElementsNumber() >= 0.8*Sparam.historyMaxSize)
pub1->removeMinSeqChange();
if(pub2->getHistoryElementsNumber() >= 0.8*Sparam.historyMaxSize)
pub2->removeMinSeqChange();
if(i==8)
{
pub1->dispose((void*)&tp1);
pub1->unregister((void*)&tp1);
pub2->dispose((void*)&tp2);
pub2->unregister((void*)&tp2);
COPYSTR(tp1.name,"Obje3");
tp1.value = 0;
tp1.price = 1.5;
COPYSTR(tp2.name,"Obje4");
tp2.value = 0;
tp2.price = 1.5;
}
if(sub->getHistoryElementsNumber() >= 1)
{
cout << "Taking from subscriber" <<endl;
if(sub->readNextData((void*)&tp_in,&info))
tp_in.print();
cout << "Subscriber History has now: " << sub->getHistoryElementsNumber() << " elements "<<endl;
}
}
cout << "Sleeping 3 seconds"<<endl;
my_sleep(3);
cout << "Slept for 3 seconds"<< endl;
while(sub->takeNextData((void*)&tp_in,&info))
{
if(info.sampleKind == ALIVE)
tp_in.print();
else
cout << "NOT ALIVE SAMPLE"<< endl;
}
break;
}
case 2:
{
SubscriberAttributes Rparam;
Rparam.historyMaxSize = 50;
Rparam.topic.topicDataType = std::string("TestType");
Rparam.topic.topicName = std::string("Test_topic");
Rparam.topic.topicKind = WITH_KEY;
Locator_t loc;
loc.kind = 1;
loc.port = 10469;
Rparam.unicastLocatorList.push_back(loc); //Listen in port 10469
Subscriber* sub = DomainRTPSParticipant::createSubscriber(p,Rparam);
TestTypeListener listener;
sub->assignListener((SubscriberListener*)&listener);
PublisherAttributes WParam;
WParam.historyMaxSize = 50;
WParam.topic.topicKind = NO_KEY;
WParam.topic.topicDataType = "TestType";
WParam.topic.topicName = "Test_topic";
Publisher* pub1 = DomainRTPSParticipant::createPublisher(p,WParam);
loc.set_IP4_address(192,168,1,IPTEST0);
pub1->addReaderLocator(loc,false);
while(1)
{
cout << "Blocking until new message arrives " << endl;
sub->waitForUnreadMessage();
//cout << "After new message block " << sub->getHistory_n() << endl;
TestType tp;
SampleInfo_t info;
while(sub->readNextData((void*)&tp,&info))
{
tp.print();
pub1->write((void*)&tp);
cout << "Write OK"<< endl;
tp.value = -1;
tp.price = 0;
COPYSTR(tp.name,"UNDEF");
}
if(sub->getHistoryElementsNumber() >= 0.5*Rparam.historyMaxSize)
{
cout << "Taking all" <<endl;
while(sub->takeNextData((void*)&tp,&info))
tp.print();
}
}
break;
}
default:
break;
}
cout << "Enter numer "<< endl;
int n;
cin >> n;
DomainRTPSParticipant::stopAll();
return 0;
}