本文整理汇总了C++中dds::Subscriber_var::create_datareader方法的典型用法代码示例。如果您正苦于以下问题:C++ Subscriber_var::create_datareader方法的具体用法?C++ Subscriber_var::create_datareader怎么用?C++ Subscriber_var::create_datareader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dds::Subscriber_var
的用法示例。
在下文中一共展示了Subscriber_var::create_datareader方法的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:
DDS::DataReader_var
create_reader(const DDS::Subscriber_var& sub, const char* topicName,
const DDS::DataReaderQos& qos = DATAREADER_QOS_DEFAULT,
const DDS::DataReaderListener_var& listener = 0,
const DDS::StatusMask& mask = OpenDDS::DCPS::DEFAULT_STATUS_MASK)
{
const DDS::TypeSupport_var ts = new ::OpenDDS::DCPS::TypeSupportImpl_T<MessageType>();
const DDS::DomainParticipant_var dp = sub->get_participant();
const CORBA::String_var typeName = ts->get_type_name();
(void) ts->register_type(dp, typeName); // may have been registered before
const DDS::Topic_var topic =
dp->create_topic(topicName, typeName, TOPIC_QOS_DEFAULT, 0, 0);
if (!topic) return 0;
const DDS::DataReader_var dr =
sub->create_datareader(topic, qos, listener, mask);
return OpenDDS::DCPS::DDSTraits<MessageType>::DataReaderType::_narrow(dr);
}
示例3: 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;
}
示例4: ACE_TMAIN
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
try
{
DDS::DomainParticipantFactory_var dpf;
DDS::DomainParticipant_var participant;
dpf = TheParticipantFactoryWithArgs(argc, argv);
if( parse_args(argc, argv) != 0)
return 1;
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,
"(%P|%t) create_participant failed.\n")
, -1);
}
MessageTypeSupportImpl* mts_servant = new MessageTypeSupportImpl;
if (DDS::RETCODE_OK != mts_servant->register_type(participant.in (),
"")) {
ACE_ERROR_RETURN ((LM_ERROR,
"(%P|%t) Failed to register the MessageTypeTypeSupport.\n")
, -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 ())) {
ACE_ERROR_RETURN ((LM_ERROR,
"(%P|%t) Failed to create_topic.\n")
, -1);
}
// Indicate that the subscriber is about to become ready
FILE* readers_ready = ACE_OS::fopen (sub_ready_filename, ACE_TEXT("w"));
if (readers_ready == 0) {
ACE_ERROR_RETURN ((LM_ERROR,
"(%P|%t) ERROR: Unable to create subscriber ready file.\n")
, -1);
}
ACE_OS::fclose(readers_ready);
// Check if the publisher is up and running
ACE_stat stats;
while (ACE_OS::stat (pub_ready_filename, &stats) == -1)
{
ACE_Time_Value small_time(0,250000);
ACE_OS::sleep (small_time);
}
for (int count = 1; count <= sub_reinit_itr; count++)
{
if (verbose) {
ACE_DEBUG ((LM_DEBUG, "(%P|%t) Reinitializing subscriber.\n"));
}
// 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 ())) {
ACE_ERROR_RETURN ((LM_ERROR,
"(%P|%t) Failed to create_subscriber.\n")
, -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(),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (dr.in ())) {
ACE_ERROR_RETURN ((LM_ERROR,
"(%P|%t) create_datareader failed.\n")
, -1);
}
// This is where a speed-bump should be.
while (true)
{
::DDS::InstanceHandleSeq handles;
dr->get_matched_publications (handles);
//.........这里部分代码省略.........
示例5: ACE_TMAIN
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
DDS::DomainParticipantFactory_var dpf = DDS::DomainParticipantFactory::_nil();
DDS::DomainParticipant_var participant = DDS::DomainParticipant::_nil();
try
{
QuantLibAddinCpp::initializeAddin();
boost::gregorian::date date ( boost::gregorian::from_undelimited_string( "20111019" ) );
long evaluationDate = QuantLib::Date( date.day(), QuantLib::Month(date.month().as_number()), date.year() ).serialNumber();
QuantLibAddinCpp::qlSettingsSetEvaluationDate(evaluationDate, OH_NULL);
std::string ticker;
// Initialize, and create a DomainParticipant
dpf = TheParticipantFactoryWithArgs(argc, argv);
qldds_utils::BasicDomainParticipant participant( dpf, EQUITY_OPTIONS_DOMAIN_ID );
participant.createPublisher();
participant.createSubscriber();
DDS::DomainParticipant_var dp = participant.getDomainParticipant();
ACE_Get_Opt cmd_opts( argc, argv, ":s:" );
int option;
while ( (option = cmd_opts()) != EOF )
{
switch( option )
{
case 's' :
ticker = cmd_opts.opt_arg();
break;
}
}
// Topics
// setting up qlBlackConstantVols Topic
DDS::Topic_var ql_black_constant_vols_topic = participant.createTopicAndRegisterType
< qlBlackConstantVolsTypeSupport_var, qlBlackConstantVolsTypeSupportImpl >
( QL_BLACK_CONSTANT_VOLS_TOPIC_NAME );
// setting up qlGeneralizedBlackScholesProcesses Topic
DDS::Topic_var ql_generalized_black_scholes_processes_topic = participant.createTopicAndRegisterType
< qlGeneralizedBlackScholesProcessesTypeSupport_var, qlGeneralizedBlackScholesProcessesTypeSupportImpl >
( QL_GENERALIZED_BLACK_SCHOLES_PROCESSES_TOPIC_NAME );
// setting up qlStrikedTypePayoff Topic
DDS::Topic_var ql_striked_type_payoffs_topic = participant.createTopicAndRegisterType
< qlStrikedTypePayoffsTypeSupport_var, qlStrikedTypePayoffsTypeSupportImpl >
( QL_STRIKED_TYPE_PAYOFFS_TOPIC_NAME );
// setting up qlEuropeanExercises Topic
DDS::Topic_var ql_european_exercises_topic = participant.createTopicAndRegisterType
< qlEuropeanExercisesTypeSupport_var, qlEuropeanExercisesTypeSupportImpl >
( QL_EUROPEAN_EXERCISES_TOPIC_NAME );
StraddleSetupTypeSupport_var ts_res = new StraddleSetupTypeSupportImpl;
if ( ts_res->register_type(dp, "") != DDS::RETCODE_OK )
{
std::cout << "Registration of the Topic FAILED!!!!" << std::endl;
}
CORBA::String_var type_name = ts_res->get_type_name();
std::cout << "Type Name : " << type_name << std::endl;
std::stringstream multi_topic_select;
multi_topic_select << "SELECT ticker, putVols, callVols, putPayoffs, callPayoffs, process, exercises FROM "<<
QL_BLACK_CONSTANT_VOLS_TOPIC_NAME << " NATURAL JOIN " <<
QL_GENERALIZED_BLACK_SCHOLES_PROCESSES_TOPIC_NAME << " NATURAL JOIN " <<
QL_STRIKED_TYPE_PAYOFFS_TOPIC_NAME << " NATURAL JOIN " <<
QL_EUROPEAN_EXERCISES_TOPIC_NAME << " WHERE ticker = '" << ticker << "'";
std::cout << multi_topic_select.str() << std::endl;
DDS::MultiTopic_var mt = dp->create_multitopic("MyMultiTopic", type_name, multi_topic_select.str().c_str(), DDS::StringSeq());
if ( CORBA::is_nil( mt ) )
std::cout << "MultiTopic Subscribtion failed.!!!!" << mt << std::endl;
DDS::Subscriber_var sub = participant.getSubscriber();
std::cout << "Creating Data Reader"<< std::endl;
DDS::DataReader_var dr = sub->create_datareader(mt, DATAREADER_QOS_DEFAULT, 0, ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
std::cout << "Done..."<< std::endl;
DDS::WaitSet_var ws = new DDS::WaitSet;
DDS::ReadCondition_var rc = dr->create_readcondition( DDS::ANY_SAMPLE_STATE, DDS::ANY_VIEW_STATE, DDS::ANY_INSTANCE_STATE);
ws->attach_condition(rc);
DDS::Duration_t infinite = { DDS::DURATION_INFINITE_SEC, DDS::DURATION_INFINITE_NSEC};
DDS::ConditionSeq active;
int ret = ws->wait(active, infinite);
if (ret != DDS::RETCODE_OK) return false;
ws->detach_condition(rc);
//.........这里部分代码省略.........
示例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: options
//.........这里部分代码省略.........
}
// 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;
while (delay < options.total_duration_msec) {
bool complete = true;
for (ListenerServants::const_iterator listener = listener_servants.begin();
listener != listener_servants.end();
++listener) {
if (!(*listener)->done()) {
complete = false;
}
}
if (complete)
break;
delay += sleep_delay_msec;
ACE_OS::sleep(ACE_Time_Value(0, sleep_delay_msec * 1000));
}
ACE_DEBUG((LM_DEBUG, ACE_TEXT("%T (%P|%t) Listeners done (ran for %d msec)\n"), delay));
示例8: listener
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
try {
// Initialize DomainParticipantFactory
DDS::DomainParticipantFactory_var dpf =
TheParticipantFactoryWithArgs(argc, argv);
// Create DomainParticipant
DDS::DomainParticipant_var participant =
dpf->create_participant(42,
PARTICIPANT_QOS_DEFAULT,
0,
OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (!participant) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" create_participant failed!\n")), -1);
}
// Register Type (Messenger::Message)
Messenger::MessageTypeSupport_var ts =
new Messenger::MessageTypeSupportImpl;
if (ts->register_type(participant, "") != DDS::RETCODE_OK) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" 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,
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);
}
// Create DataReader
DDS::DataReaderListener_var listener(new DataReaderListenerImpl);
DDS::DataReader_var reader =
subscriber->create_datareader(topic,
DATAREADER_QOS_DEFAULT,
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);
}
Messenger::MessageDataReader_var reader_i =
Messenger::MessageDataReader::_narrow(reader);
if (!reader_i) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" _narrow 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);
while (true) {
DDS::SubscriptionMatchedStatus matches;
if (reader->get_subscription_matched_status(matches) != DDS::RETCODE_OK) {
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT("ERROR: %N:%l: main() -")
ACE_TEXT(" get_subscription_matched_status failed!\n")), -1);
}
if (matches.current_count == 0 && matches.total_count > 0) {
break;
//.........这里部分代码省略.........
示例9: 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;
}
示例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: do_reader
int do_reader(DDS::DomainParticipant_var participant, DDS::Topic_var topic, bool toggle)
{
// 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: do_reader() -")
ACE_TEXT(" create_subscriber failed!\n")), -1);
}
DDS::DataReaderQos qos;
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) {
//.........这里部分代码省略.........
示例12: SubscriberListenerImpl
//.........这里部分代码省略.........
::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 &&
(sample_count - sample_count_start) < samples_per_cycle);
subscriber->delete_datareader(reader.in());
if (use_cft)
CORBA::release(cft);
participant->delete_subscriber(subscriber.in());
ACE_OS::sleep(delay_between_cycles);
}
while (!expected_samples_received);
participant->delete_contained_entities();
dpf->delete_participant(participant.in());
TheServiceParticipant->shutdown();
ACE_DEBUG ((LM_INFO,
ACE_TEXT("INFO: %d samples received\n"),
subscriberListener->received_samples()));
if (deadline_used)
ACE_DEBUG ((LM_INFO,
ACE_TEXT("INFO: deadline missed %d times\n"),
subscriberListener->missed_samples()));
}
catch (const CORBA::Exception& e)
{
e._tao_print_exception("caught in main()");
return 9;
}
ACE_DEBUG((LM_INFO, ACE_TEXT("(%P|%t) <- SUBSCRIBER FINISHED\n")));
return 0;
}
示例13: ACE_TMAIN
//.........这里部分代码省略.........
OpenDDS::DCPS::AttachStatus status = sub_impl->attach_transport(transport_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);
}
// activate the listener
DDS::DataReaderListener_var listener = new DataReaderListenerImpl;
DataReaderListenerImpl &listener_servant =
*dynamic_cast<DataReaderListenerImpl*>(listener.in());
if (CORBA::is_nil (listener.in ())) {
cerr << "listener is nil." << endl;
exit(1);
}
// Create the Datareaders
DDS::DataReader_var dr = sub->create_datareader(topic.in (),
DATAREADER_QOS_DEFAULT,
listener.in (),
::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
if (CORBA::is_nil (dr.in ())) {
cerr << "create_datareader failed." << endl;
exit(1);
}
if (dr->enable () != ::DDS::RETCODE_PRECONDITION_NOT_MET)
{
cerr << "DataReader can not be enabled because Subscriber is not enabled." << endl;
return 1;
}
// Now enable DomainParticipantFactory autoenable
fqos.entity_factory.autoenable_created_entities = 1;
if (dpf->set_qos (fqos) != ::DDS::RETCODE_OK)
{
cerr << "DomainParticipantFactory set_qos failed." << endl;
return 1;
}
// Enable every entity from factory to it's entities and it should succeed.
if (participant->enable () != ::DDS::RETCODE_OK
|| topic->enable () != ::DDS::RETCODE_OK
|| sub->enable () != ::DDS::RETCODE_OK)
{
cerr << "Failed to enable factory." << endl;
return 1;
}
// The datareader is not enabled so it will not able to
示例14: 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;
}
//.........这里部分代码省略.........
示例15: 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;
}