iceoryx_doc  1.0.1
subscriber_port_user.hpp
1 // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
2 // Copyright (c) 2021 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_POPO_SUBSCRIBER_PORT_USER_HPP_
19 #define IOX_POPO_SUBSCRIBER_PORT_USER_HPP_
20 
21 #include "iceoryx_posh/internal/popo/building_blocks/chunk_receiver.hpp"
22 #include "iceoryx_posh/internal/popo/ports/base_port.hpp"
23 #include "iceoryx_posh/internal/popo/ports/subscriber_port_data.hpp"
24 #include "iceoryx_posh/mepoo/chunk_header.hpp"
25 #include "iceoryx_posh/popo/subscriber_options.hpp"
26 #include "iceoryx_utils/cxx/expected.hpp"
27 #include "iceoryx_utils/cxx/helplets.hpp"
28 #include "iceoryx_utils/cxx/optional.hpp"
29 #include "iceoryx_utils/error_handling/error_handling.hpp"
30 
31 namespace iox
32 {
33 namespace popo
34 {
41 {
42  public:
44 
45  explicit SubscriberPortUser(cxx::not_null<MemberType_t* const> subscriberPortDataPtr) noexcept;
46 
47  SubscriberPortUser(const SubscriberPortUser& other) = delete;
48  SubscriberPortUser& operator=(const SubscriberPortUser&) = delete;
49  SubscriberPortUser(SubscriberPortUser&& rhs) = default;
50  SubscriberPortUser& operator=(SubscriberPortUser&& rhs) = default;
51  ~SubscriberPortUser() = default;
52 
54  void subscribe() noexcept;
55 
57  void unsubscribe() noexcept;
58 
63  SubscribeState getSubscriptionState() const noexcept;
64 
69  cxx::expected<const mepoo::ChunkHeader*, ChunkReceiveResult> tryGetChunk() noexcept;
70 
73  void releaseChunk(const mepoo::ChunkHeader* const chunkHeader) noexcept;
74 
76  void releaseQueuedChunks() noexcept;
77 
80  bool hasNewChunks() const noexcept;
81 
84  bool hasLostChunksSinceLastCall() noexcept;
85 
87  void setConditionVariable(ConditionVariableData& conditionVariableData, const uint64_t notificationIndex) noexcept;
88 
90  void unsetConditionVariable() noexcept;
91 
94  bool isConditionVariableSet() noexcept;
95 
96  private:
97  const MemberType_t* getMembers() const noexcept;
98  MemberType_t* getMembers() noexcept;
99 
100  ChunkReceiver<SubscriberPortData::ChunkReceiverData_t> m_chunkReceiver;
101 };
102 
103 } // namespace popo
104 } // namespace iox
105 
106 
107 #endif
this class is the base for all ports. it is constructed from a member pointer and is only movable....
Definition: base_port.hpp:43
The ChunkReceiver is a building block of the shared memory communication infrastructure....
Definition: chunk_receiver.hpp:46
The SubscriberPortUser provides the API for accessing a subscriber port from the user side....
Definition: subscriber_port_user.hpp:41
void unsetConditionVariable() noexcept
detach a condition variable from subscriber
bool isConditionVariableSet() noexcept
check if there's a condition variable attached
void releaseQueuedChunks() noexcept
Release all the chunks that are currently queued up.
SubscribeState getSubscriptionState() const noexcept
get the current subscription state. Caution: There can be delays between calling subscribe and a chan...
void unsubscribe() noexcept
unsubscribe from publishers, if there are any to which we are currently subscribed
bool hasNewChunks() const noexcept
check if there are chunks in the queue
cxx::expected< const mepoo::ChunkHeader *, ChunkReceiveResult > tryGetChunk() noexcept
Tries to get the next chunk from the queue. If there is a new one, the ChunkHeader of the oldest chun...
void subscribe() noexcept
try to subscribe to all matching publishers
void releaseChunk(const mepoo::ChunkHeader *const chunkHeader) noexcept
Release a chunk that was obtained with tryGetChunk.
bool hasLostChunksSinceLastCall() noexcept
check if there was a queue overflow since the last call of hasLostChunksSinceLastCall
void setConditionVariable(ConditionVariableData &conditionVariableData, const uint64_t notificationIndex) noexcept
attach a condition variable (via its pointer) to subscriber
Definition: service_description.hpp:29
Defines different base port data.
Definition: base_port_data.hpp:34
Definition: condition_variable_data.hpp:31
Definition: subscriber_port_data.hpp:37