iceoryx_posh 2.0.5
Loading...
Searching...
No Matches
base_subscriber.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_BASE_SUBSCRIBER_HPP
19#define IOX_POSH_POPO_BASE_SUBSCRIBER_HPP
20
21#include "iceoryx_hoofs/cxx/expected.hpp"
22#include "iceoryx_hoofs/cxx/optional.hpp"
23#include "iceoryx_hoofs/cxx/unique_ptr.hpp"
24#include "iceoryx_posh/internal/popo/ports/subscriber_port_user.hpp"
25#include "iceoryx_posh/popo/enum_trigger_type.hpp"
26#include "iceoryx_posh/popo/sample.hpp"
27#include "iceoryx_posh/popo/subscriber_options.hpp"
28#include "iceoryx_posh/popo/wait_set.hpp"
29#include "iceoryx_posh/runtime/posh_runtime.hpp"
30
31namespace iox
32{
33namespace runtime
34{
35class ServiceDiscovery;
36}
37namespace popo
38{
39using uid_t = UniquePortId;
40
41enum class SubscriberEvent : EventEnumIdentifier
42{
43 DATA_RECEIVED
44};
45
46enum class SubscriberState : StateEnumIdentifier
47{
48 HAS_DATA
49};
50
54template <typename port_t = iox::SubscriberPortUserType>
56{
57 public:
58 virtual ~BaseSubscriber() noexcept;
59
64 uid_t getUid() const noexcept;
65
70 capro::ServiceDescription getServiceDescription() const noexcept;
71
76 void subscribe() noexcept;
77
82 SubscribeState getSubscriptionState() const noexcept;
83
87 void unsubscribe() noexcept;
88
93 bool hasData() const noexcept;
94
100 bool hasMissedData() noexcept;
101
103 void releaseQueuedData() noexcept;
104
105 friend class NotificationAttorney;
106 friend class iox::runtime::ServiceDiscovery;
107
108 protected:
112 using SelfType = BaseSubscriber<port_t>;
113 using PortType = port_t;
114
115 BaseSubscriber() noexcept; // Required for testing.
116 BaseSubscriber(const capro::ServiceDescription& service, const SubscriberOptions& subscriberOptions) noexcept;
117
118 BaseSubscriber(const BaseSubscriber& other) = delete;
119 BaseSubscriber& operator=(const BaseSubscriber&) = delete;
120 BaseSubscriber(BaseSubscriber&& rhs) = delete;
121 BaseSubscriber& operator=(BaseSubscriber&& rhs) = delete;
122
125 cxx::expected<const mepoo::ChunkHeader*, ChunkReceiveResult> takeChunk() noexcept;
126
127 void invalidateTrigger(const uint64_t trigger) noexcept;
128
132 void enableState(iox::popo::TriggerHandle&& triggerHandle, const SubscriberState subscriberState) noexcept;
133
137 WaitSetIsConditionSatisfiedCallback
138 getCallbackForIsStateConditionSatisfied(const SubscriberState subscriberState) const noexcept;
139
142 void disableState(const SubscriberState subscriberState) noexcept;
143
147 void enableEvent(iox::popo::TriggerHandle&& triggerHandle, const SubscriberEvent subscriberState) noexcept;
148
151 void disableEvent(const SubscriberEvent subscriberEvent) noexcept;
152
156 const port_t& port() const noexcept;
157
161 port_t& port() noexcept;
162
163 protected:
164 port_t m_port{nullptr};
165 TriggerHandle m_trigger;
166};
167
168} // namespace popo
169} // namespace iox
170
171#include "iceoryx_posh/internal/popo/base_subscriber.inl"
172
173#endif // IOX_POSH_POPO_BASE_SUBSCRIBER_HPP
base class for all types of subscriber
Definition base_subscriber.hpp:56
WaitSetIsConditionSatisfiedCallback getCallbackForIsStateConditionSatisfied(const SubscriberState subscriberState) const noexcept
Only usable by the WaitSet, not for public use. Returns method pointer to the event corresponding has...
void enableState(iox::popo::TriggerHandle &&triggerHandle, const SubscriberState subscriberState) noexcept
Only usable by the WaitSet, not for public use. Attaches the triggerHandle to the internal trigger.
capro::ServiceDescription getServiceDescription() const noexcept
getServiceDescription Get the service description of the subscriber.
void enableEvent(iox::popo::TriggerHandle &&triggerHandle, const SubscriberEvent subscriberState) noexcept
Only usable by the WaitSet, not for public use. Attaches the triggerHandle to the internal trigger.
void subscribe() noexcept
subscribe Initiate subscription.
uid_t getUid() const noexcept
uid Get the unique ID of the subscriber.
const port_t & port() const noexcept
const accessor of the underlying port
void disableState(const SubscriberState subscriberState) noexcept
Only usable by the WaitSet, not for public use. Resets the internal triggerHandle.
bool hasData() const noexcept
Check if data is available.
void unsubscribe() noexcept
unsubscribe Unsubscribes if currently subscribed, otherwise do nothing.
cxx::expected< const mepoo::ChunkHeader *, ChunkReceiveResult > takeChunk() noexcept
small helper method to unwrap the expected<optional<ChunkHeader*>> from the tryGetChunk method of the...
void releaseQueuedData() noexcept
Releases any unread queued data.
void disableEvent(const SubscriberEvent subscriberEvent) noexcept
Only usable by the WaitSet, not for public use. Resets the internal triggerHandle.
bool hasMissedData() noexcept
Check if data has been missed since the last call of this method.
SubscribeState getSubscriptionState() const noexcept
getSubscriptionState Get current subscription state.
Class which allows accessing private methods to friends of NotificationAttorney. Used for example by ...
Definition notification_attorney.hpp:33
TriggerHandle is threadsafe without restrictions in a single process. Not qualified for inter process...
Definition trigger_handle.hpp:38
This struct is used to configure the subscriber.
Definition subscriber_options.hpp:33