OpenSplice ISO C++ 2 DCPS  v6.x
ISO C++ 2 OpenSplice Data Distribution Service Data-Centric Publish-Subscribe API
DataReader.hpp
Go to the documentation of this file.
1 /*
2  * Vortex OpenSplice
3  *
4  * This software and documentation are Copyright 2006 to 2021 ADLINK
5  * Technology Limited, its affiliated companies and licensors. All rights
6  * reserved.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 #ifndef OMG_DDS_SUB_DETAIL_DATA_READER_HPP_
21 #define OMG_DDS_SUB_DETAIL_DATA_READER_HPP_
22 
23 #include <dds/topic/Topic.hpp>
25 
30 #include <dds/sub/Subscriber.hpp>
31 #include <dds/sub/Query.hpp>
32 
33 #include <org/opensplice/core/EntityDelegate.hpp>
34 #include <org/opensplice/sub/AnyDataReaderDelegate.hpp>
35 
36 #include <org/opensplice/core/ScopedLock.hpp>
37 #include <org/opensplice/ForwardDeclarations.hpp>
38 
39 
46 /***************************************************************************
47  *
48  * dds/sub/detail/DataReader<> DELEGATE declaration.
49  * Implementation can be found in dds/sub/detail/TDataReaderImpl.hpp
50  *
51  ***************************************************************************/
52 template <typename T>
53 class dds::sub::detail::DataReader : public ::org::opensplice::sub::AnyDataReaderDelegate
54 {
55 public:
56 
57  typedef typename ::dds::core::smart_ptr_traits< DataReader<T> >::ref_type ref_type;
58  typedef typename ::dds::core::smart_ptr_traits< DataReader<T> >::weak_ref_type weak_ref_type;
59 
60  DataReader(const dds::sub::Subscriber& sub,
61  const dds::topic::Topic<T>& topic,
63  dds::sub::DataReaderListener<T>* listener = NULL,
65 
66  DataReader(const dds::sub::Subscriber& sub,
69  dds::sub::DataReaderListener<T>* listener = NULL,
71 
72  void common_constructor(dds::sub::DataReaderListener<T>* listener,
73  const dds::core::status::StatusMask& mask);
74 
75  virtual ~DataReader();
76 
77  void init(ObjectDelegate::weak_ref_type weak_ref);
78 
79  dds::sub::status::DataState default_filter_state();
80  void default_filter_state(const dds::sub::status::DataState& state);
81 
84 
85  template<typename SamplesFWIterator>
86  uint32_t read(SamplesFWIterator samples, uint32_t max_samples);
87  template<typename SamplesFWIterator>
88  uint32_t take(SamplesFWIterator samples, uint32_t max_samples);
89 
90  template<typename SamplesBIIterator>
91  uint32_t read(SamplesBIIterator samples);
92  template<typename SamplesBIIterator>
93  uint32_t take(SamplesBIIterator samples);
94 
96  T& key_value(T& key, const dds::core::InstanceHandle& h);
97 
98  const dds::core::InstanceHandle lookup_instance(const T& key) const;
99 
100  virtual const dds::sub::Subscriber& subscriber() const;
101 
102  void close();
103 
105  void listener(dds::sub::DataReaderListener<T>* l,
106  const dds::core::status::StatusMask& event_mask);
107 
109 
110  virtual void listener_notify(ObjectDelegate::ref_type source,
111  uint32_t triggerMask,
112  void *eventData,
113  void *listener);
114 
115 private:
117  dds::sub::status::DataState status_filter_;
118 
119 
120 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
121 private:
122  enum SelectMode {
123  SELECT_MODE_READ,
124  SELECT_MODE_READ_INSTANCE,
125  SELECT_MODE_READ_NEXT_INSTANCE,
126  SELECT_MODE_READ_WITH_CONDITION,
127  SELECT_MODE_READ_INSTANCE_WITH_CONDITION,
128  SELECT_MODE_READ_NEXT_INSTANCE_WITH_CONDITION
129  };
130 
131 
132 public:
133 
134  class Selector
135  {
136  public:
137  Selector(typename DataReader<T>::ref_type dr);
138 
139  Selector& instance(const dds::core::InstanceHandle& h);
140  Selector& next_instance(const dds::core::InstanceHandle& h);
141  Selector& filter_state(const dds::sub::status::DataState& s);
142  Selector& max_samples(uint32_t n);
143  Selector& filter_content(const dds::sub::Query& query);
144 
147 
148  // --- Forward Iterators: --- //
149  template<typename SamplesFWIterator>
150  uint32_t read(SamplesFWIterator sfit, uint32_t max_samples);
151  template<typename SamplesFWIterator>
152  uint32_t take(SamplesFWIterator sfit, uint32_t max_samples);
153 
154  // --- Back-Inserting Iterators: --- //
155  template<typename SamplesBIIterator>
156  uint32_t read(SamplesBIIterator sbit);
157  template<typename SamplesBIIterator>
158  uint32_t take(SamplesBIIterator sbit);
159 
160  SelectMode get_mode() const;
161 
162  DataReader<T> * get_reader() const {
163  return this->reader.get();
164  }
165 
166  private:
167  friend class DataReader;
168  SelectMode mode;
169  typename DataReader<T>::ref_type reader;
170  dds::sub::status::DataState state_filter_;
171  bool state_filter_is_set_;
173  uint32_t max_samples_;
174  dds::sub::Query query_;
175  };
176 
177 
178  class ManipulatorSelector: public Selector
179  {
180  public:
181  //ManipulatorSelector(DataReader<T>* dr);
182  ManipulatorSelector(typename DataReader<T>::ref_type dr);
183 
184  bool read_mode();
185  void read_mode(bool b);
186 
187  ManipulatorSelector&
188  operator >>(dds::sub::LoanedSamples<T>& samples);
189 
190  private:
191  bool read_mode_;
192  };
193 
194 
195 private:
196  // ==============================================================
197  // == Selector Read/Take API
198 
199  dds::sub::LoanedSamples<T> read(const Selector& selector);
200 
201  dds::sub::LoanedSamples<T> take(const Selector& selector);
202 
203  // --- Forward Iterators: --- //
204  template<typename SamplesFWIterator>
205  uint32_t read(SamplesFWIterator samples,
206  uint32_t max_samples, const Selector& selector);
207 
208  template<typename SamplesFWIterator>
209  uint32_t take(SamplesFWIterator samples,
210  uint32_t max_samples, const Selector& selector);
211 
212  // --- Back-Inserting Iterators: --- //
213  template<typename SamplesBIIterator>
214  uint32_t read(SamplesBIIterator samples, const Selector& selector);
215 
216  template<typename SamplesBIIterator>
217  uint32_t take(SamplesBIIterator samples, const Selector& selector);
218 
219 };
220 
223 #endif /* OMG_TDDS_SUB_DETAIL_DATA_READER_HPP_ */
224 
DataReader events Listener.
Definition: DataReader.hpp:37
A Subscriber is the object responsible for the actual reception of the data resulting from its subscr...
Definition: Subscriber.hpp:53
dds::sub::functors::MaxSamplesManipulatorFunctor max_samples(uint32_t n)
static StatusMask none()
Definition: State.hpp:205
A TopicInstance encapsulates a dds::sub::Sample and its associated dds::core::InstanceHandle.
Topic is the most basic description of the data to be published and subscribed.
Definition: Topic.hpp:36
This class provides the basic mechanism for an application to specify Quality of Service attributes f...
ContentFilteredTopic is a specialization of TopicDescription that allows for content-based subscripti...
Query objects contain expressions that allow the application to specify a filter on the locally avail...
Definition: Query.hpp:61
DataReader allows the applicatin to access published sample data.
Definition: DataReader.hpp:34
Class to hold sample DataState information.
Definition: DataState.hpp:371
SELECTOR & take(SELECTOR &selector)
dds::sub::functors::NextInstanceManipulatorFunctor next_instance(const dds::core::InstanceHandle &h)
Class to hold the handle associated with in sample instance.
SELECTOR & read(SELECTOR &selector)
dds::sub::functors::StateFilterManipulatorFunctor state(const dds::sub::status::DataState &s)
StatusMask is a bitmap or bitset field.
Definition: State.hpp:144
This class encapsulates and automates the management of loaned samples.
dds::sub::functors::InstanceManipulatorFunctor instance(const dds::core::InstanceHandle &h)