本文整理汇总了C++中dds::DataReader_var::set_listener方法的典型用法代码示例。如果您正苦于以下问题:C++ DataReader_var::set_listener方法的具体用法?C++ DataReader_var::set_listener怎么用?C++ DataReader_var::set_listener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dds::DataReader_var
的用法示例。
在下文中一共展示了DataReader_var::set_listener方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ACE_TMAIN
int ACE_TMAIN(int argc, ACE_TCHAR** argv)
{
bool complete = false;
try {
OpenDDS::Model::Application application(argc, argv);
MessengerMC::DefaultMessengerMCType model(application, argc, argv);
using OpenDDS::Model::MessengerMC::Elements;
DDS::DataReader_var reader = model.reader( Elements::DataReaders::reader);
DDS::DataReaderListener_var listener(new ReaderListener(complete));
reader->set_listener( listener.in(), OpenDDS::DCPS::DEFAULT_STATUS_MASK);
// START OF EXISTING MESSENGER EXAMPLE CODE
data1::MessageDataReader_var reader_i =
data1::MessageDataReader::_narrow(reader);
if (CORBA::is_nil(reader_i.in())) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" _narrow failed!\n")),
-1);
}
ACE_OS::sleep(2);
std::cout << "sub signaling ready" << std::endl;
// Signal readiness to publisher
FileSystemSignal(1).signal();
// END OF EXISTING MESSENGER EXAMPLE CODE
} catch (const CORBA::Exception& e) {
e._tao_print_exception("Exception caught in main():");
return -1;
} catch( const std::exception& ex) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: %N:%l: main() -")
ACE_TEXT(" Exception caught: %C\n"),
ex.what()),
-1);
}
ACE_OS::sleep(5);
std::cout << "sub exiting" << std::endl;
return 0;
}
示例2: ACE_TMAIN
int ACE_TMAIN(int argc, ACE_TCHAR** argv)
{
try {
OpenDDS::Model::Application application(argc, argv);
SubQos::DefaultSubQosType model(application, argc, argv);
using OpenDDS::Model::SubQos::Elements;
DDS::DataReader_var reader = model.reader( Elements::DataReaders::reader);
DDS::Subscriber_var subscriber = reader->get_subscriber();
ACE_SYNCH_MUTEX lock;
ACE_Condition<ACE_SYNCH_MUTEX> condition(lock);
OpenDDS::Model::ReaderCondSync rcs(reader, condition);
DDS::DataReaderListener_var listener(new ReaderListener(rcs));
reader->set_listener( listener.in(), OpenDDS::DCPS::DEFAULT_STATUS_MASK);
// Call on_data_available in case there are samples which are waiting
listener->on_data_available(reader);
// START OF EXISTING MESSENGER EXAMPLE CODE
MessageDataReader_var reader_i =
MessageDataReader::_narrow(reader);
if (CORBA::is_nil(reader_i.in())) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" _narrow failed!\n")),
-1);
}
DDS::SubscriberQos sub_qos;
if (subscriber->get_qos(sub_qos) != 0) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: %N:%l: main() -")
ACE_TEXT(" get_qos failed!\n")),
-1);
}
// was set to false for Sub
if (sub_qos.entity_factory.autoenable_created_entities) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: %N:%l: main() -")
ACE_TEXT(" subscriber has wrong autoenable value!\n")),
-1);
} else {
if (subscriber->enable() != DDS::RETCODE_OK) {
std::cout << "bad return code enabling subscriber" << std::endl;
}
if (reader->enable() != DDS::RETCODE_OK) {
std::cout << "bad return code enabling reader" << std::endl;
}
}
char* buff = reinterpret_cast<char*>(sub_qos.group_data.value.get_buffer());
std::cout << "Group data is:" << buff << std::endl;
if (strcmp(buff, "eight is 8") != 0) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: %N:%l: main() -")
ACE_TEXT(" subscriber has wrong group_data value\n")),
-1);
}
if (sub_qos.partition.name.length() != 1) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: %N:%l: main() -")
ACE_TEXT(" subscriber has wrong # of partitions\n")),
-1);
}
if (strcmp(sub_qos.partition.name[0], "*") != 0) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: %N:%l: main() -")
ACE_TEXT(" subscriber has wrong partition value\n")),
-1);
}
if (sub_qos.presentation.access_scope != DDS::TOPIC_PRESENTATION_QOS) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: %N:%l: main() -")
ACE_TEXT(" subscriber has wrong access scope\n")),
-1);
}
if (sub_qos.presentation.coherent_access != true) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: %N:%l: main() -")
ACE_TEXT(" subscriber has wrong choerent access\n")),
-1);
}
if (sub_qos.presentation.ordered_access != true) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: %N:%l: main() -")
ACE_TEXT(" subscriber has wrong ordered access\n")),
-1);
}
OpenDDS::Model::ReaderSync rs(reader);
//.........这里部分代码省略.........
示例3: do_reader
//.........这里部分代码省略.........
subscriber->get_default_datareader_qos(qos);
qos.user_data.value.length(3);
qos.user_data.value[0] = 0;
qos.user_data.value[1] = 0;
qos.user_data.value[2] = 0;
qos.reliability.kind = DDS::RELIABLE_RELIABILITY_QOS;
if (toggle) {
ACE_DEBUG((LM_DEBUG, "Creating reader\n"));
DDS::DataReader_var reader =
subscriber->create_datareader(topic,
qos,
0,
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (!reader) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: do_reader() -")
ACE_TEXT(" create_datareader failed!\n")), -1);
}
ACE_OS::sleep(SLEEP_SHORT);
// Go away.
ACE_DEBUG((LM_DEBUG, "Deleting reader\n"));
subscriber->delete_datareader(reader);
ACE_OS::sleep(SLEEP_SHORT);
// Come back.
ACE_DEBUG((LM_DEBUG, "Creating reader\n"));
reader = subscriber->create_datareader(topic,
qos,
0,
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
ACE_OS::sleep(SLEEP_SHORT);
return 0;
} else {
struct Listener : public DDS::DataReaderListener {
size_t found, lost;
Listener() : found(0), lost(0) { }
virtual void
on_requested_deadline_missed (::DDS::DataReader_ptr,
const ::DDS::RequestedDeadlineMissedStatus &) { }
virtual void
on_requested_incompatible_qos (::DDS::DataReader_ptr,
const ::DDS::RequestedIncompatibleQosStatus &) { }
virtual void
on_sample_rejected (::DDS::DataReader_ptr,
const ::DDS::SampleRejectedStatus &) { }
virtual void
on_liveliness_changed (::DDS::DataReader_ptr,
const ::DDS::LivelinessChangedStatus &) { }
virtual void
on_data_available (::DDS::DataReader_ptr) { }
virtual void
on_subscription_matched (::DDS::DataReader_ptr,
const ::DDS::SubscriptionMatchedStatus & status) {
if (status.current_count_change > 0) {
ACE_DEBUG((LM_DEBUG, "Reader found writer\n"));
++found;
}
if (status.current_count_change < 0) {
ACE_DEBUG((LM_DEBUG, "Reader lost writer\n"));
++lost;
}
}
virtual void
on_sample_lost (::DDS::DataReader_ptr,
const ::DDS::SampleLostStatus &) { }
} listener;
// Create DataReader
DDS::DataReader_var reader =
subscriber->create_datareader(topic,
qos,
&listener,
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (!reader) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: do_reader() -")
ACE_TEXT(" create_datareader failed!\n")),
-1);
}
ACE_OS::sleep(SLEEP_LONG);
if (listener.found == 2 && listener.lost == 1) {
reader->set_listener(0, OpenDDS::DCPS::DEFAULT_STATUS_MASK);
return 0;
}
return -1;
}
}