本文整理汇总了C++中dds::DataWriter_var::get_publication_matched_status方法的典型用法代码示例。如果您正苦于以下问题:C++ DataWriter_var::get_publication_matched_status方法的具体用法?C++ DataWriter_var::get_publication_matched_status怎么用?C++ DataWriter_var::get_publication_matched_status使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dds::DataWriter_var
的用法示例。
在下文中一共展示了DataWriter_var::get_publication_matched_status方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void
connector_status_exec_i::on_unexpected_status (::DDS::Entity_ptr the_entity,
::DDS::StatusKind status_kind)
{
if (!CORBA::is_nil (the_entity) &&
status_kind == DDS::PUBLICATION_MATCHED_STATUS)
{
::DDS::PublicationMatchedStatus_var stat;
DDS::DataWriter_var wr = ::DDS::DataWriter::_narrow (the_entity);
if(::CORBA::is_nil (wr.in ()))
{
throw ::CORBA::INTERNAL ();
}
::DDS::ReturnCode_t retval =
wr->get_publication_matched_status (stat.out ());
if (retval == ::DDS::RETCODE_OK)
{
if (stat.in ().current_count >= this->number_of_subscribers_ &&
!this->started_.value ())
{
ACE_DEBUG ((LM_DEBUG, "ConnectorStatusListener_exec_i::on_unexpected_status - "
"on_publication_matched status received. Starting application\n"));
this->started_ = true;
this->callback_.start ();
}
}
}
}
示例2: if
int
OpenDDS::Model::WriterSync::wait_unmatch(const DDS::DataWriter_var& writer,
unsigned int num_readers)
{
DDS::ReturnCode_t stat;
DDS::StatusCondition_var condition = writer->get_statuscondition();
condition->set_enabled_statuses(DDS::PUBLICATION_MATCHED_STATUS);
DDS::WaitSet_var ws = new DDS::WaitSet;
ws->attach_condition(condition);
DDS::ConditionSeq conditions;
DDS::PublicationMatchedStatus ms = { 0, 0, 0, 0, 0 };
DDS::Duration_t timeout = { 1, 0 };
do {
if (DCPS_debug_level > 4) {
ACE_DEBUG((LM_NOTICE, ACE_TEXT("WriterSync: pub checking unmatched\n")));
}
stat = writer->get_publication_matched_status(ms);
if (stat != DDS::RETCODE_OK) {
ACE_ERROR_RETURN((
LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: %N:%l: wait_unmatch() -")
ACE_TEXT(" get_publication_matched_status failed!\n")),
-1);
} else if (ms.current_count == 0 && (unsigned int)ms.total_count >= num_readers) {
if (DCPS_debug_level > 4) {
ACE_DEBUG((LM_NOTICE, ACE_TEXT("WriterSync: pub match count %d total count %d\n"),
ms.current_count, ms.total_count));
}
break; // unmatched
}
if (DCPS_debug_level > 4) {
ACE_DEBUG((LM_NOTICE, ACE_TEXT("WriterSync: pub match count %d total count %d\n"),
ms.current_count, ms.total_count));
}
// wait for a change
stat = ws->wait(conditions, timeout);
if ((stat != DDS::RETCODE_OK) && (stat != DDS::RETCODE_TIMEOUT)) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: %N:%l: wait_unmatch() -")
ACE_TEXT(" wait failed!\n")),
-1);
}
} while (true);
ws->detach_condition(condition);
if (DCPS_debug_level > 4) {
ACE_DEBUG((LM_NOTICE, ACE_TEXT("WriterSync: pub unmatched\n")));
}
return 0;
}
示例3: BadSyncException
void
Publisher::run()
{
DDS::Duration_t timeout = { DDS::DURATION_INFINITE_SEC, DDS::DURATION_INFINITE_NSEC};
DDS::ConditionSeq conditions;
DDS::PublicationMatchedStatus matches = { 0, 0, 0, 0, 0};
const int readers_per_publication = 2;
unsigned int cummulative_count = 0;
do {
if( this->options_.verbose()) {
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) Publisher::run() - ")
ACE_TEXT("%d of %d subscriptions attached, waiting for more.\n"),
cummulative_count,
this->publications_.size()*readers_per_publication
));
}
if( DDS::RETCODE_OK != this->waiter_->wait( conditions, timeout)) {
ACE_ERROR((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: Publisher::run() - ")
ACE_TEXT("failed to synchronize at start of test.\n")
));
throw BadSyncException();
}
for( unsigned long index = 0; index < conditions.length(); ++index) {
DDS::StatusCondition_var condition
= DDS::StatusCondition::_narrow( conditions[ index].in());
DDS::Entity_var writer_entity = condition->get_entity();
DDS::DataWriter_var writer = DDS::DataWriter::_narrow( writer_entity);
if( !CORBA::is_nil( writer.in())) {
DDS::StatusMask changes = writer->get_status_changes();
if( changes & DDS::PUBLICATION_MATCHED_STATUS) {
if (writer->get_publication_matched_status(matches) != ::DDS::RETCODE_OK)
{
ACE_ERROR ((LM_ERROR,
"ERROR: failed to get publication matched status\n"));
ACE_OS::exit (1);
}
cummulative_count += matches.current_count_change;
}
}
}
// We know that there are 2 subscriptions matched with each publication.
} while( cummulative_count < (readers_per_publication*this->publications_.size()));
// Kluge to bias the race between BuiltinTopic samples and application
// samples towards the BuiltinTopics during association establishment.
// ACE_OS::sleep( 2);
if( this->options_.verbose()) {
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) Publisher::run() - ")
ACE_TEXT("starting to publish samples with %d matched subscriptions.\n"),
cummulative_count
));
}
for( unsigned int index = 0; index < this->publications_.size(); ++index) {
this->publications_[ index]->start();
}
// Allow some traffic to occur before making any wait() calls.
ACE_OS::sleep( 2);
::DDS::Duration_t delay = { 5, 0 }; // Wait for up to 5 seconds.
if (this->options_.publisher())
{
DDS::ReturnCode_t error =
this->publisher_->wait_for_acknowledgments(delay);
if (error != DDS::RETCODE_OK)
{
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) ERROR: Publisher::run() - ")
ACE_TEXT("publisher wait failed with code: %d.\n"),
error));
++this->status_;
}
}
else
{
for( unsigned int index = 0; index < this->publications_.size(); ++index) {
// First wait on this writer.
::DDS::ReturnCode_t result
= this->publications_[ index]->wait_for_acks( delay);
if( result != ::DDS::RETCODE_OK) {
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) ERROR: Publisher::run() - ")
ACE_TEXT("publication %d wait failed with code: %d.\n"),
index,
result
));
++this->status_;
}
}
}
// Signal the writers to terminate.
for( unsigned int index = 0; index < this->publications_.size(); ++index) {
//.........这里部分代码省略.........
示例4: ACE_TMAIN
int ACE_TMAIN(int argc, ACE_TCHAR** argv)
{
try {
OpenDDS::Model::Application application(argc, argv);
UDP::DefaultUDPType model(application, argc, argv);
using OpenDDS::Model::UDP::Elements;
DDS::DataWriter_var writer = model.writer( Elements::DataWriters::writer);
// START OF EXISTING MESSENGER EXAMPLE CODE
MessageDataWriter_var message_writer =
MessageDataWriter::_narrow(writer.in());
if (CORBA::is_nil(message_writer.in())) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: %N:%l: main() -")
ACE_TEXT(" _narrow failed!\n")),
-1);
}
// Block until Subscriber is available
DDS::StatusCondition_var condition = writer->get_statuscondition();
condition->set_enabled_statuses(DDS::PUBLICATION_MATCHED_STATUS);
DDS::WaitSet_var ws = new DDS::WaitSet;
ws->attach_condition(condition);
DDS::ConditionSeq conditions;
DDS::PublicationMatchedStatus matches = { 0, 0, 0, 0, 0 };
DDS::Duration_t timeout = { 30, 0 };
do {
if (ws->wait(conditions, timeout) != DDS::RETCODE_OK) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: %N:%l: main() -")
ACE_TEXT(" wait failed!\n")),
-1);
}
if (writer->get_publication_matched_status(matches) != ::DDS::RETCODE_OK) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: %N:%l: main() -")
ACE_TEXT(" get_publication_matched_status failed!\n")),
-1);
}
} while (matches.current_count < 1);
ws->detach_condition(condition);
// Write samples
Message message;
message.subject_id = 99;
message.from = CORBA::string_dup("Comic Book Guy");
message.subject = CORBA::string_dup("Review");
message.text = CORBA::string_dup("Worst. Movie. Ever.");
message.count = 0;
for (int i = 0; i < 10; i++) {
DDS::ReturnCode_t error = message_writer->write(message, DDS::HANDLE_NIL);
++message.count;
if (error != DDS::RETCODE_OK) {
ACE_ERROR((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: %N:%l: main() -")
ACE_TEXT(" write returned %d!\n"), error));
}
}
// Cannot wait for samples to be acknowledged - not supported in UDP
std::cout << "publisher sleeping...." << std::endl;
ACE_OS::sleep(2);
std::cout << "publisher done sleeping" << std::endl;
// 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);
}
return 0;
}
示例5: 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;
}
示例6: 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;
}
示例7: ACE_TMAIN
//.........这里部分代码省略.........
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" create_publisher failed!\n")),
-1);
}
// Create DataWriter
DDS::DataWriter_var writer =
publisher->create_datawriter(topic,
DATAWRITER_QOS_DEFAULT,
0,
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (!writer) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" create_datawriter failed!\n")),
-1);
}
Messenger::MessageDataWriter_var message_writer =
Messenger::MessageDataWriter::_narrow(writer);
if (!message_writer) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" _narrow failed!\n")),
-1);
}
// Block until Subscriber is available
DDS::StatusCondition_var condition = writer->get_statuscondition();
condition->set_enabled_statuses(DDS::PUBLICATION_MATCHED_STATUS);
DDS::WaitSet_var ws = new DDS::WaitSet;
ws->attach_condition(condition);
while (true) {
DDS::PublicationMatchedStatus matches;
if (writer->get_publication_matched_status(matches) != ::DDS::RETCODE_OK) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" get_publication_matched_status failed!\n")),
-1);
}
if (matches.current_count >= 1) {
break;
}
DDS::ConditionSeq conditions;
DDS::Duration_t timeout = { 60, 0 };
if (ws->wait(conditions, timeout) != DDS::RETCODE_OK) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" wait failed!\n")),
-1);
}
}
ws->detach_condition(condition);
// Write samples
Messenger::Message message;
message.subject_id = 99;
message.from = "Comic Book Guy";
message.subject = "Review";
message.text = "Worst. Movie. Ever.";
message.count = 0;
for (int i = 0; i < 10; ++i) {
DDS::ReturnCode_t error = message_writer->write(message, DDS::HANDLE_NIL);
++message.count;
++message.subject_id;
if (error != DDS::RETCODE_OK) {
ACE_ERROR((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" write returned %d!\n"), error));
}
}
}
ACE_DEBUG((LM_DEBUG, "(%P|%t) Stop publisher\n"));
// Clean-up!
participant->delete_contained_entities();
dpf->delete_participant(participant);
TheServiceParticipant->shutdown();
} catch (const CORBA::Exception& e) {
e._tao_print_exception("Exception caught in main():");
return -1;
}
ACE_DEBUG((LM_DEBUG, "(%P|%t) Publisher exiting\n"));
return 0;
}
示例8: svc
int svc()
{
int thread_id = thread_counter_++;
// Create Publisher
DDS::Publisher_var publisher =
participant_->create_publisher(PUBLISHER_QOS_DEFAULT,
0,
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (!publisher) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" create_publisher failed!\n")),
-1);
}
writers_[thread_id].resize(6);
ACE_DEBUG((LM_DEBUG, "(%P|%t) Starting DataWriter %C\n", writers_[thread_id].c_str()));
DDS::DataWriterQos qos;
publisher->get_default_datawriter_qos(qos);
qos.user_data.value.length(3);
qos.user_data.value[0] = fromhex(writers_[thread_id], 0);
qos.user_data.value[1] = fromhex(writers_[thread_id], 1);
qos.user_data.value[2] = fromhex(writers_[thread_id], 2);
if (reliable_) {
qos.reliability.kind = DDS::RELIABLE_RELIABILITY_QOS;
qos.reliability.max_blocking_time.sec = DDS::DURATION_INFINITE_SEC;
// qos.resource_limits.max_instances = 10;
// qos.history.depth = 10;
} else {
qos.reliability.kind = DDS::BEST_EFFORT_RELIABILITY_QOS;
}
// Create DataWriter
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: main() -")
ACE_TEXT(" create_datawriter failed!\n")),
-1);
}
TestMsgDataWriter_var message_writer =
TestMsgDataWriter::_narrow(writer);
if (!message_writer) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" _narrow failed!\n")),
-1);
}
// Block until Subscriber is available
DDS::StatusCondition_var condition = writer->get_statuscondition();
condition->set_enabled_statuses(DDS::PUBLICATION_MATCHED_STATUS);
DDS::WaitSet_var ws = new DDS::WaitSet;
ws->attach_condition(condition);
while (true) {
DDS::PublicationMatchedStatus matches;
if (writer->get_publication_matched_status(matches) != ::DDS::RETCODE_OK) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" get_publication_matched_status failed!\n")),
-1);
}
ACE_DEBUG((LM_DEBUG, "(%P|%t) DataWriter %C has %d of %d readers\n", writers_[thread_id].c_str(), matches.current_count, total_readers_));
if (matches.current_count >= total_readers_) {
break;
}
DDS::ConditionSeq conditions;
DDS::Duration_t timeout = { 60, 0 };
if (ws->wait(conditions, timeout) != DDS::RETCODE_OK) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" wait failed!\n")),
-1);
}
}
ws->detach_condition(condition);
// Write samples
TestMsg message;
message.value = 0;
for (int i = 0; i < MSGS_PER_WRITER; ++i) {
DDS::ReturnCode_t error = message_writer->write(message, DDS::HANDLE_NIL);
++message.value;
//.........这里部分代码省略.........
示例9: ACE_TMAIN
//.........这里部分代码省略.........
++attempts;
}
if (attempts == max_attempts)
{
ACE_DEBUG((LM_DEBUG, "ERROR: subscriptions failed to match.\n"));
exit (1);
}
writer->start ();
writer->end ();
ACE_DEBUG((LM_DEBUG, "Writer changing deadline to incompatible value\n"));
// Now set DataWriter deadline to be 6 seconds which is not
// compatible with the existing DataReader. This QoS change
// should be applied and the association broken.
dw_qos.deadline.period.sec = 6;
if (dw->set_qos (dw_qos) != ::DDS::RETCODE_OK) {
ACE_DEBUG((LM_DEBUG,
"ERROR: DataWriter could not change deadline period which "
"should break DataReader associations\n"));
exit (1);
} else {
DDS::WaitSet_var ws = new DDS::WaitSet;
DDS::StatusCondition_var sc = dw->get_statuscondition();
sc->set_enabled_statuses(DDS::PUBLICATION_MATCHED_STATUS);
ws->attach_condition(sc);
DDS::PublicationMatchedStatus matched;
DDS::ConditionSeq active;
const DDS::Duration_t timeout = {5, 0}; // seconds
while (dw->get_publication_matched_status(matched) == DDS::RETCODE_OK
&& matched.current_count) {
if (ws->wait(active, timeout) == DDS::RETCODE_TIMEOUT) {
break;
}
}
ws->detach_condition(sc);
if (matched.current_count != 0) {
ACE_DEBUG((LM_DEBUG,
"ERROR: DataWriter changed deadline period which should "
"break association with all existing DataReaders, but did not\n"));
exit(1);
}
}
// We know the reader has been disassociated, but the reader itself may
// not have been notified yet. Introducing delay here to let the reader
// sync up with the disassociated state before re-associating.
// Wait for reader to finish unmatching.
FILE* fp = ACE_OS::fopen (synch_fname, ACE_TEXT("r"));
int i = 0;
while (fp == 0 && i < 15)
{
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT("(%P|%t) waiting reader to unmatch...\n")));
ACE_OS::sleep (1);
++i;
fp = ACE_OS::fopen (synch_fname, ACE_TEXT("r"));
}
if (fp != 0)
ACE_OS::fclose (fp);
示例10: BadSyncException
void
Publisher::run()
{
DDS::Duration_t timeout = { DDS::DURATION_INFINITE_SEC, DDS::DURATION_INFINITE_NSEC};
DDS::ConditionSeq conditions;
DDS::PublicationMatchedStatus matches = { 0, 0, 0, 0, 0};
unsigned int cummulative_count = 0;
do {
if( this->options_.verbose()) {
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) Publisher::run() - ")
ACE_TEXT("%d of %d subscriptions attached, waiting for more.\n"),
cummulative_count,
this->publications_.size()
));
}
if( DDS::RETCODE_OK != this->waiter_->wait( conditions, timeout)) {
ACE_ERROR((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: Publisher::run() - ")
ACE_TEXT("failed to synchronize at start of test.\n")
));
throw BadSyncException();
}
for( unsigned long index = 0; index < conditions.length(); ++index) {
DDS::StatusCondition_var condition
= DDS::StatusCondition::_narrow( conditions[ index].in());
DDS::DataWriter_var writer = DDS::DataWriter::_narrow( condition->get_entity());
if( !CORBA::is_nil( writer.in())) {
DDS::StatusMask changes = writer->get_status_changes();
if( changes & DDS::PUBLICATION_MATCHED_STATUS) {
if (writer->get_publication_matched_status(matches) != ::DDS::RETCODE_OK)
{
ACE_ERROR ((LM_ERROR,
"ERROR: failed to get publication matched status\n"));
ACE_OS::exit (1);
}
cummulative_count += matches.current_count_change;
}
}
}
} while( cummulative_count < this->publications_.size());
// Kluge to bias the race between BuiltinTopic samples and application
// samples towards the BuiltinTopics during association establishment.
ACE_OS::sleep( 2);
if( this->options_.verbose()) {
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) Publisher::run() - ")
ACE_TEXT("starting to publish samples with %d matched subscriptions.\n"),
cummulative_count
));
}
for( PublicationMap::const_iterator current = this->publications_.begin();
current != this->publications_.end();
++current
) {
current->second->start();
}
// Execute test for specified duration, or block until terminated externally.
if( this->options_.duration() > 0) {
ACE_Time_Value duration( this->options_.duration(), 0);
ACE_OS::sleep( duration);
} else {
// Block the main thread, leaving the others working.
ACE_Thread_Manager::instance()->wait();
}
// Signal the writers to terminate.
for( PublicationMap::const_iterator current = this->publications_.begin();
current != this->publications_.end();
++current
) {
current->second->stop();
}
// Separate loop so the termination messages can be handled concurrently.
for( PublicationMap::const_iterator current = this->publications_.begin();
current != this->publications_.end();
++current
) {
// Join and clean up.
current->second->wait();
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) Publisher::run() - ")
ACE_TEXT("publication %C stopping after sending %d messages.\n"),
current->first.c_str(),
current->second->messages()
));
delete current->second;
}
this->publications_.clear();
if( this->options_.verbose()) {
ACE_DEBUG((LM_DEBUG,
//.........这里部分代码省略.........
示例11: test
//.........这里部分代码省略.........
ACE_TEXT(" ERROR: create_datareader failed!\n")), 7);
FooDataReader_var reader_i = FooDataReader::_narrow(reader);
if (CORBA::is_nil(reader_i))
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" ERROR: _narrow failed!\n")), 1);
// Create DataWriter
DDS::DataWriter_var writer =
publisher->create_datawriter(topic.in(),
DATAWRITER_QOS_DEFAULT,
DDS::DataWriterListener::_nil(),
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(writer.in()))
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" ERROR: 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: main()")
ACE_TEXT(" ERROR: _narrow failed!\n")), 1);
// Block until Subscriber is associated
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: main()")
ACE_TEXT(" ERROR: wait failed!\n")), 1);
if (writer->get_publication_matched_status(matches) != ::DDS::RETCODE_OK)
{
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" ERROR: failed to get publication matched status!\n")),
2);
}
}
while (matches.current_count < 1);
ws->detach_condition(cond);
//
// FooDataWriter::dispose should cause an instance to be
// deleted after the last sample in the instance has been
// taken from the ReceivedDataElementList:
//
DDS_TEST test(reader_i);
if (!test) return 1;
Foo foo;
DDS::InstanceHandle_t handle;
handle = writer_i->register_instance(foo);
writer_i->write(foo, handle);
writer_i->dispose(foo, handle);
ACE_OS::sleep(5); // wait for samples to arrive
if (!test.take_all_samples())
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" ERROR: unable to take samples!\n")), 2);
/// Verify instance has been deleted
if (test.has_instance(handle))
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" ERROR: instance not removed!\n")), 3);
// Clean-up!
participant->delete_contained_entities();
TheParticipantFactory->delete_participant(participant);
TheTransportFactory->release();
TheServiceParticipant->shutdown();
}
catch (const CORBA::Exception& e)
{
e._tao_print_exception("caught in main()");
return -1;
}
return 0;
}
示例12: BadSyncException
void
Publisher::run()
{
DDS::Duration_t timeout = { DDS::DURATION_INFINITE_SEC, DDS::DURATION_INFINITE_NSEC};
DDS::ConditionSeq conditions;
DDS::PublicationMatchedStatus matches = { 0, 0, 0, 0, 0};
unsigned int cummulative_count = 0;
do {
if( this->options_.verbose()) {
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) Publisher::run() - ")
ACE_TEXT("%d of 2 subscriptions attached, waiting for more.\n"),
cummulative_count
));
}
if( DDS::RETCODE_OK != this->waiter_->wait( conditions, timeout)) {
ACE_ERROR((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: Publisher::run() - ")
ACE_TEXT("failed to synchronize at start of test.\n")
));
throw BadSyncException();
}
for( unsigned long index = 0; index < conditions.length(); ++index) {
DDS::StatusCondition_var condition
= DDS::StatusCondition::_narrow( conditions[ index].in());
DDS::Entity_var writer_entity = condition->get_entity();
DDS::DataWriter_var writer = DDS::DataWriter::_narrow( writer_entity);
if( !CORBA::is_nil( writer.in())) {
DDS::StatusMask changes = writer->get_status_changes();
if( changes & DDS::PUBLICATION_MATCHED_STATUS) {
if (writer->get_publication_matched_status(matches) != ::DDS::RETCODE_OK)
{
ACE_ERROR ((LM_ERROR,
"ERROR: failed to get publication matched status\n"));
ACE_OS::exit (1);
}
cummulative_count += matches.current_count_change;
}
}
}
} while( cummulative_count < 2);
/// Kluge to ensure that the remote/subscriber side endpoints have
/// been fully associated before starting to send. This appears to be
/// a race between the association creation and use and the BuiltIn
/// Topic data becoming available. There is no existing mechanism (nor
/// should there be) to prevent an association from exchanging data
/// prior to the remote endpoint information becoming available via the
/// BuiltIn Topic publications.
ACE_OS::sleep( 2);
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) Publisher::run() - ")
ACE_TEXT("starting to publish samples.\n")
));
Test::DataDataWriter_var writer0
= Test::DataDataWriter::_narrow( this->writer_[0].in());
Test::DataDataWriter_var writer1
= Test::DataDataWriter::_narrow( this->writer_[1].in());
Test::Data sample0;
Test::Data sample1;
sample0.key = 1;
sample0.value = 0;
// before_value is just for the high priority sample, low priority samples are in order
sample0.before_value = 0;
sample0.priority = false;
// add some extra baggage to ensure
sample0.baggage.length(9999);
if (options_.multipleInstances())
sample1.key = 2;
else
sample1.key = 1;
sample1.value = 0;
// will determine later which value this sample should be seen before
sample1.before_value = 0;
sample1.priority = true;
bool sent = false;
for (unsigned long num_samples = 1; num_samples < (unsigned long)-1 && !sent; ++num_samples) {
++sample0.value;
if (writer0->write( sample0, DDS::HANDLE_NIL) == DDS::RETCODE_TIMEOUT) {
// indicate the high priority sample should arrive before the indicated low priority sample
sample1.before_value = sample0.value - 1;
while (writer1->write( sample1, DDS::HANDLE_NIL) == DDS::RETCODE_TIMEOUT) {
ACE_ERROR((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: Publisher::run() - ")
ACE_TEXT("should not have backpressure for the second writer.\n")
));
}
sent = true;
}
}
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) Publisher::run() - ")
ACE_TEXT("finished publishing %d samples.\n"),
sample0.value
//.........这里部分代码省略.........
示例13: MessageTypeSupportImpl
//.........这里部分代码省略.........
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" create_publisher failed!\n")),
-1);
}
// Create DataWriter
DDS::DataWriter_var writer =
publisher->create_datawriter(topic.in(),
DATAWRITER_QOS_DEFAULT,
DDS::DataWriterListener::_nil(),
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(writer.in())) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" create_datawriter failed!\n")),
-1);
}
Messenger::MessageDataWriter_var message_writer =
Messenger::MessageDataWriter::_narrow(writer.in());
if (CORBA::is_nil(message_writer.in())) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" _narrow failed!\n")),
-1);
}
// Block until Subscriber is available
DDS::StatusCondition_var condition = writer->get_statuscondition();
condition->set_enabled_statuses(DDS::PUBLICATION_MATCHED_STATUS);
DDS::WaitSet_var ws = new DDS::WaitSet;
ws->attach_condition(condition);
DDS::ConditionSeq conditions;
DDS::PublicationMatchedStatus matches = { 0, 0, 0, 0, 0 };
DDS::Duration_t timeout = { 30, 0 };
do {
if (ws->wait(conditions, timeout) != DDS::RETCODE_OK) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" wait failed!\n")),
-1);
}
if (writer->get_publication_matched_status(matches) != ::DDS::RETCODE_OK) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" get_publication_matched_status failed!\n")),
-1);
}
} while (matches.current_count < 1);
ws->detach_condition(condition);
// Write samples
Messenger::Message message;
message.subject_id = 99;
message.from = CORBA::string_dup("Comic Book Guy");
message.subject = CORBA::string_dup("Review");
message.text = CORBA::string_dup("Worst. Movie. Ever.");
message.count = 0;
for (int i = 0; i < 10; i++) {
DDS::ReturnCode_t error = message_writer->write(message, DDS::HANDLE_NIL);
if (error != DDS::RETCODE_OK) {
ACE_ERROR((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" write returned %d!\n"), error));
}
}
// Wait for samples to be acknowledged
if (message_writer->wait_for_acknowledgments(timeout) != DDS::RETCODE_OK) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" wait_for_acknowledgments failed!\n")),
-1);
}
// 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():");
return -1;
}
return 0;
}