本文整理汇总了C++中dds::DataWriter_var::set_listener方法的典型用法代码示例。如果您正苦于以下问题:C++ DataWriter_var::set_listener方法的具体用法?C++ DataWriter_var::set_listener怎么用?C++ DataWriter_var::set_listener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dds::DataWriter_var
的用法示例。
在下文中一共展示了DataWriter_var::set_listener方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: do_writer
//.........这里部分代码省略.........
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (!publisher) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: do_writer() -")
ACE_TEXT(" create_publisher failed!\n")),
-1);
}
DDS::DataWriterQos qos;
publisher->get_default_datawriter_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] = 1;
qos.reliability.kind = DDS::RELIABLE_RELIABILITY_QOS;
if (toggle) {
ACE_DEBUG((LM_DEBUG, "Creating writer\n"));
DDS::DataWriter_var writer =
publisher->create_datawriter(topic,
qos,
0,
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (!writer) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: do_writer() -")
ACE_TEXT(" create_datawriter failed!\n")), -1);
}
ACE_OS::sleep(SLEEP_SHORT);
// Go away.
ACE_DEBUG((LM_DEBUG, "Deleting writer\n"));
publisher->delete_datawriter(writer);
ACE_OS::sleep(SLEEP_SHORT);
// Come back.
ACE_DEBUG((LM_DEBUG, "Creating writer\n"));
writer = publisher->create_datawriter(topic,
qos,
0,
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
ACE_OS::sleep(SLEEP_SHORT);
return 0;
} else {
struct Listener : public DDS::DataWriterListener {
size_t found, lost;
Listener() : found(0), lost(0) { }
virtual void
on_offered_deadline_missed (::DDS::DataWriter_ptr,
const ::DDS::OfferedDeadlineMissedStatus &) { }
virtual void
on_offered_incompatible_qos (::DDS::DataWriter_ptr,
const ::DDS::OfferedIncompatibleQosStatus &) { }
virtual void
on_liveliness_lost (::DDS::DataWriter_ptr,
const ::DDS::LivelinessLostStatus &) { }
virtual void
on_publication_matched (::DDS::DataWriter_ptr,
const ::DDS::PublicationMatchedStatus & status) {
if (status.current_count_change > 0) {
ACE_DEBUG((LM_DEBUG, "Writer found reader\n"));
++found;
}
if (status.current_count_change < 0) {
ACE_DEBUG((LM_DEBUG, "Writer lost reader\n"));
++lost;
}
}
} listener;
// Create DataWriter
DDS::DataWriter_var writer =
publisher->create_datawriter(topic,
qos,
&listener,
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (!writer) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: do_writer() -")
ACE_TEXT(" create_datawriter failed!\n")),
-1);
}
ACE_OS::sleep(SLEEP_LONG);
if (listener.found == 2 && listener.lost == 1) {
writer->set_listener(0, OpenDDS::DCPS::DEFAULT_STATUS_MASK);
return 0;
}
return -1;
}
}