本文整理汇总了C++中dds::DataWriter_var::wait_for_acknowledgments方法的典型用法代码示例。如果您正苦于以下问题:C++ DataWriter_var::wait_for_acknowledgments方法的具体用法?C++ DataWriter_var::wait_for_acknowledgments怎么用?C++ DataWriter_var::wait_for_acknowledgments使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dds::DataWriter_var
的用法示例。
在下文中一共展示了DataWriter_var::wait_for_acknowledgments方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
int
OpenDDS::Model::WriterSync::wait_ack(const DDS::DataWriter_var& writer)
{
DDS::ReturnCode_t stat;
DDS::Duration_t timeout = { 30, 0 };
if (DCPS_debug_level > 4) {
ACE_DEBUG((LM_NOTICE, ACE_TEXT("WriterSync: waiting for acks\n")));
}
stat = writer->wait_for_acknowledgments(timeout);
if ((stat != DDS::RETCODE_OK) && (stat != DDS::RETCODE_TIMEOUT)) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: %N:%l: wait_ack() -")
ACE_TEXT(" wait_for_acknowledgments failed!\n")),
-1);
}
if (DCPS_debug_level > 4) {
ACE_DEBUG((LM_NOTICE, ACE_TEXT("WriterSync: acks received\n")));
}
return 0;
}
示例2: guard
//.........这里部分代码省略.........
// Create DataWriter
DDS::DataWriterQos writer_qos;
publisher->get_default_datawriter_qos(writer_qos);
#ifndef OPENDDS_NO_OWNERSHIP_PROFILE
writer_qos.history.depth = samples_per_thread_;
#endif
writer =
publisher->create_datawriter(topic.in(),
writer_qos,
DDS::DataWriterListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(writer.in()))
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: svc()")
ACE_TEXT(" create_datawriter failed!\n")), 1);
writer_i = FooDataWriter::_narrow(writer);
if (CORBA::is_nil(writer_i))
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: svc()")
ACE_TEXT(" _narrow failed!\n")), 1);
// Block until Subscriber is available
cond = writer->get_statuscondition();
cond->set_enabled_statuses(DDS::PUBLICATION_MATCHED_STATUS);
ws->attach_condition(cond);
DDS::Duration_t timeout =
{ DDS::DURATION_INFINITE_SEC, DDS::DURATION_INFINITE_NSEC };
DDS::ConditionSeq conditions;
DDS::PublicationMatchedStatus matches = {0, 0, 0, 0, 0};
do
{
if (ws->wait(conditions, timeout) != DDS::RETCODE_OK)
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: svc()")
ACE_TEXT(" wait failed!\n")), 1);
if (writer->get_publication_matched_status(matches) != ::DDS::RETCODE_OK)
{
ACE_ERROR ((LM_ERROR,
"(%P|%t) ERROR: failed to get publication matched status\n"));
ACE_OS::exit (1);
}
}
while (matches.current_count < 1);
ws->detach_condition(cond);
// The following is intentionally inefficient to stress various
// pathways related to publication; we should be especially dull
// and write only one sample at a time per writer.
ProgressIndicator progress("(%P|%t) PARTICIPANT %d%% (%d samples sent)\n",
samples_per_thread_);
for (std::size_t i = 0; i < samples_per_thread_; ++i)
{
Foo foo;
foo.key = 3;
DDS::InstanceHandle_t handle = writer_i->register_instance(foo);
if (writer_i->write(foo, handle) != DDS::RETCODE_OK) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: svc()")
ACE_TEXT(" write failed!\n")), 1);
}
++progress;
}
DDS::Duration_t interval = { 30, 0};
if( DDS::RETCODE_OK != writer->wait_for_acknowledgments( interval)) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("(%P:%t) ERROR: svc() - ")
ACE_TEXT("timed out waiting for acks!\n")
), 1);
}
}
// Clean-up!
ACE_DEBUG((LM_INFO, ACE_TEXT("(%P|%t) <- PUBLISHER PARTICIPANT DEL CONT ENTITIES\n")));
participant->delete_contained_entities();
ACE_DEBUG((LM_INFO, ACE_TEXT("(%P|%t) <- PUBLISHER DELETE PARTICIPANT\n")));
dpf->delete_participant(participant.in());
ACE_DEBUG((LM_INFO, ACE_TEXT("(%P|%t) <- PUBLISHER PARTICIPANT VARS GOING OUT OF SCOPE\n")));
}
catch (const CORBA::Exception& e)
{
e._tao_print_exception("caught in svc()");
return 1;
}
ACE_DEBUG((LM_INFO, ACE_TEXT("(%P|%t) <- PARTICIPANT FINISHED\n")));
return 0;
}
示例3: delay_between_pubs
//.........这里部分代码省略.........
writer_qos.history.depth = samples_per_thread_;
if (deadline_.sec > 0 || deadline_.nanosec > 0)
{
writer_qos.deadline.period.sec = deadline_.sec;
writer_qos.deadline.period.nanosec = deadline_.nanosec;
}
DDS::DataWriter_var writer =
publisher->create_datawriter(topic.in(),
writer_qos,
DDS::DataWriterListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(writer.in()))
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: svc()")
ACE_TEXT(" create_datawriter failed!\n")), 1);
FooDataWriter_var writer_i = FooDataWriter::_narrow(writer);
if (CORBA::is_nil(writer_i))
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: svc()")
ACE_TEXT(" _narrow failed!\n")), 1);
// Block until Subscriber is available
DDS::StatusCondition_var cond = writer->get_statuscondition();
cond->set_enabled_statuses(DDS::PUBLICATION_MATCHED_STATUS);
DDS::WaitSet_var ws = new DDS::WaitSet;
ws->attach_condition(cond);
DDS::Duration_t timeout =
{ DDS::DURATION_INFINITE_SEC, DDS::DURATION_INFINITE_NSEC };
DDS::ConditionSeq conditions;
DDS::PublicationMatchedStatus matches = {0, 0, 0, 0, 0};
do
{
if (ws->wait(conditions, timeout) != DDS::RETCODE_OK)
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: svc()")
ACE_TEXT(" wait failed!\n")), 1);
if (writer->get_publication_matched_status(matches) != ::DDS::RETCODE_OK)
{
ACE_ERROR ((LM_ERROR,
"(%P|%t) ERROR: failed to get publication matched status\n"));
ACE_OS::exit (1);
}
}
while (matches.current_count < 1);
ws->detach_condition(cond);
// The following is intentionally inefficient to stress various
// pathways related to publication; we should be especially dull
// and write only one sample at a time per writer.
ProgressIndicator progress("(%P|%t) PARTICIPANT %d%% (%d samples sent)\n",
samples_per_thread_);
for (std::size_t i = 0; i < samples_per_thread_; ++i)
{
Foo foo;
foo.key = 3;
DDS::InstanceHandle_t handle = writer_i->register_instance(foo);
if (writer_i->write(foo, handle) != DDS::RETCODE_OK)
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: svc()")
ACE_TEXT(" write failed!\n")), 1);
++progress;
ACE_OS::sleep(delay_between_pubs);
}
DDS::Duration_t interval = { 30, 0};
if( DDS::RETCODE_OK != writer->wait_for_acknowledgments( interval)) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("(%P:%t) ERROR: svc() - ")
ACE_TEXT("timed out waiting for acks!\n")
), 1);
}
publisher->delete_datawriter(writer);
// Clean-up!
participant->delete_contained_entities();
dpf->delete_participant(participant.in());
}
catch (const CORBA::Exception& e)
{
e._tao_print_exception("caught in svc()");
return 1;
}
ACE_DEBUG((LM_INFO, ACE_TEXT("(%P|%t) <- PARTICIPANT FINISHED\n")));
return 0;
}
示例4: ACE_TMAIN
//.........这里部分代码省略.........
if (mts->register_type(participant.in(), "") != DDS::RETCODE_OK) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" ERROR: register_type failed!\n")),
-1);
}
// Create Topic
CORBA::String_var type_name = mts->get_type_name();
DDS::Topic_var topic =
participant->create_topic("Movie Discussion List",
type_name.in(),
TOPIC_QOS_DEFAULT,
DDS::TopicListener::_nil(),
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(topic.in())) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" ERROR: create_topic failed!\n")),
-1);
}
// Create Publisher
DDS::Publisher_var pub =
participant->create_publisher(PUBLISHER_QOS_DEFAULT,
DDS::PublisherListener::_nil(),
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(pub.in())) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" ERROR: create_publisher failed!\n")),
-1);
}
DDS::DataWriterQos qos;
pub->get_default_datawriter_qos(qos);
if (dw_reliable()) {
std::cout << "Reliable DataWriter" << std::endl;
qos.history.kind = DDS::KEEP_ALL_HISTORY_QOS;
qos.reliability.kind = DDS::RELIABLE_RELIABILITY_QOS;
}
// Create DataWriter
DDS::DataWriter_var dw =
pub->create_datawriter(topic.in(),
qos,
DDS::DataWriterListener::_nil(),
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(dw.in())) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" ERROR: create_datawriter failed!\n")),
-1);
}
// Start writing threads
std::cout << "Creating Writer" << std::endl;
Writer* writer = new Writer(dw.in());
std::cout << "Starting Writer" << std::endl;
writer->start();
while (!writer->is_finished()) {
ACE_Time_Value small_time(0, 250000);
ACE_OS::sleep(small_time);
}
std::cout << "Writer finished " << std::endl;
writer->end();
if (wait_for_acks) {
std::cout << "Writer wait for ACKS" << std::endl;
DDS::Duration_t timeout =
{ DDS::DURATION_INFINITE_SEC, DDS::DURATION_INFINITE_NSEC };
dw->wait_for_acknowledgments(timeout);
} else {
// let any missed multicast/rtps messages get re-delivered
ACE_Time_Value small_time(0, 250000);
ACE_OS::sleep(small_time);
}
std::cout << "deleting DW" << std::endl;
delete writer;
}
// Clean-up!
participant->delete_contained_entities();
dpf->delete_participant(participant.in());
TheServiceParticipant->shutdown();
} catch (const CORBA::Exception& e) {
e._tao_print_exception("Exception caught in main():");
ACE_OS::exit(-1);
}
return 0;
}