本文整理汇总了C++中dds::Subscriber_var::get_default_datareader_qos方法的典型用法代码示例。如果您正苦于以下问题:C++ Subscriber_var::get_default_datareader_qos方法的具体用法?C++ Subscriber_var::get_default_datareader_qos怎么用?C++ Subscriber_var::get_default_datareader_qos使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dds::Subscriber_var
的用法示例。
在下文中一共展示了Subscriber_var::get_default_datareader_qos方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: string
DDS::DataReader_var
createDataReader(
DDS::Subscriber_var subscriber,
DDS::Topic_var topic,
DDS::DataReaderListener_var listener,
bool keep_last_one)
{
// Set qos
DDS::DataReaderQos dr_qos;
// RELIABLE/KEEP_LAST/10 works
subscriber->get_default_datareader_qos(dr_qos);
dr_qos.reliability.kind = DDS::RELIABLE_RELIABILITY_QOS;
if (keep_last_one) {
dr_qos.history.kind = DDS::KEEP_LAST_HISTORY_QOS;
dr_qos.history.depth = 1;
std::cout << "Datareader QOS keep last one" << std::endl;
} else {
dr_qos.history.kind = DDS::KEEP_LAST_HISTORY_QOS;
dr_qos.history.depth = 10;
}
// Create DataReader
DDS::DataReader_var reader =
subscriber->create_datareader(topic,
dr_qos,
listener,
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
// Check for failure
if (!reader) {
throw std::string("failed to create data reader");
}
return reader;
}
示例2: rd
DDS::DataReader_var
Factory::reader(const DDS::Subscriber_var& sub, const DDS::Topic_var& topic, const DDS::DataReaderListener_var& drl) const
{
// Create the data readers
DDS::DataReaderQos dr_qos;
sub->get_default_datareader_qos(dr_qos);
dr_qos.durability.kind = opts_.durability_kind;
dr_qos.liveliness.kind = opts_.liveliness_kind;
dr_qos.liveliness.lease_duration = opts_.LEASE_DURATION;
dr_qos.reliability.kind = opts_.reliability_kind;
DDS::DomainParticipant_var dp = sub->get_participant();
CORBA::String_var tn = topic->get_name();
DDS::TopicDescription_var description = dp->lookup_topicdescription(tn);
TEST_ASSERT(!CORBA::is_nil(description.in()));
DDS::DataReader_var rd(sub->create_datareader(description.in(),
dr_qos,
drl.in(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK));
// Initialize the transport configuration for the appropriate entity
TEST_ASSERT(!opts_.configuration_str.empty());
if (opts_.configuration_str != "none" && opts_.entity_str == "rw")
{
OpenDDS::DCPS::TransportRegistry::instance()->bind_config(opts_.configuration_str,
rd.in());
if (!opts_.entity_autoenable)
{
TEST_ASSERT(DDS::RETCODE_OK == rd->enable());
}
}
return rd;
}
示例3: MessageTypeSupportImpl
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
int status = 0;
try {
// Initialize DomainParticipantFactory
DDS::DomainParticipantFactory_var dpf =
TheParticipantFactoryWithArgs(argc, argv);
int error;
if ((error = parse_args(argc, argv)) != 0) {
return error;
}
// Create DomainParticipant
DDS::DomainParticipant_var participant =
dpf->create_participant(4,
PARTICIPANT_QOS_DEFAULT,
DDS::DomainParticipantListener::_nil(),
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(participant.in())) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l main()")
ACE_TEXT(" ERROR: create_participant() failed!\n")), -1);
}
// Register Type (Messenger::Message)
Messenger::MessageTypeSupport_var ts =
new Messenger::MessageTypeSupportImpl();
if (ts->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 (Movie Discussion List)
CORBA::String_var type_name = ts->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 Subscriber
DDS::Subscriber_var sub =
participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
DDS::SubscriberListener::_nil(),
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(sub.in())) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l main()")
ACE_TEXT(" ERROR: create_subscriber() failed!\n")), -1);
}
// Create DataReader
DataReaderListenerImpl* const listener_servant = new DataReaderListenerImpl;
DDS::DataReaderListener_var listener(listener_servant);
DDS::DataReaderQos dr_qos;
sub->get_default_datareader_qos(dr_qos);
if (DataReaderListenerImpl::is_reliable()) {
std::cout << "Reliable DataReader" << std::endl;
dr_qos.reliability.kind = DDS::RELIABLE_RELIABILITY_QOS;
}
DDS::DataReader_var reader =
sub->create_datareader(topic.in(),
dr_qos,
listener.in(),
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(reader.in())) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l main()")
ACE_TEXT(" ERROR: create_datareader() failed!\n")), -1);
}
// Block until Publisher completes
DDS::StatusCondition_var condition = reader->get_statuscondition();
condition->set_enabled_statuses(DDS::SUBSCRIPTION_MATCHED_STATUS);
DDS::WaitSet_var ws = new DDS::WaitSet;
ws->attach_condition(condition);
DDS::Duration_t timeout =
{ DDS::DURATION_INFINITE_SEC, DDS::DURATION_INFINITE_NSEC };
DDS::ConditionSeq conditions;
DDS::SubscriptionMatchedStatus matches = { 0, 0, 0, 0, 0 };
//.........这里部分代码省略.........
示例4: ACE_TMAIN
int ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
int result = 0;
ACE_DEBUG ((LM_DEBUG, "(%P|%t) subscriber main\n"));
try
{
DDS::DomainParticipantFactory_var dpf;
DDS::DomainParticipant_var participant;
dpf = TheParticipantFactoryWithArgs(argc, argv);
if (parse_args (argc, argv) == -1) {
return -1;
}
DDS::DomainParticipantQos partQos;
dpf->get_default_participant_qos(partQos);
// set up user data in DP qos
CORBA::ULong part_user_data_len
= static_cast<CORBA::ULong>(ACE_OS::strlen (PART_USER_DATA));
partQos.user_data.value.length (part_user_data_len);
partQos.user_data.value.replace (part_user_data_len,
part_user_data_len,
reinterpret_cast<CORBA::Octet*>(PART_USER_DATA));
participant = dpf->create_participant(411,
partQos,
DDS::DomainParticipantListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (participant.in ())) {
cerr << "subscriber: create_participant failed." << endl;
return 1 ;
}
::Messenger::MessageTypeSupport_var mts = new ::Messenger::MessageTypeSupportImpl();
if (DDS::RETCODE_OK != mts->register_type(participant.in (), "Messenger")) {
cerr << "subscriber: Failed to register the MessageTypeTypeSupport." << endl;
exit(1);
}
CORBA::String_var type_name = mts->get_type_name ();
DDS::TopicQos topic_qos;
participant->get_default_topic_qos(topic_qos);
// set up topic data in topic qos
CORBA::ULong topic_data_len = static_cast<CORBA::ULong>(ACE_OS::strlen (TOPIC_DATA));
topic_qos.topic_data.value.length (topic_data_len);
topic_qos.topic_data.value.replace (topic_data_len, topic_data_len, reinterpret_cast<CORBA::Octet*>(TOPIC_DATA));
DDS::Topic_var topic = participant->create_topic("Movie Discussion List",
type_name.in (),
topic_qos,
DDS::TopicListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (topic.in ())) {
cerr << "subscriber: Failed to create_topic." << endl;
exit(1);
}
// Create the subscriber
DDS::SubscriberQos sub_qos;
participant->get_default_subscriber_qos (sub_qos);
// set up group data in subscriber qos
CORBA::ULong group_data_len = static_cast<CORBA::ULong> (ACE_OS::strlen (GROUP_DATA));
sub_qos.group_data.value.length (group_data_len);
sub_qos.group_data.value.replace (group_data_len, group_data_len, reinterpret_cast<CORBA::Octet*>(GROUP_DATA));
DDS::Subscriber_var sub =
participant->create_subscriber(sub_qos,
DDS::SubscriberListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (sub.in ())) {
cerr << "subscriber: Failed to create_subscriber." << endl;
exit(1);
}
// activate the listener
DDS::DataReaderListener_var listener (new DataReaderListenerImpl);
DataReaderListenerImpl* listener_servant =
dynamic_cast<DataReaderListenerImpl*>(listener.in());
DDS::Subscriber_var builtin = participant->get_builtin_subscriber();
DDS::DataReader_var bitdr =
builtin->lookup_datareader(OpenDDS::DCPS::BUILT_IN_PUBLICATION_TOPIC);
listener_servant->set_builtin_datareader(bitdr.in());
if (CORBA::is_nil (listener.in ())) {
cerr << "subscriber: listener is nil." << endl;
exit(1);
}
// Create the Datareaders
DDS::DataReaderQos dr_qos;
sub->get_default_datareader_qos (dr_qos);
//.........这里部分代码省略.........
示例5: options
//.........这里部分代码省略.........
if (ts->register_type(part->in(), "") != DDS::RETCODE_OK) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l main()")
ACE_TEXT(" ERROR: register_type() failed!\n")), -1);
}
// Create Topic (Movie Discussion List)
DDS::Topic_var topic =
(*part)->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 Subscriber
DDS::Subscriber_var sub =
(*part)->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
DDS::SubscriberListener::_nil(),
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(sub.in())) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l main()")
ACE_TEXT(" ERROR: create_subscriber() failed!\n")), -1);
}
DDS::DataReaderQos qos;
sub->get_default_datareader_qos(qos);
qos.liveliness.kind = DDS::AUTOMATIC_LIVELINESS_QOS;
qos.liveliness.lease_duration.sec = 10;
qos.liveliness.lease_duration.nanosec = 0;
qos.history.kind = DDS::KEEP_ALL_HISTORY_QOS;
if (options.reliable) {
qos.reliability.kind = DDS::RELIABLE_RELIABILITY_QOS;
}
for (unsigned int reader = 0; reader < options.num_readers; ++reader) {
ACE_DEBUG((LM_DEBUG, ACE_TEXT("%T (%P|%t) Creating reader\n")));
// Create DataReader
listener_servants.push_back(new DataReaderListenerImpl(options, pid, part_index, reader));
listeners.push_back(DDS::DataReaderListener_var(listener_servants.back()));
DDS::DataReader_var data_reader =
sub->create_datareader(topic.in(),
qos,
listeners.back().in(),
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(data_reader.in())) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l main()")
ACE_TEXT(" ERROR: create_datareader() failed!\n")), -1);
}
}
}
const unsigned int sleep_delay_msec = 500;
unsigned int delay = 0;
示例6: MessageTypeSupportImpl
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
try {
// Initialize DomainParticipantFactory
DDS::DomainParticipantFactory_var dpf =
TheParticipantFactoryWithArgs(argc, argv);
int error;
if ((error = parse_args(argc, argv)) != 0) {
return error;
}
// Create DomainParticipant
DDS::DomainParticipant_var participant =
dpf->create_participant(411,
PARTICIPANT_QOS_DEFAULT,
DDS::DomainParticipantListener::_nil(),
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(participant.in())) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l main()")
ACE_TEXT(" ERROR: create_participant() failed!\n")), -1);
}
// Register Type (Messenger::Message)
Messenger::MessageTypeSupport_var ts =
new Messenger::MessageTypeSupportImpl();
if (ts->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 (Movie Discussion List)
DDS::Topic_var topic =
participant->create_topic("Movie Discussion List",
ts->get_type_name(),
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);
}
::DDS::SubscriberQos subscriber_qos;
participant->get_default_subscriber_qos (subscriber_qos);
subscriber_qos.presentation.access_scope
= (::DDS::PresentationQosPolicyAccessScopeKind)acess_scope;
subscriber_qos.presentation.coherent_access = true;
subscriber_qos.presentation.ordered_access = true;
SubscriberListenerImpl* subscriber_listener_svt = new SubscriberListenerImpl();
DDS::SubscriberListener_var subscriber_listener(subscriber_listener_svt);
// Create Subscriber
DDS::Subscriber_var sub =
participant->create_subscriber(subscriber_qos,
subscriber_listener.in(),
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(sub.in())) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l main()")
ACE_TEXT(" ERROR: create_subscriber() failed!\n")), -1);
}
// Initialize Transport
OpenDDS::DCPS::TransportImpl_rch transport_impl =
TheTransportFactory->create_transport_impl(transport_impl_id,
OpenDDS::DCPS::AUTO_CONFIG);
OpenDDS::DCPS::AttachStatus status = transport_impl->attach(sub.in());
if (status != OpenDDS::DCPS::ATTACH_OK) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l main()")
ACE_TEXT(" ERROR: attach() failed!\n")), -1);
}
// Create DataReader
DataReaderListenerImpl* listener_svt1 = new DataReaderListenerImpl("DataReader1");
DataReaderListenerImpl* listener_svt2 = new DataReaderListenerImpl("DataReader2");
DDS::DataReaderListener_var listener1(listener_svt1);
DDS::DataReaderListener_var listener2(listener_svt2);
::DDS::DataReaderQos readerQos;
sub->get_default_datareader_qos( readerQos);
readerQos.history.kind = ::DDS::KEEP_ALL_HISTORY_QOS;
readerQos.resource_limits.max_samples_per_instance = ::DDS::LENGTH_UNLIMITED;
DDS::DataReader_var reader1 =
sub->create_datareader(topic.in(),
//.........这里部分代码省略.........
示例7: main
//.........这里部分代码省略.........
/**
Publisher code
**/
if(mode == PUBLISHER){
DDS::PublisherQos publisher_qos;
retval = participant->get_default_publisher_qos(publisher_qos);
assert( DDS::RETCODE_OK == retval );
DDS::Publisher_var publisher = participant->create_publisher(publisher_qos,
NULL,
DDS::STATUS_MASK_NONE);
assert( NULL != publisher.in() );
/**
PID Data Writer
**/
DDS::DataWriterQos dw_qos;
retval = publisher->get_default_datawriter_qos(dw_qos);
assert( DDS::RETCODE_OK == retval );
const char* msg = "HI THERE COWBOY";
dw_qos.user_data.value = DDS_DCPSUFLSeq<unsigned char, DDS::octSeq_uniq_>(msg);
assert( strlen(msg) == dw_qos.user_data.value.length() );
DDS::DataWriter_var writer = publisher->create_datawriter(presence_topic, dw_qos, NULL, DDS::STATUS_MASK_NONE);
assert( NULL != writer.in() );
PID::PresenceDataWriter_var presence_writer = PID::PresenceDataWriter::_narrow(writer);
assert( NULL != presence_writer.in() );
PID::Presence temp_presence;
temp_presence.pid = 100;
temp_presence.hostname = "my_machine";
//handle = presence_writer->register_instance(temp_presence);
//assert( DDS::HANDLE_NIL != handle );
handle = DDS::HANDLE_NIL;
// std::cout << "LOOPING" << std::endl;
// while(shutdown_flag == 0){
retval = presence_writer->write(temp_presence,handle);
assert( DDS::RETCODE_OK == retval );
// usleep(50);
//}
}
/**
Subscriber
**/
else if(mode == SUBSCRIBER){
DDS::SubscriberQos subscriber_qos;
retval = participant->get_default_subscriber_qos(subscriber_qos);
assert( DDS::RETCODE_OK == retval );
DDS::Subscriber_var subscriber = participant->create_subscriber(subscriber_qos,
NULL,
DDS::STATUS_MASK_NONE);
assert( NULL != subscriber.in() );
/**
PID Data Reader
**/
DDS::DataReaderQos dr_qos;
retval = subscriber->get_default_datareader_qos(dr_qos);
assert( DDS::RETCODE_OK == retval );
PID::PresenceReaderListener *p_r_listener = new PID::PresenceReaderListener();
assert(p_r_listener != NULL);
DDS::DataReader_ptr reader = subscriber->create_datareader(presence_topic, dr_qos, p_r_listener, DDS::DATA_AVAILABLE_STATUS);
assert( NULL != reader );
PID::PresenceDataReader *presence_reader = PID::PresenceDataReader::_narrow(reader);
assert( NULL != presence_reader );
while(shutdown_flag == 0){
usleep(50);
}
}
//retval = dpf->delete_participant(participant);
//assert( DDS::RETCODE_OK == retval );
retval = DDS::RETCODE_PRECONDITION_NOT_MET;
while(retval != DDS::RETCODE_OK){
retval = dpf->delete_contained_entities();
/*
switch(retval){
case DDS::RETCODE_OK:
printf("DDS::RETCODE_OK\n");
break;
case DDS::RETCODE_ERROR:
printf("DDS::RETCODE_ERROR\n");
break;
case DDS::RETCODE_OUT_OF_RESOURCES:
printf("DDS::RETCODE_OUT_OF_RESOURCES\n");
break;
case DDS::RETCODE_PRECONDITION_NOT_MET:
printf("DDS::RETCODE_PRECONDITION_NOT_MET\n");
break;
default:
printf("Default case?\n");
}
*/
usleep(10);
}
assert( DDS::RETCODE_OK == retval );
return 0;
}
示例8: ACE_TMAIN
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
try
{
DDS::DomainParticipantFactory_var dpf;
DDS::DomainParticipant_var participant;
dpf = TheParticipantFactoryWithArgs(argc, argv);
participant =
dpf->create_participant(411,
PARTICIPANT_QOS_DEFAULT,
DDS::DomainParticipantListener::_nil());
if (CORBA::is_nil (participant.in ())) {
cerr << "create_participant failed." << endl;
return 1 ;
}
Messenger::MessageTypeSupportImpl* mts_servant =
new Messenger::MessageTypeSupportImpl;
if (DDS::RETCODE_OK != mts_servant->register_type(participant.in (),
""))
{
cerr << "Failed to register the MessageTypeTypeSupport." << endl;
exit(1);
}
CORBA::String_var type_name = mts_servant->get_type_name ();
DDS::TopicQos topic_qos;
participant->get_default_topic_qos(topic_qos);
DDS::Topic_var topic =
participant->create_topic("Movie Discussion List",
type_name.in (),
topic_qos,
DDS::TopicListener::_nil());
if (CORBA::is_nil (topic.in ())) {
cerr << "Failed to create_topic." << endl;
exit(1);
}
// Initialize the transport
OpenDDS::DCPS::TransportImpl_rch tcp_impl =
TheTransportFactory->create_transport_impl (
transport_impl_id,
::OpenDDS::DCPS::AUTO_CONFIG);
// Create the subscriber and attach to the corresponding
// transport.
DDS::Subscriber_var sub =
participant->create_subscriber (SUBSCRIBER_QOS_DEFAULT,
DDS::SubscriberListener::_nil());
if (CORBA::is_nil (sub.in ())) {
cerr << "Failed to create_subscriber." << endl;
exit(1);
}
// Attach the subscriber to the transport.
OpenDDS::DCPS::SubscriberImpl* sub_impl =
dynamic_cast<OpenDDS::DCPS::SubscriberImpl*> (sub.in ());
if (0 == sub_impl) {
cerr << "Failed to obtain subscriber servant\n" << endl;
exit(1);
}
OpenDDS::DCPS::AttachStatus const status =
sub_impl->attach_transport(tcp_impl.in());
if (status != OpenDDS::DCPS::ATTACH_OK) {
std::string status_str;
switch (status) {
case OpenDDS::DCPS::ATTACH_BAD_TRANSPORT:
status_str = "ATTACH_BAD_TRANSPORT";
break;
case OpenDDS::DCPS::ATTACH_ERROR:
status_str = "ATTACH_ERROR";
break;
case OpenDDS::DCPS::ATTACH_INCOMPATIBLE_QOS:
status_str = "ATTACH_INCOMPATIBLE_QOS";
break;
default:
status_str = "Unknown Status";
break;
}
cerr << "Failed to attach to the transport. Status == "
<< status_str.c_str() << endl;
exit(1);
}
// ----------------------------------------------
{
// Attempt to create a DataReader with intentionally
// incompatible QoS.
DDS::DataReaderQos bogus_qos;
sub->get_default_datareader_qos (bogus_qos);
// Set up a 1 second recurring deadline. DataReader creation
// should fail with this QoS since the requested deadline period
// will be less than the test configured offered deadline
//.........这里部分代码省略.........
示例9: ACE_TMAIN
int ACE_TMAIN(int argc, ACE_TCHAR* argv[])
{
try
{
DDS::DomainParticipantFactory_var dpf;
DDS::DomainParticipant_var participant;
dpf = TheParticipantFactoryWithArgs(argc, argv);
participant = dpf->create_participant(411,
PARTICIPANT_QOS_DEFAULT,
DDS::DomainParticipantListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (participant.in ())) {
cerr << "create_participant failed." << endl;
return 1 ;
}
Test::DataTypeSupportImpl * const dts_servant =
new Test::DataTypeSupportImpl;
if (DDS::RETCODE_OK != dts_servant->register_type(participant.in (),
""))
{
cerr << "Failed to register the DataTypeSupport." << endl;
exit(1);
}
CORBA::String_var type_name = dts_servant->get_type_name ();
DDS::TopicQos topic_qos;
participant->get_default_topic_qos(topic_qos);
DDS::Topic_var topic =
participant->create_topic("Data",
type_name.in (),
topic_qos,
DDS::TopicListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (topic.in ())) {
cerr << "Failed to create_topic." << endl;
exit(1);
}
size_t const num_partitions =
sizeof (Test::Requested::PartitionConfigs)
/ sizeof (Test::Requested::PartitionConfigs[0]);
Test::PartitionConfig const * const begin =
Test::Requested::PartitionConfigs;
Test::PartitionConfig const * const end =
begin + num_partitions;
// Keep the readers around long enough for the publications and
// subscriptions to match.
std::vector<DDS::DataReader_var> readers (num_partitions);
for (Test::PartitionConfig const * i = begin; i != end; ++i)
{
DDS::SubscriberQos sub_qos;
participant->get_default_subscriber_qos (sub_qos);
// Specify partitions we're requesting.
CORBA::ULong n = 0;
DDS::StringSeq & names = sub_qos.partition.name;
for (char const * const * s = (*i).partitions;
s != 0 && *s != 0;
++s, ++n)
{
CORBA::ULong const new_len = names.length () + 1;
names.length (new_len);
names[n] = *s;
}
// Create the subscriber and attach to the corresponding
// transport.
DDS::Subscriber_var sub =
participant->create_subscriber (sub_qos,
DDS::SubscriberListener::_nil (),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (sub.in ()))
{
cerr << "Failed to create_subscriber." << endl;
exit(1);
}
DDS::DataReaderListener_var listener (
new Test::DataReaderListener ((*i).expected_matches));
// Create the Datareaders
DDS::DataReaderQos dr_qos;
sub->get_default_datareader_qos (dr_qos);
DDS::DataReader_var dr = sub->create_datareader (topic.in (),
dr_qos,
listener.in (),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (dr.in ())) {
cerr << "create_datareader failed." << endl;
exit(1);
}
readers.push_back (dr);
//.........这里部分代码省略.........
示例10: ACE_TMAIN
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
int return_result = 0;
try
{
DDS::DomainParticipantFactory_var dpf;
DDS::DomainParticipant_var participant;
dpf = TheParticipantFactoryWithArgs(argc, argv);
participant =
dpf->create_participant(11,
PARTICIPANT_QOS_DEFAULT,
DDS::DomainParticipantListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (participant.in ())) {
cerr << "create_participant failed." << endl;
return 1 ;
}
Messenger::MessageTypeSupportImpl* mts_servant =
new Messenger::MessageTypeSupportImpl;
if (DDS::RETCODE_OK != mts_servant->register_type(participant.in (),
""))
{
cerr << "Failed to register the MessageTypeTypeSupport." << endl;
exit(1);
}
CORBA::String_var type_name = mts_servant->get_type_name ();
DDS::TopicQos topic_qos;
participant->get_default_topic_qos(topic_qos);
DDS::Topic_var topic =
participant->create_topic("Movie Discussion List",
type_name.in (),
topic_qos,
DDS::TopicListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (topic.in ())) {
cerr << "Failed to create_topic." << endl;
exit(1);
}
// Create the subscriber and attach to the corresponding
// transport.
DDS::Subscriber_var sub =
participant->create_subscriber (SUBSCRIBER_QOS_DEFAULT,
DDS::SubscriberListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (sub.in ())) {
cerr << "Failed to create_subscriber." << endl;
exit(1);
}
// Create the listener.
DDS::DataReaderListener_var listener (new DataReaderListenerImpl);
DataReaderListenerImpl* listener_servant =
dynamic_cast<DataReaderListenerImpl*>(listener.in());
if (CORBA::is_nil (listener.in ()))
{
cerr << "ERROR: listener is nil." << endl;
exit(1);
}
DDS::DataReaderQos dr_qos; // Good QoS.
sub->get_default_datareader_qos (dr_qos);
dr_qos.resource_limits.max_samples_per_instance = MAX_SAMPLES_PER_INSTANCES;
dr_qos.resource_limits.max_samples = MAX_SAMPLES;
dr_qos.resource_limits.max_instances = MAX_INSTANCES;
#ifndef OPENDDS_NO_OWNERSHIP_PROFILE
dr_qos.history.kind = ::DDS::KEEP_ALL_HISTORY_QOS;
dr_qos.history.depth = MAX_SAMPLES_PER_INSTANCES;
#endif
DDS::DataReader_var dr1 =
sub->create_datareader (topic.in (),
dr_qos,
listener.in (),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (dr1.in ()) )
{
cerr << "ERROR: create_datareader failed." << endl;
exit(1);
}
DDS::DataReader_var dr2 =
sub->create_datareader (topic.in (),
dr_qos,
DDS::DataReaderListener::_nil (),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (dr2.in ()) )
{
cerr << "ERROR: create_datareader failed." << endl;
exit(1);
}
//.........这里部分代码省略.........
示例11: SubscriberListenerImpl
//.........这里部分代码省略.........
ts->get_type_name(),
TOPIC_QOS_DEFAULT,
DDS::TopicListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
DDS::TopicDescription_ptr topic_used = topic.in();
DDS::ContentFilteredTopic_ptr cft = 0;
if (use_cft)
{
// Topic name must be unique.
ACE_CString topic_name = "FooTopic-Filtered-" + toStr(i);
cft =
participant->create_contentfilteredtopic(topic_name.c_str(),
topic,
"key > 0",
DDS::StringSeq());
if (CORBA::is_nil(cft))
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" create_contentfilteredtopic failed!\n")), 8);
topic_used = cft;
}
if (CORBA::is_nil(topic.in()))
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" create_topic failed!\n")), 6);
// Create DataReader
DDS::DataReaderQos reader_qos;
subscriber->get_default_datareader_qos(reader_qos);
reader_qos.history.kind = DDS::KEEP_ALL_HISTORY_QOS;
if (deadline_used)
{
reader_qos.deadline.period.sec = DEADLINE_PERIOD.sec;
reader_qos.deadline.period.nanosec = DEADLINE_PERIOD.nanosec;
}
DDS::DataReader_var reader =
subscriber->create_datareader(topic_used,
reader_qos,
DDS::DataReaderListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil(reader.in()))
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("%N:%l: main()")
ACE_TEXT(" create_datareader failed!\n")), 7);
ACE_Time_Value sample_count_sleep(0, sample_count_sleep_msec * 1000);
std::size_t sample_count;
std::size_t sample_count_start = subscriberListener->samples_processed();
do
{
ACE_OS::sleep(sample_count_sleep);
sample_count =
subscriberListener->samples_processed();
expected_samples_received = sample_count >= expected_samples;
// ACE_DEBUG((LM_DEBUG, "(%P|%t) sample_count = %d\n", sample_count));
}
while (!expected_samples_received &&
示例12: listener
int
ACE_TMAIN(int argc, ACE_TCHAR* argv[])
{
try {
DDS::DomainParticipantFactory_var dpf;
DDS::DomainParticipant_var participant;
dpf = TheParticipantFactoryWithArgs(argc, argv);
participant =
dpf->create_participant(411,
PARTICIPANT_QOS_DEFAULT,
DDS::DomainParticipantListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (participant.in ())) {
cerr << "create_participant failed." << endl;
return 1 ;
}
MessageTypeSupportImpl* mts_servant = new MessageTypeSupportImpl;
if (DDS::RETCODE_OK != mts_servant->register_type(participant.in (),
"")) {
cerr << "Failed to register the MessageTypeTypeSupport." << endl;
exit(1);
}
CORBA::String_var type_name = mts_servant->get_type_name ();
DDS::TopicQos topic_qos;
participant->get_default_topic_qos(topic_qos);
DDS::Topic_var topic =
participant->create_topic("Movie Discussion List",
type_name.in (),
topic_qos,
DDS::TopicListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (topic.in ())) {
cerr << "Failed to create_topic." << endl;
exit(1);
}
// Create the subscriber and attach to the corresponding
// transport.
DDS::Subscriber_var sub =
participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
DDS::SubscriberListener::_nil(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (sub.in ())) {
cerr << "Failed to create_subscriber." << endl;
exit(1);
}
// activate the listener
DDS::DataReaderListener_var listener (new DataReaderListenerImpl);
if (CORBA::is_nil (listener.in ())) {
cerr << "listener is nil." << endl;
exit(1);
}
DataReaderListenerImpl* listener_servant =
dynamic_cast<DataReaderListenerImpl*>(listener.in());
// Create the Datareaders
DDS::DataReaderQos dr_qos;
sub->get_default_datareader_qos (dr_qos);
DDS::DataReader_var dr
= sub->create_datareader(topic.in (),
dr_qos,
listener.in (),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (dr.in ())) {
cerr << "create_datareader failed." << endl;
exit(1);
}
while ( ! listener_servant->received_all ()) {
ACE_OS::sleep (1);
}
if (! listener_servant->passed ()) {
cerr << "test failed - see errors." << endl;
return 1;
}
if (!CORBA::is_nil (participant.in ())) {
participant->delete_contained_entities();
}
if (!CORBA::is_nil (dpf.in ())) {
dpf->delete_participant(participant.in ());
}
::DDS::InstanceHandleSeq handles;
while (1)
{
ACE_OS::sleep(1);
dr->get_matched_publications(handles);
if (handles.length() == 0)
break;
}
//.........这里部分代码省略.........
示例13: shifter
//.........这里部分代码省略.........
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" register_type failed!\n")),
-1);
}
// Create Topic
CORBA::String_var type_name = ts->get_type_name();
DDS::Topic_var topic =
participant->create_topic("TheTopic",
type_name,
TOPIC_QOS_DEFAULT,
0,
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (!topic) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" create_topic failed!\n")),
-1);
}
// Create Subscriber
DDS::Subscriber_var subscriber =
participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
0,
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (!subscriber) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" create_subscriber failed!\n")), -1);
}
const int n_msgs = reliable ? MSGS_PER_WRITER * total_writers : 0;
// Create DataReaders
for (std::vector<std::string>::iterator pos = readers.begin(), limit = readers.end();
pos != limit;
++pos) {
pos->resize(6);
DDS::DataReaderListener_var listener(new DataReaderListenerImpl(*pos, n_msgs, reader_done_callback));
DDS::DataReaderQos qos;
subscriber->get_default_datareader_qos(qos);
qos.user_data.value.length(3);
qos.user_data.value[0] = fromhex(*pos, 0);
qos.user_data.value[1] = fromhex(*pos, 1);
qos.user_data.value[2] = fromhex(*pos, 2);
qos.reliability.kind = reliable ? DDS::RELIABLE_RELIABILITY_QOS : DDS::BEST_EFFORT_RELIABILITY_QOS;
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: main() -")
ACE_TEXT(" create_datareader failed!\n")), -1);
}
TestMsgDataReader_var reader_i =
TestMsgDataReader::_narrow(reader);
if (!reader_i) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" _narrow failed!\n")),
-1);
}
}
WriterTask task(writers, participant, topic, reliable, total_readers);
task.activate(DEFAULT_FLAGS, writers.size());
task.wait();
if (!reliable)
ACE_OS::sleep(10);
else {
ACE_Guard<ACE_Thread_Mutex> g(readers_done_lock);
while (readers_done != static_cast<int>(readers.size()))
readers_done_cond.wait();
// Sleep allows an ACKNACK to be generated.
ACE_OS::sleep(3);
}
// 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;
}
return 0;
}
示例14: main
//.........这里部分代码省略.........
ACE_ERROR ((LM_ERROR,
ACE_TEXT("(%P|%t) ::main: ")
ACE_TEXT("Failed to configure the transport.\n")));
exit(1);
}
// jhoffert - End of transport configuration changes
// Attach the subscriber to the transport.
TAO::DCPS::SubscriberImpl* sub_impl =
::TAO::DCPS::reference_to_servant< TAO::DCPS::SubscriberImpl,
DDS::Subscriber_ptr> (sub.in ());
if (0 == sub_impl) {
cerr << "Failed to obtain subscriber servant\n" << endl;
exit(1);
}
TAO::DCPS::AttachStatus status = sub_impl->attach_transport(tcp_impl.in());
if (status != TAO::DCPS::ATTACH_OK) {
std::string status_str;
switch (status) {
case TAO::DCPS::ATTACH_BAD_TRANSPORT:
status_str = "ATTACH_BAD_TRANSPORT";
break;
case TAO::DCPS::ATTACH_ERROR:
status_str = "ATTACH_ERROR";
break;
case TAO::DCPS::ATTACH_INCOMPATIBLE_QOS:
status_str = "ATTACH_INCOMPATIBLE_QOS";
break;
default:
status_str = "Unknown Status";
break;
}
cerr << "Failed to attach to the transport. Status == "
<< status_str.c_str() << endl;
exit(1);
}
// activate the listener
DataReaderListenerImpl listener_servant;
PortableServer::POA_var poa = TheServiceParticipant->the_poa ();
CORBA::Object_var obj = poa->servant_to_reference(&listener_servant);
DDS::DataReaderListener_var listener =
DDS::DataReaderListener::_narrow (obj.in ());
if (CORBA::is_nil (listener.in ())) {
cerr << "listener is nil." << endl;
exit(1);
}
// To Do: Get default data reader QoS and create the data reader.
DDS::DataReaderQos dr_qos;
sub->get_default_datareader_qos (dr_qos);
DDS::DataReader_var dr = sub->create_datareader(topic.in (),
dr_qos,
listener.in ());
if (CORBA::is_nil (dr.in ())) {
cerr << "create_datareader failed." << endl;
exit(1);
}
// End: Get default data reader QoS and create the data reader.
// To Do: Set up the constraints for when the subscriber is done
// receiving updates.
int expected = 10;
while ( listener_servant.num_reads() < expected) {
ACE_OS::sleep (1);
}
// End: Set up the constraints for how long the subscriber should
// receive updates.
// To Do: Delete the participant's contained entities
if (!CORBA::is_nil (participant.in ())) {
participant->delete_contained_entities();
}
// End: Delete the participant's contained entities
if (!CORBA::is_nil (dpf.in ())) {
dpf->delete_participant(participant.in ());
}
::DDS::InstanceHandleSeq handles;
while (1)
{
ACE_OS::sleep(1);
dr->get_matched_publications(handles);
if (handles.length() == 0)
break;
}
ACE_OS::sleep(2);
TheTransportFactory->release();
TheServiceParticipant->shutdown ();
} catch (CORBA::Exception& e) {
cerr << "Exception caught in main ():" << endl << e << endl;
return 1;
}
return 0;
}
示例15: main
//.........这里部分代码省略.........
DDS::SubscriberListener::_nil());
if (CORBA::is_nil (sub.in ())) {
ACE_ERROR_RETURN ((LM_ERROR,
"(%P|%t) Failed to create_subscriber.\n")
, -1);
}
// Attach the subscriber to the transport.
TAO::DCPS::SubscriberImpl* sub_impl =
::TAO::DCPS::reference_to_servant
< TAO::DCPS::SubscriberImpl, DDS::Subscriber_ptr> (sub.in ());
if (0 == sub_impl) {
ACE_ERROR_RETURN ((LM_ERROR,
"(%P|%t) Failed to obtain subscriber servant.\n")
, -1);
}
TAO::DCPS::AttachStatus status = sub_impl->attach_transport(tcp_impl.in());
if (status != TAO::DCPS::ATTACH_OK)
{
std::string status_str;
switch (status)
{
case TAO::DCPS::ATTACH_BAD_TRANSPORT:
status_str = "ATTACH_BAD_TRANSPORT";
break;
case TAO::DCPS::ATTACH_ERROR:
status_str = "ATTACH_ERROR";
break;
case TAO::DCPS::ATTACH_INCOMPATIBLE_QOS:
status_str = "ATTACH_INCOMPATIBLE_QOS";
break;
default:
status_str = "Unknown Status";
break;
}
ACE_ERROR_RETURN ((LM_ERROR,
"(%P|%t) Failed to attach to the transport. "
"Status == %s.\n"
, status_str.c_str())
, -1);
}
// Create the Datareaders
DDS::DataReaderQos dr_qos;
sub->get_default_datareader_qos (dr_qos);
DDS::DataReader_var dr = sub->create_datareader(topic.in (),
dr_qos,
DDS::DataReaderListener::_nil());
if (CORBA::is_nil (dr.in ())) {
ACE_ERROR_RETURN ((LM_ERROR,
"(%P|%t) create_datareader failed.\n")
, -1);
}
{
ACE_OS::sleep (2);
// This is where a speed-bump should be.
}
if (verbose) {
ACE_DEBUG ((LM_DEBUG, "(%P|%t) *** Destroying Subscriber\n"));
}
// Delete data reader
sub->delete_datareader(dr.in());
// Delete subscriber
participant->delete_subscriber(sub.in());
sub = DDS::Subscriber::_nil();
}
if (!CORBA::is_nil (participant.in ())) {
participant->delete_contained_entities();
}
if (!CORBA::is_nil (dpf.in ())) {
dpf->delete_participant(participant.in ());
}
TheTransportFactory->release();
TheServiceParticipant->shutdown ();
// Indicate that the subscriber is done
FILE* readers_completed = ACE_OS::fopen (sub_finished_filename, "w");
if (readers_completed == 0) {
ACE_ERROR_RETURN ((LM_ERROR,
"(%P|%t) ERROR Unable to create subscriber completed file.\n")
, -1);
}
ACE_OS::fclose(readers_completed);
}
catch (CORBA::Exception& e) {
ACE_ERROR_RETURN ((LM_ERROR,
"(%P|%t) Exception caught in main (): %s (%s).\n"
, e._name (), e._rep_id ())
, -1);
}
return 0;
}