/* * Copyright(c) 2006 to 2021 ZettaScale Technology and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License * v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ #ifndef CYCLONEDDS_DDS_SUB_TDATAREADER_IMPL_HPP_ #define CYCLONEDDS_DDS_SUB_TDATAREADER_IMPL_HPP_ /** * @file */ /* * OMG PSM class declaration */ #include #include #include #include #include "dds/core/macros.hpp" /*************************************************************************** * * dds/sub/DataReader<> WRAPPER implementation. * Declaration can be found in dds/sub/TDataReader.hpp * ***************************************************************************/ // Implementation namespace dds { namespace sub { //-------------------------------------------------------------------------------- // DATAREADER //-------------------------------------------------------------------------------- template class DELEGATE> DataReader::Selector::Selector(DataReader& dr) : impl_(dr.delegate()) { } template class DELEGATE> typename DataReader::Selector& DataReader::Selector::instance(const dds::core::InstanceHandle& h) { impl_.instance(h); return *this; } template class DELEGATE> typename DataReader::Selector& DataReader::Selector::next_instance(const dds::core::InstanceHandle& h) { impl_.next_instance(h); return *this; } template class DELEGATE> typename DataReader::Selector& DataReader::Selector::state(const dds::sub::status::DataState& s) { impl_.filter_state(s); return *this; } template class DELEGATE> typename DataReader::Selector& DataReader::Selector::content(const dds::sub::Query& query) { impl_.filter_content(query); return *this; } template class DELEGATE> typename DataReader::Selector& DataReader::Selector::max_samples(uint32_t n) { impl_.max_samples(n); return *this; } template class DELEGATE> dds::sub::LoanedSamples DataReader::Selector::read() { return impl_.read(); } template class DELEGATE> dds::sub::LoanedSamples DataReader::Selector::take() { return impl_.take(); } template class DELEGATE> template uint32_t DataReader::Selector::read(SamplesFWIterator sfit, uint32_t max_samples) { return impl_.read(sfit, max_samples); } template class DELEGATE> template uint32_t DataReader::Selector::take(SamplesFWIterator sfit, uint32_t max_samples) { return impl_.take(sfit, max_samples); } template class DELEGATE> template uint32_t DataReader::Selector::read(SamplesBIIterator sbit) { return impl_.read(sbit); } template class DELEGATE> template uint32_t DataReader::Selector::take(SamplesBIIterator sbit) { return impl_.take(sbit); } //-------------------------------------------------------------------------------- // DATAREADER::MANIPULATORSELECTOR //-------------------------------------------------------------------------------- template class DELEGATE> DataReader::ManipulatorSelector:: ManipulatorSelector(DataReader& dr) : impl_(dr.delegate()) {} template class DELEGATE> bool DataReader::ManipulatorSelector::read_mode() { return impl_.read_mode(); } template class DELEGATE> void DataReader::ManipulatorSelector::read_mode(bool b) { impl_.read_mode(b); } template class DELEGATE> typename DataReader::ManipulatorSelector& DataReader::ManipulatorSelector::instance(const dds::core::InstanceHandle& h) { impl_.instance(h); return *this; } template class DELEGATE> typename DataReader::ManipulatorSelector& DataReader::ManipulatorSelector::next_instance(const dds::core::InstanceHandle& h) { impl_.next_instance(h); return *this; } template class DELEGATE> typename DataReader::ManipulatorSelector& DataReader::ManipulatorSelector::operator >>(dds::sub::LoanedSamples& samples) { impl_ >> samples; return *this; } template class DELEGATE> typename DataReader::ManipulatorSelector& DataReader::ManipulatorSelector::operator >> (ManipulatorSelector & (manipulator)(ManipulatorSelector&)) { manipulator(*this); return *this; } template class DELEGATE> template typename DataReader::ManipulatorSelector DataReader::ManipulatorSelector::operator >> (Functor f) { f(*this); return *this; } template class DELEGATE> typename DataReader::ManipulatorSelector& DataReader::ManipulatorSelector::state(const dds::sub::status::DataState& s) { impl_.filter_state(s); return *this; } template class DELEGATE> typename DataReader::ManipulatorSelector& DataReader::ManipulatorSelector::content(const dds::sub::Query& query) { impl_.filter_content(query); return *this; } template class DELEGATE> typename DataReader::ManipulatorSelector& DataReader::ManipulatorSelector::max_samples(uint32_t n) { impl_.max_samples(n); return *this; } template class DELEGATE> DataReader::DataReader( const dds::sub::Subscriber& sub, const dds::topic::Topic& topic): ::dds::core::Reference< DELEGATE >(new DELEGATE(sub, topic, sub->default_datareader_qos())) { this->delegate()->init(this->impl_); } template class DELEGATE> DataReader::DataReader( const dds::sub::Subscriber& sub, const ::dds::topic::Topic& topic, const dds::sub::qos::DataReaderQos& qos, dds::sub::DataReaderListener* listener, const dds::core::status::StatusMask& mask) : ::dds::core::Reference< DELEGATE >(new DELEGATE(sub, topic, qos, listener, mask)) { this->delegate()->init(this->impl_); } #ifdef OMG_DDS_CONTENT_SUBSCRIPTION_SUPPORT template class DELEGATE> DataReader::DataReader( const dds::sub::Subscriber& sub, const dds::topic::ContentFilteredTopic& topic) : ::dds::core::Reference< DELEGATE >(new DELEGATE(sub, topic, sub.default_datareader_qos())) { this->delegate()->init(this->impl_); } template class DELEGATE> DataReader::DataReader( const dds::sub::Subscriber& sub, const ::dds::topic::ContentFilteredTopic& topic, const dds::sub::qos::DataReaderQos& qos, dds::sub::DataReaderListener* listener, const dds::core::status::StatusMask& mask) : ::dds::core::Reference< DELEGATE >(new DELEGATE(sub, topic, qos, listener, mask)) { this->delegate()->init(this->impl_); } #endif /* OMG_DDS_CONTENT_SUBSCRIPTION_SUPPORT */ #ifdef OMG_DDS_MULTI_TOPIC_SUPPORT template class DELEGATE> DataReader::DataReader( const dds::sub::Subscriber& sub, const dds::topic::MultiTopic& topic) : ::dds::core::Reference< DELEGATE >(new DELEGATE(sub, topic)) { this->delegate()->init(this->impl_); } template class DELEGATE> DataReader::DataReader( const dds::sub::Subscriber& sub, const ::dds::topic::MultiTopic& topic, const dds::sub::qos::DataReaderQos& qos, dds::sub::DataReaderListener* listener, const dds::core::status::StatusMask& mask) : ::dds::core::Reference< DELEGATE >(new DELEGATE(sub, topic, qos, listener, mask)) { this->delegate()->init(this->impl_); } #endif /* OMG_DDS_MULTI_TOPIC_SUPPORT */ template class DELEGATE> dds::sub::status::DataState DataReader::default_filter_state() { return this->delegate()->default_filter_state(); } template class DELEGATE> DataReader& DataReader::default_filter_state(const dds::sub::status::DataState& status) { this->delegate()->default_filter_state(status); return *this; } template class DELEGATE> DataReader& DataReader::operator >>(dds::sub::LoanedSamples& ls) { ls = this->read(); return *this; } template class DELEGATE> typename DataReader::ManipulatorSelector DataReader::operator >> (ManipulatorSelector& (manipulator)(ManipulatorSelector&)) { ManipulatorSelector selector(*this); manipulator(selector); return selector; } template class DELEGATE> template typename DataReader::ManipulatorSelector DataReader::operator >> (Functor f) { ManipulatorSelector selector(*this); f(selector); return selector; } template class DELEGATE> LoanedSamples DataReader::read() { return this->delegate()->read(); } template class DELEGATE> LoanedSamples DataReader::take() { return this->delegate()->take(); } template class DELEGATE> template uint32_t DataReader::read(SamplesFWIterator sfit, uint32_t max_samples) { return this->delegate()->read(sfit, max_samples); } template class DELEGATE> template uint32_t DataReader::take(SamplesFWIterator sfit, uint32_t max_samples) { return this->delegate()->take(sfit, max_samples); } template class DELEGATE> template uint32_t DataReader::read(SamplesBIIterator sbit) { return this->delegate()->read(sbit); } template class DELEGATE> template uint32_t DataReader::take(SamplesBIIterator sbit) { return this->delegate()->take(sbit); } template class DELEGATE> typename DataReader::Selector DataReader::select() { Selector selector(*this); return selector; } template class DELEGATE> dds::topic::TopicInstance DataReader::key_value(const dds::core::InstanceHandle& h) { return this->delegate()->key_value(h); } template class DELEGATE> T& DataReader::key_value(T& sample, const dds::core::InstanceHandle& h) { return this->delegate()->key_value(sample, h); } template class DELEGATE> const dds::core::InstanceHandle DataReader::lookup_instance(const T& key) const { return this->delegate()->lookup_instance(key); } template class DELEGATE> void DataReader::listener( Listener* listener, const dds::core::status::StatusMask& event_mask) { this->delegate()->listener(listener, event_mask); } template class DELEGATE> typename DataReader::Listener* DataReader::listener() const { return this->delegate()->listener(); } } } /*************************************************************************** * * dds/sub/detail/DataReader<> DELEGATE implementation. * Declaration can be found in dds/sub/detail/DataReader.hpp * * Implementation and declaration have been separated because some circular * dependencies, like with DataReaderListener and AnyDataReader. * ***************************************************************************/ #include #include #include #include #include #include template dds::sub::detail::DataReader::DataReader(const dds::sub::Subscriber& sub, const dds::topic::Topic& topic, const dds::sub::qos::DataReaderQos& qos, dds::sub::DataReaderListener* listener, const dds::core::status::StatusMask& mask) : ::org::eclipse::cyclonedds::sub::AnyDataReaderDelegate(qos, topic), sub_(sub), typed_sample_() { common_constructor(listener, mask); } template dds::sub::detail::DataReader::DataReader(const dds::sub::Subscriber& sub, const dds::topic::ContentFilteredTopic& topic, const dds::sub::qos::DataReaderQos& qos, dds::sub::DataReaderListener* listener, const dds::core::status::StatusMask& mask) : ::org::eclipse::cyclonedds::sub::AnyDataReaderDelegate(qos, topic), sub_(sub), typed_sample_() { common_constructor(listener, mask); } template void dds::sub::detail::DataReader::common_constructor( dds::sub::DataReaderListener* listener, const dds::core::status::StatusMask& mask) { DDSCXX_WARNING_MSVC_OFF(4127) DDSCXX_WARNING_MSVC_OFF(6326) if (dds::topic::is_topic_type::value == 0) { ISOCPP_THROW_EXCEPTION(ISOCPP_PRECONDITION_NOT_MET_ERROR, "DataReader cannot be created, topic information not found"); } DDSCXX_WARNING_MSVC_ON(6326) DDSCXX_WARNING_MSVC_ON(4127) org::eclipse::cyclonedds::sub::qos::DataReaderQosDelegate drQos = qos_.delegate(); dds_entity_t ddsc_sub = sub_.delegate()->get_ddsc_entity(); dds_entity_t ddsc_top = this->AnyDataReaderDelegate::td_.delegate()->get_ddsc_entity(); // get and validate the ddsc qos drQos.check(); dds_qos_t* ddsc_qos = drQos.ddsc_qos(); #if 0 std::string expression = this->AnyDataReaderDelegate::td_.delegate()->reader_expression(); c_value *params = this->AnyDataReaderDelegate::td_.delegate()->reader_parameters(); #endif dds_entity_t ddsc_reader = dds_create_reader(ddsc_sub, ddsc_top, ddsc_qos, NULL); dds_delete_qos(ddsc_qos); ISOCPP_DDSC_RESULT_CHECK_AND_THROW(ddsc_reader, "Could not create DataReader."); this->AnyDataReaderDelegate::td_.delegate()->incrNrDependents(); this->AnyDataReaderDelegate::setSample(&this->typed_sample_); this->set_ddsc_entity(ddsc_reader); this->listener(listener, mask); } template dds::sub::detail::DataReader::~DataReader() { if (!this->closed) { try { close(); } catch (...) { } } } template void dds::sub::detail::DataReader::init(ObjectDelegate::weak_ref_type weak_ref) { /* Set weak_ref before passing ourselves to other isocpp objects. */ this->set_weak_ref(weak_ref); /* Add weak_ref to the map of entities */ this->add_to_entity_map(weak_ref); /* Add the datareader to the datareader set of the subscriber */ this->sub_.delegate()->add_datareader(*this); // Because listeners are added after reader is created (which is in enabled state, because // disabled state is not yet supported), events could have occured before listeners were // registered. Therefore the event handlers for those events are called here. if (this->listener_get()) { dds::core::status::StatusMask readerStatus = status_changes(); if (listener_mask.to_ulong() & dds::core::status::StatusMask::data_available().to_ulong() && readerStatus.test(DDS_DATA_AVAILABLE_STATUS_ID)) { on_data_available(this->ddsc_entity); } if (listener_mask.to_ulong() & dds::core::status::StatusMask::liveliness_changed().to_ulong() && readerStatus.test(DDS_LIVELINESS_CHANGED_STATUS_ID)) { dds::core::status::LivelinessChangedStatus status = liveliness_changed_status(); on_liveliness_changed(this->ddsc_entity, status); } if (listener_mask.to_ulong() & dds::core::status::StatusMask::requested_deadline_missed().to_ulong() && readerStatus.test(DDS_REQUESTED_DEADLINE_MISSED_STATUS_ID)) { dds::core::status::RequestedDeadlineMissedStatus status = requested_deadline_missed_status(); on_requested_deadline_missed(this->ddsc_entity, status); } if (listener_mask.to_ulong() & dds::core::status::StatusMask::requested_incompatible_qos().to_ulong() && readerStatus.test(DDS_REQUESTED_INCOMPATIBLE_QOS_STATUS_ID)) { dds::core::status::RequestedIncompatibleQosStatus status = requested_incompatible_qos_status(); on_requested_incompatible_qos(this->ddsc_entity, status); } if (listener_mask.to_ulong() & dds::core::status::StatusMask::sample_lost().to_ulong() && readerStatus.test(DDS_SAMPLE_LOST_STATUS_ID)) { dds::core::status::SampleLostStatus status = sample_lost_status(); on_sample_lost(this->ddsc_entity, status); } if (listener_mask.to_ulong() & dds::core::status::StatusMask::sample_rejected().to_ulong() && readerStatus.test(DDS_SAMPLE_REJECTED_STATUS_ID)) { dds::core::status::SampleRejectedStatus status = sample_rejected_status(); on_sample_rejected(this->ddsc_entity, status); } if (listener_mask.to_ulong() & dds::core::status::StatusMask::subscription_matched().to_ulong() && readerStatus.test(DDS_SUBSCRIPTION_MATCHED_STATUS_ID)) { dds::core::status::SubscriptionMatchedStatus status = subscription_matched_status(); on_subscription_matched(this->ddsc_entity, status); } } this->enable(); } template dds::sub::status::DataState dds::sub::detail::DataReader::default_filter_state() { org::eclipse::cyclonedds::core::ScopedObjectLock scopedLock(*this); dds::sub::status::DataState state = this->status_filter_; scopedLock.unlock(); return state; } template void dds::sub::detail::DataReader::default_filter_state(const dds::sub::status::DataState& state) { org::eclipse::cyclonedds::core::ScopedObjectLock scopedLock(*this); this->status_filter_ = state; scopedLock.unlock(); } template bool dds::sub::detail::DataReader::is_loan_supported() { this->check(); return this->AnyDataReaderDelegate::is_loan_supported(static_cast(this->ddsc_entity)); } template dds::sub::LoanedSamples dds::sub::detail::DataReader::read_cdr() { dds::sub::LoanedSamples samples; dds::sub::detail::CDRSamplesHolder holder(samples); this->AnyDataReaderDelegate::read_cdr(static_cast(this->ddsc_entity), this->status_filter_, holder, static_cast(dds::core::LENGTH_UNLIMITED)); return samples; } template dds::sub::LoanedSamples dds::sub::detail::DataReader::take_cdr() { dds::sub::LoanedSamples samples; dds::sub::detail::CDRSamplesHolder holder(samples); this->AnyDataReaderDelegate::take_cdr(static_cast(this->ddsc_entity), this->status_filter_, holder, static_cast(dds::core::LENGTH_UNLIMITED)); return samples; } template dds::sub::LoanedSamples dds::sub::detail::DataReader::read() { dds::sub::LoanedSamples samples; dds::sub::detail::LoanedSamplesHolder holder(samples); this->AnyDataReaderDelegate::loaned_read(static_cast(this->ddsc_entity), this->status_filter_, holder, static_cast(dds::core::LENGTH_UNLIMITED)); return samples; } template dds::sub::LoanedSamples dds::sub::detail::DataReader::take() { dds::sub::LoanedSamples samples; dds::sub::detail::LoanedSamplesHolder holder(samples); this->AnyDataReaderDelegate::loaned_take(static_cast(this->ddsc_entity), this->status_filter_, holder, static_cast(dds::core::LENGTH_UNLIMITED)); return samples; } template template uint32_t dds::sub::detail::DataReader::read(SamplesFWIterator samples, uint32_t max_samples) { dds::sub::detail::SamplesFWInteratorHolder holder(samples); this->AnyDataReaderDelegate::read(static_cast(this->ddsc_entity), this->status_filter_, holder, max_samples); return holder.get_length(); } template template uint32_t dds::sub::detail::DataReader::take(SamplesFWIterator samples, uint32_t max_samples) { dds::sub::detail::SamplesFWInteratorHolder holder(samples); this->AnyDataReaderDelegate::take(static_cast(this->ddsc_entity), this->status_filter_, holder, max_samples); return holder.get_length(); } template template uint32_t dds::sub::detail::DataReader::read(SamplesBIIterator samples) { dds::sub::detail::SamplesBIIteratorHolder holder(samples); this->AnyDataReaderDelegate::read(static_cast(this->ddsc_entity), this->status_filter_, holder, static_cast(dds::core::LENGTH_UNLIMITED)); return holder.get_length(); } template template uint32_t dds::sub::detail::DataReader::take(SamplesBIIterator samples) { dds::sub::detail::SamplesBIIteratorHolder holder(samples); this->AnyDataReaderDelegate::take(static_cast(this->ddsc_entity), this->status_filter_, holder, static_cast(dds::core::LENGTH_UNLIMITED)); return holder.get_length(); } template dds::topic::TopicInstance dds::sub::detail::DataReader::key_value(const dds::core::InstanceHandle& h) { T key_holder; this->AnyDataReaderDelegate::get_key_value(static_cast(this->ddsc_entity), h, &key_holder); return dds::topic::TopicInstance(h, key_holder); } template T& dds::sub::detail::DataReader::key_value(T& key, const dds::core::InstanceHandle& h) { this->AnyDataReaderDelegate::get_key_value(static_cast(this->ddsc_entity), h, &key); return key; } template const dds::core::InstanceHandle dds::sub::detail::DataReader::lookup_instance(const T& key) const { dds::core::InstanceHandle handle(this->AnyDataReaderDelegate::lookup_instance(static_cast(this->ddsc_entity), &key)); return handle; } template const dds::sub::Subscriber& dds::sub::detail::DataReader::subscriber() const { this->check(); return sub_; } template void dds::sub::detail::DataReader::close() { this->prevent_callbacks(); org::eclipse::cyclonedds::core::ScopedObjectLock scopedLock(*this); this->listener_set(NULL, dds::core::status::StatusMask::none()); this->sub_.delegate()->remove_datareader(*this); // Remove our dependency on the topicdescription, and drop our reference to it, // so that it can become garbage collected. // It is important that we also drop our reference to the topicdescription, since // subsequent dependencies between for example ContentFilteredTopic to Topic can // only be dropped by the destructor of the ContentFilteredTopic. this->AnyDataReaderDelegate::td_.delegate()->decrNrDependents(); this->AnyDataReaderDelegate::td_ = dds::topic::TopicDescription(dds::core::null); org::eclipse::cyclonedds::sub::AnyDataReaderDelegate::close(); scopedLock.unlock(); } template dds::sub::DataReaderListener* dds::sub::detail::DataReader::listener() { this->check(); return reinterpret_cast*>(this->listener_get()); } template void dds::sub::detail::DataReader::listener( dds::sub::DataReaderListener* l, const dds::core::status::StatusMask& event_mask) { org::eclipse::cyclonedds::core::ScopedObjectLock scopedLock(*this); this->listener_set( l, event_mask ) ; scopedLock.unlock(); } template dds::sub::DataReader dds::sub::detail::DataReader::wrapper() { typename DataReader::ref_type ref = ::std::dynamic_pointer_cast >(this->get_strong_ref()); dds::sub::DataReader reader(ref); return reader; } template dds::sub::detail::DataReader::Selector::Selector(typename DataReader::ref_type dr) : mode(SELECT_MODE_READ), reader(dr), state_filter_is_set_(false), max_samples_(static_cast(dds::core::LENGTH_UNLIMITED)), query_(dds::core::null) { } template typename dds::sub::detail::DataReader::Selector& dds::sub::detail::DataReader::Selector::instance(const dds::core::InstanceHandle& h) { this->handle = h; switch (this->mode) { case SELECT_MODE_READ: case SELECT_MODE_READ_INSTANCE: case SELECT_MODE_READ_NEXT_INSTANCE: this->mode = SELECT_MODE_READ_INSTANCE; break; case SELECT_MODE_READ_WITH_CONDITION: case SELECT_MODE_READ_INSTANCE_WITH_CONDITION: case SELECT_MODE_READ_NEXT_INSTANCE_WITH_CONDITION: this->mode = SELECT_MODE_READ_INSTANCE_WITH_CONDITION; break; } return *this; } template typename dds::sub::detail::DataReader::Selector& dds::sub::detail::DataReader::Selector::next_instance(const dds::core::InstanceHandle& h) { this->handle = h; switch (this->mode) { case SELECT_MODE_READ: case SELECT_MODE_READ_INSTANCE: case SELECT_MODE_READ_NEXT_INSTANCE: this->mode = SELECT_MODE_READ_NEXT_INSTANCE; break; case SELECT_MODE_READ_WITH_CONDITION: case SELECT_MODE_READ_INSTANCE_WITH_CONDITION: case SELECT_MODE_READ_NEXT_INSTANCE_WITH_CONDITION: this->mode = SELECT_MODE_READ_NEXT_INSTANCE_WITH_CONDITION; break; } return *this; } template typename dds::sub::detail::DataReader::Selector& dds::sub::detail::DataReader::Selector::filter_state(const dds::sub::status::DataState& s) { this->state_filter_ = s; this->state_filter_is_set_ = true; if ((this->mode == SELECT_MODE_READ_WITH_CONDITION) || (this->mode == SELECT_MODE_READ_INSTANCE_WITH_CONDITION) || (this->mode == SELECT_MODE_READ_NEXT_INSTANCE_WITH_CONDITION)) { if (!this->query_.delegate()->modify_state_filter(this->state_filter_)) { dds::sub::Query q(this->query_.data_reader(), this->query_.expression(), this->query_.delegate()->parameters()); q.delegate()->state_filter(this->state_filter_); this->query_ = q; } } return *this; } template typename dds::sub::detail::DataReader::Selector& dds::sub::detail::DataReader::Selector::max_samples(uint32_t n) { this->max_samples_ = n; return *this; } template typename dds::sub::detail::DataReader::Selector& dds::sub::detail::DataReader::Selector::filter_content( const dds::sub::Query& query) { ISOCPP_THROW_EXCEPTION(ISOCPP_UNSUPPORTED_ERROR, "Read with queries not currently supported"); this->query_ = query; switch (this->mode) { case SELECT_MODE_READ: case SELECT_MODE_READ_INSTANCE: case SELECT_MODE_READ_NEXT_INSTANCE: this->mode = SELECT_MODE_READ_WITH_CONDITION; break; default: break; } return *this; } template dds::sub::LoanedSamples dds::sub::detail::DataReader::Selector::read() { return this->reader->read(*this); } template dds::sub::LoanedSamples dds::sub::detail::DataReader::Selector::take() { return this->reader->take(*this); } // --- Forward Iterators: --- // template template uint32_t dds::sub::detail::DataReader::Selector::read(SamplesFWIterator sfit, uint32_t max_samples) { return this->reader->read(sfit, max_samples, *this); } template template uint32_t dds::sub::detail::DataReader::Selector::take(SamplesFWIterator sfit, uint32_t max_samples) { return this->reader->take(sfit, max_samples, *this); } // --- Back-Inserting Iterators: --- // template template uint32_t dds::sub::detail::DataReader::Selector::read(SamplesBIIterator sbit) { return this->reader->read(sbit, *this); } template template uint32_t dds::sub::detail::DataReader::Selector::take(SamplesBIIterator sbit) { return this->reader->take(sbit, *this); } template typename dds::sub::detail::DataReader::SelectMode dds::sub::detail::DataReader::Selector::get_mode() const { return this->mode; } template dds::sub::detail::DataReader::ManipulatorSelector::ManipulatorSelector(typename DataReader::ref_type dr) : Selector(dr), read_mode_(true) { } template bool dds::sub::detail::DataReader::ManipulatorSelector::read_mode() { return read_mode_; } template void dds::sub::detail::DataReader::ManipulatorSelector::read_mode(bool b) { read_mode_ = b; } template typename dds::sub::detail::DataReader::ManipulatorSelector& dds::sub::detail::DataReader::ManipulatorSelector::operator >>(dds::sub::LoanedSamples& samples) { if(read_mode_) { samples = this->Selector::read(); } else { samples = this->Selector::take(); } return *this; } template dds::sub::LoanedSamples dds::sub::detail::DataReader::read(const Selector& selector) { dds::sub::LoanedSamples samples; dds::sub::detail::LoanedSamplesHolder holder(samples); switch(selector.mode) { case SELECT_MODE_READ: this->AnyDataReaderDelegate::loaned_read(static_cast(this->ddsc_entity), selector.state_filter_, holder, selector.max_samples_); break; case SELECT_MODE_READ_INSTANCE: this->AnyDataReaderDelegate::loaned_read_instance(static_cast(this->ddsc_entity), selector.handle, selector.state_filter_, holder, selector.max_samples_); break; case SELECT_MODE_READ_NEXT_INSTANCE: this->AnyDataReaderDelegate::loaned_read_next_instance(static_cast(this->ddsc_entity), selector.handle, selector.state_filter_, holder, selector.max_samples_); break; case SELECT_MODE_READ_WITH_CONDITION: /* When SQL queries and QueryContitions are supported, then * create a QueryContitions from the Query and Reader status_filter_. * Use the resulting condition entity to read. */ break; case SELECT_MODE_READ_INSTANCE_WITH_CONDITION: /* When SQL queries and QueryContitions are supported, then * create a QueryContitions from the Query and Reader status_filter_. * Use the resulting condition entity to read. */ break; case SELECT_MODE_READ_NEXT_INSTANCE_WITH_CONDITION: /* When SQL queries and QueryContitions are supported, then * create a QueryContitions from the Query and Reader status_filter_. * Use the resulting condition entity to read. */ break; } return samples; } template dds::sub::LoanedSamples dds::sub::detail::DataReader::take(const Selector& selector) { dds::sub::LoanedSamples samples; dds::sub::detail::LoanedSamplesHolder holder(samples); switch(selector.mode) { case SELECT_MODE_READ: this->AnyDataReaderDelegate::loaned_take(static_cast(this->ddsc_entity), selector.state_filter_, holder, selector.max_samples_); break; case SELECT_MODE_READ_INSTANCE: this->AnyDataReaderDelegate::loaned_take_instance(static_cast(this->ddsc_entity), selector.handle, selector.state_filter_, holder, selector.max_samples_); break; case SELECT_MODE_READ_NEXT_INSTANCE: this->AnyDataReaderDelegate::loaned_take_next_instance(static_cast(this->ddsc_entity), selector.handle, selector.state_filter_, holder, selector.max_samples_); break; case SELECT_MODE_READ_WITH_CONDITION: /* When SQL queries and QueryContitions are supported, then * create a QueryContitions from the Query and Reader status_filter_. * Use the resulting condition entity to read. */ break; case SELECT_MODE_READ_INSTANCE_WITH_CONDITION: /* When SQL queries and QueryContitions are supported, then * create a QueryContitions from the Query and Reader status_filter_. * Use the resulting condition entity to read. */ break; case SELECT_MODE_READ_NEXT_INSTANCE_WITH_CONDITION: /* When SQL queries and QueryContitions are supported, then * create a QueryContitions from the Query and Reader status_filter_. * Use the resulting condition entity to read. */ break; } return samples; } // --- Forward Iterators: --- // template template uint32_t dds::sub::detail::DataReader::read(SamplesFWIterator samples, uint32_t max_samples, const Selector& selector) { dds::sub::detail::SamplesFWInteratorHolder holder(samples); max_samples = std::min(max_samples, selector.max_samples_); switch(selector.mode) { case SELECT_MODE_READ: this->AnyDataReaderDelegate::read(static_cast(this->ddsc_entity), selector.state_filter_, holder, max_samples); break; case SELECT_MODE_READ_INSTANCE: this->AnyDataReaderDelegate::read_instance(static_cast(this->ddsc_entity), selector.handle, selector.state_filter_, holder, max_samples); break; case SELECT_MODE_READ_NEXT_INSTANCE: this->AnyDataReaderDelegate::read_next_instance(static_cast(this->ddsc_entity), selector.handle, selector.state_filter_, holder, max_samples); break; case SELECT_MODE_READ_WITH_CONDITION: /* When SQL queries and QueryContitions are supported, then * create a QueryContitions from the Query and Reader status_filter_. * Use the resulting condition entity to read. */ break; case SELECT_MODE_READ_INSTANCE_WITH_CONDITION: /* When SQL queries and QueryContitions are supported, then * create a QueryContitions from the Query and Reader status_filter_. * Use the resulting condition entity to read. */ break; case SELECT_MODE_READ_NEXT_INSTANCE_WITH_CONDITION: /* When SQL queries and QueryContitions are supported, then * create a QueryContitions from the Query and Reader status_filter_. * Use the resulting condition entity to read. */ break; } return holder.get_length(); } template template uint32_t dds::sub::detail::DataReader::take(SamplesFWIterator samples, uint32_t max_samples, const Selector& selector) { dds::sub::detail::SamplesFWInteratorHolder holder(samples); max_samples = std::min(max_samples, selector.max_samples_); switch(selector.mode) { case SELECT_MODE_READ: this->AnyDataReaderDelegate::take(static_cast(this->ddsc_entity), selector.state_filter_, holder, max_samples); break; case SELECT_MODE_READ_INSTANCE: this->AnyDataReaderDelegate::take_instance(static_cast(this->ddsc_entity), selector.handle, selector.state_filter_, holder, max_samples); break; case SELECT_MODE_READ_NEXT_INSTANCE: this->AnyDataReaderDelegate::take_next_instance(static_cast(this->ddsc_entity), selector.handle, selector.state_filter_, holder, max_samples); break; case SELECT_MODE_READ_WITH_CONDITION: /* When SQL queries and QueryContitions are supported, then * create a QueryContitions from the Query and Reader status_filter_. * Use the resulting condition entity to read. */ break; case SELECT_MODE_READ_INSTANCE_WITH_CONDITION: /* When SQL queries and QueryContitions are supported, then * create a QueryContitions from the Query and Reader status_filter_. * Use the resulting condition entity to read. */ break; case SELECT_MODE_READ_NEXT_INSTANCE_WITH_CONDITION: /* When SQL queries and QueryContitions are supported, then * create a QueryContitions from the Query and Reader status_filter_. * Use the resulting condition entity to read. */ break; } return holder.get_length(); } // --- Back-Inserting Iterators: --- // template template uint32_t dds::sub::detail::DataReader::read(SamplesBIIterator samples, const Selector& selector) { dds::sub::detail::SamplesBIIteratorHolder holder(samples); switch(selector.mode) { case SELECT_MODE_READ: this->AnyDataReaderDelegate::read(static_cast(this->ddsc_entity), selector.state_filter_, holder, selector.max_samples_); break; case SELECT_MODE_READ_INSTANCE: this->AnyDataReaderDelegate::read_instance(static_cast(this->ddsc_entity), selector.handle, selector.state_filter_, holder, selector.max_samples_); break; case SELECT_MODE_READ_NEXT_INSTANCE: this->AnyDataReaderDelegate::read_next_instance(static_cast(this->ddsc_entity), selector.handle, selector.state_filter_, holder, selector.max_samples_); break; case SELECT_MODE_READ_WITH_CONDITION: /* When SQL queries and QueryContitions are supported, then * create a QueryContitions from the Query and Reader status_filter_. * Use the resulting condition entity to read. */ break; case SELECT_MODE_READ_INSTANCE_WITH_CONDITION: /* When SQL queries and QueryContitions are supported, then * create a QueryContitions from the Query and Reader status_filter_. * Use the resulting condition entity to read. */ break; case SELECT_MODE_READ_NEXT_INSTANCE_WITH_CONDITION: /* When SQL queries and QueryContitions are supported, then * create a QueryContitions from the Query and Reader status_filter_. * Use the resulting condition entity to read. */ break; } return holder.get_length(); } template template uint32_t dds::sub::detail::DataReader::take(SamplesBIIterator samples, const Selector& selector) { dds::sub::detail::SamplesBIIteratorHolder holder(samples); switch(selector.mode) { case SELECT_MODE_READ: this->AnyDataReaderDelegate::take(static_cast(this->ddsc_entity), selector.state_filter_, holder, selector.max_samples_); break; case SELECT_MODE_READ_INSTANCE: this->AnyDataReaderDelegate::take_instance(static_cast(this->ddsc_entity), selector.handle, selector.state_filter_, holder, selector.max_samples_); break; case SELECT_MODE_READ_NEXT_INSTANCE: this->AnyDataReaderDelegate::take_next_instance(static_cast(this->ddsc_entity), selector.handle, selector.state_filter_, holder, selector.max_samples_); break; case SELECT_MODE_READ_WITH_CONDITION: /* When SQL queries and QueryContitions are supported, then * create a QueryContitions from the Query and Reader status_filter_. * Use the resulting condition entity to read. */ break; case SELECT_MODE_READ_INSTANCE_WITH_CONDITION: /* When SQL queries and QueryContitions are supported, then * create a QueryContitions from the Query and Reader status_filter_. * Use the resulting condition entity to read. */ break; case SELECT_MODE_READ_NEXT_INSTANCE_WITH_CONDITION: /* When SQL queries and QueryContitions are supported, then * create a QueryContitions from the Query and Reader status_filter_. * Use the resulting condition entity to read. */ break; } return holder.get_length(); } namespace dds { namespace sub { template SELECTOR& read(SELECTOR& selector) { selector.read_mode(true); return selector; } template SELECTOR& take(SELECTOR& selector) { selector.read_mode(false); return selector; } inline dds::sub::functors::MaxSamplesManipulatorFunctor max_samples(uint32_t n) { return dds::sub::functors::MaxSamplesManipulatorFunctor(n); } inline dds::sub::functors::ContentFilterManipulatorFunctor content(const dds::sub::Query& query) { return dds::sub::functors::ContentFilterManipulatorFunctor(query); } inline dds::sub::functors::StateFilterManipulatorFunctor state(const dds::sub::status::DataState& s) { return dds::sub::functors::StateFilterManipulatorFunctor(s); } inline dds::sub::functors::InstanceManipulatorFunctor instance(const dds::core::InstanceHandle& h) { return dds::sub::functors::InstanceManipulatorFunctor(h); } inline dds::sub::functors::NextInstanceManipulatorFunctor next_instance(const dds::core::InstanceHandle& h) { return dds::sub::functors::NextInstanceManipulatorFunctor(h); } } } template void dds::sub::detail::DataReader::on_requested_deadline_missed(dds_entity_t, org::eclipse::cyclonedds::core::RequestedDeadlineMissedStatusDelegate &sd) { dds::core::status::RequestedDeadlineMissedStatus s; s.delegate() = sd; dds::sub::DataReader dr = wrapper(); dds::sub::DataReaderListener *l = reinterpret_cast *>(this->listener_get()); l->on_requested_deadline_missed(dr, s); } template void dds::sub::detail::DataReader::on_requested_incompatible_qos(dds_entity_t, org::eclipse::cyclonedds::core::RequestedIncompatibleQosStatusDelegate &sd) { dds::core::status::RequestedIncompatibleQosStatus s; s.delegate() = sd; dds::sub::DataReader dr = wrapper(); dds::sub::DataReaderListener *l = reinterpret_cast *>(this->listener_get()); l->on_requested_incompatible_qos(dr, s); } template void dds::sub::detail::DataReader::on_sample_rejected(dds_entity_t, org::eclipse::cyclonedds::core::SampleRejectedStatusDelegate &sd) { dds::core::status::SampleRejectedStatus s; s.delegate() = sd; dds::sub::DataReader dr = wrapper(); dds::sub::DataReaderListener *l = reinterpret_cast *>(this->listener_get()); l->on_sample_rejected(dr, s); } template void dds::sub::detail::DataReader::on_liveliness_changed(dds_entity_t, org::eclipse::cyclonedds::core::LivelinessChangedStatusDelegate &sd) { dds::core::status::LivelinessChangedStatus s; s.delegate() = sd; dds::sub::DataReader dr = wrapper(); dds::sub::DataReaderListener *l = reinterpret_cast *>(this->listener_get()); l->on_liveliness_changed(dr, s); } template void dds::sub::detail::DataReader::on_data_available(dds_entity_t) { dds::sub::DataReader dr = wrapper(); dds::sub::DataReaderListener *l = reinterpret_cast *>(this->listener_get()); l->on_data_available(dr); } template void dds::sub::detail::DataReader::on_subscription_matched(dds_entity_t, org::eclipse::cyclonedds::core::SubscriptionMatchedStatusDelegate &sd) { dds::core::status::SubscriptionMatchedStatus s; s.delegate() = sd; dds::sub::DataReader dr = wrapper(); dds::sub::DataReaderListener *l = reinterpret_cast *>(this->listener_get()); l->on_subscription_matched(dr, s); } template void dds::sub::detail::DataReader::on_sample_lost(dds_entity_t, org::eclipse::cyclonedds::core::SampleLostStatusDelegate &sd) { dds::core::status::SampleLostStatus s; s.delegate() = sd; dds::sub::DataReader dr = wrapper(); dds::sub::DataReaderListener *l = reinterpret_cast *>(this->listener_get()); l->on_sample_lost(dr, s); } // End of implementation #endif /* CYCLONEDDS_DDS_SUB_TDATAREADER_IMPL_HPP_ */