void SubscriberDelegate::init_builtin(DDS::Subscriber_ptr ddssub) { if(ddssub == 0) throw dds::core::NullReferenceError(org::opensplice::core::exception_helper( OSPL_CONTEXT_LITERAL( "dds::core::NullReferenceError : Unable to get builtin Subscriber. " "Nil return from ::get_builtin_subscriber"))); DDS::SubscriberQos qos; DDS::ReturnCode_t result = ddssub->get_qos(qos); org::opensplice::core::check_and_throw(result, OSPL_CONTEXT_LITERAL("Calling ::get_qos")); qos_ = org::opensplice::sub::qos::convertQos(qos); sub_.reset(ddssub, ::org::opensplice::core::SubDeleter(dp_->dp_)); DDS::DataReaderQos oldqos; result = sub_->get_default_datareader_qos(oldqos); org::opensplice::core::check_and_throw(result, OSPL_CONTEXT_LITERAL("Calling ::get_default_datareader_qos")); default_dr_qos_ = org::opensplice::sub::qos::convertQos(oldqos); entity_ = DDS::Entity::_narrow(ddssub); org::opensplice::core::SubDeleter* d = OSPL_CXX11_STD_MODULE::get_deleter<org::opensplice::core::SubDeleter>(sub_); if(d) { d->set_builtin(); } }
void SubscriberListenerImpl::on_data_on_readers( DDS::Subscriber_ptr subs) { ::DDS::ReturnCode_t ret = subs->begin_access (); if (ret != ::DDS::RETCODE_OK) { ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: SubscriberListenerImpl::on_data_on_readers()") ACE_TEXT(" ERROR: begin_access failed!\n"))); ACE_OS::exit(-1); } DDS::SubscriberQos qos; ret = subs->get_qos (qos); if (ret != ::DDS::RETCODE_OK) { ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: SubscriberListenerImpl::on_data_on_readers()") ACE_TEXT(" ERROR: get_qos failed!\n"))); ACE_OS::exit(-1); } ::DDS::DataReaderSeq_var readers = new ::DDS::DataReaderSeq(100); ret = subs->get_datareaders(readers.inout(), ::DDS::NOT_READ_SAMPLE_STATE, ::DDS::ANY_VIEW_STATE, ::DDS::ANY_INSTANCE_STATE) ; if (ret != ::DDS::RETCODE_OK) { ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: SubscriberListenerImpl::on_data_on_readers()") ACE_TEXT(" ERROR: get_datareaders failed!\n"))); ACE_OS::exit(-1); } CORBA::ULong len = readers->length (); if (qos.presentation.access_scope == ::DDS::GROUP_PRESENTATION_QOS) { // redirect datareader listener to receive DISPOSE and UNREGISTER notifications. if (len == 0) { if (subs->notify_datareaders () != ::DDS::RETCODE_OK) { ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: SubscriberListenerImpl::on_data_on_readers()") ACE_TEXT(" ERROR: notify_datareaders failed!\n"))); this->verify_result_ = false; } return; } if (len != num_messages * 4) { ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: SubscriberListenerImpl::on_data_on_readers()") ACE_TEXT(" ERROR: get_datareaders returned %d readers!\n"), len)); this->verify_result_ = false; } for (CORBA::ULong i = 0; i < len; ++i) { Messenger::MessageDataReader_var message_dr = Messenger::MessageDataReader::_narrow(readers[i]); Messenger::MessageSeq msg; ::DDS::SampleInfoSeq si; ret = message_dr->take(msg, si, DDS::LENGTH_UNLIMITED, ::DDS::NOT_READ_SAMPLE_STATE, ::DDS::ANY_VIEW_STATE, ::DDS::ANY_INSTANCE_STATE) ; if (msg.length() != 1 || si.length() != 1) { ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: SubscriberListenerImpl::on_data_on_readers()") ACE_TEXT(" ERROR: MessageSeq %d SampleInfoSeq %d!\n"), msg.length(), si.length())); this->verify_result_ = false; } if (ret != DDS::RETCODE_OK) { ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: SubscriberListenerImpl::on_data_on_readers()") ACE_TEXT(" ERROR: read failed!\n"))); ACE_OS::exit(-1); } this->verify (msg[0], si[0], qos, false); } } else if (qos.presentation.access_scope == ::DDS::TOPIC_PRESENTATION_QOS) { // redirect datareader listener to receive DISPOSE and UNREGISTER notifications. if (len != 2) { if (subs->notify_datareaders () != ::DDS::RETCODE_OK) { ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: SubscriberListenerImpl::on_data_on_readers()") ACE_TEXT(" ERROR: notify_datareaders failed!\n"))); this->verify_result_ = false; } return; } for (CORBA::ULong i = 0; i < len; ++i) { Messenger::MessageDataReader_var message_dr = Messenger::MessageDataReader::_narrow(readers[i]); Messenger::MessageSeq msg; ::DDS::SampleInfoSeq si; ret = message_dr->take(msg, si, DDS::LENGTH_UNLIMITED, ::DDS::NOT_READ_SAMPLE_STATE, ::DDS::ANY_VIEW_STATE, ::DDS::ANY_INSTANCE_STATE) ; if (si[0].instance_state == DDS::NOT_ALIVE_DISPOSED_INSTANCE_STATE || si[0].instance_state == DDS::NOT_ALIVE_NO_WRITERS_INSTANCE_STATE) if (msg.length() != num_messages || si.length() != num_messages) { ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: SubscriberListenerImpl::on_data_on_readers()") ACE_TEXT(" ERROR: MessageSeq %d SampleInfoSeq %d !\n"), msg.length(), si.length())); this->verify_result_ = false; } if (ret != DDS::RETCODE_OK) { ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: SubscriberListenerImpl::on_data_on_readers()") ACE_TEXT(" ERROR: read failed!\n"))); ACE_OS::exit(-1); } CORBA::ULong num_samples = si.length(); for (CORBA::ULong i = 0; i < num_samples; ++i) { this->verify (msg[i], si[i], qos, i == num_samples - 1 ? true : false); } } } else { //::DDS::INSTANCE_PRESENTATION_QOS subs->notify_datareaders (); } ret = subs->end_access (); if (ret != ::DDS::RETCODE_OK) { ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: SubscriberListenerImpl::on_data_on_readers()") ACE_TEXT(" ERROR: end_access failed!\n"))); ACE_OS::exit(-1); } }