iceoryx_posh  2.0.2
subscriber_impl.hpp
1 // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
2 // Copyright (c) 2020 - 2022 by Apex.AI Inc. All rights reserved.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 // SPDX-License-Identifier: Apache-2.0
17 
18 #ifndef IOX_POSH_POPO_TYPED_SUBSCRIBER_IMPL_HPP
19 #define IOX_POSH_POPO_TYPED_SUBSCRIBER_IMPL_HPP
20 
21 #include "iceoryx_posh/internal/popo/base_subscriber.hpp"
22 #include "iceoryx_posh/internal/popo/sample_deleter.hpp"
23 #include "iceoryx_posh/internal/popo/typed_port_api_trait.hpp"
24 
25 namespace iox
26 {
27 namespace popo
28 {
31 template <typename T, typename H = iox::mepoo::NoUserHeader, typename BaseSubscriberType = BaseSubscriber<>>
32 class SubscriberImpl : public BaseSubscriberType
33 {
35 
36  using DataTypeAssert = typename TypedPortApiTrait<T>::Assert;
37  using HeaderTypeAssert = typename TypedPortApiTrait<H>::Assert;
38 
39  public:
40  explicit SubscriberImpl(const capro::ServiceDescription& service,
41  const SubscriberOptions& subscriberOptions = SubscriberOptions()) noexcept;
42  SubscriberImpl(const SubscriberImpl& other) = delete;
43  SubscriberImpl& operator=(const SubscriberImpl&) = delete;
44  SubscriberImpl(SubscriberImpl&& rhs) = delete;
45  SubscriberImpl& operator=(SubscriberImpl&& rhs) = delete;
46  virtual ~SubscriberImpl() noexcept;
47 
54  cxx::expected<Sample<const T, const H>, ChunkReceiveResult> take() noexcept;
55 
56  using PortType = typename BaseSubscriberType::PortType;
57  using SubscriberSampleDeleter = SampleDeleter<PortType>;
58 
59  protected:
60  using BaseSubscriberType::port;
61 
62  private:
63  SubscriberSampleDeleter m_sampleDeleter{port()};
64 };
65 
66 } // namespace popo
67 } // namespace iox
68 
69 #include "iceoryx_posh/internal/popo/subscriber_impl.inl"
70 
71 #endif // IOX_POSH_POPO_TYPED_SUBSCRIBER_IMPL_HPP
class for the identification of a communication event including information on the service,...
Definition: service_description.hpp:81
base class for all types of subscriber
Definition: base_subscriber.hpp:56
const port_t & port() const noexcept
const accessor of the underlying port
The SubscriberImpl class implements the typed subscriber API.
Definition: subscriber_impl.hpp:33
cxx::expected< Sample< const T, const H >, ChunkReceiveResult > take() noexcept
Take the samples from the top of the receive queue.
This struct is used to configure the subscriber.
Definition: subscriber_options.hpp:33