iceoryx_posh 2.0.3
trigger.hpp
1// Copyright (c) 2020, 2021 by Apex.AI Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// SPDX-License-Identifier: Apache-2.0
16
17#ifndef IOX_POSH_POPO_TRIGGER_HPP
18#define IOX_POSH_POPO_TRIGGER_HPP
19
20#include "iceoryx_hoofs/cxx/helplets.hpp"
21#include "iceoryx_hoofs/cxx/method_callback.hpp"
22#include "iceoryx_posh/internal/popo/building_blocks/condition_variable_data.hpp"
23#include "iceoryx_posh/popo/notification_callback.hpp"
24#include "iceoryx_posh/popo/notification_info.hpp"
25
26#include <type_traits>
27#include <typeinfo>
28
29namespace iox
30{
31namespace popo
32{
34{
35};
36constexpr StateBasedTrigger_t StateBasedTrigger{};
37
39{
40};
41constexpr EventBasedTrigger_t EventBasedTrigger{};
42
43enum class TriggerType
44{
45 STATE_BASED,
46 EVENT_BASED,
47 INVALID
48};
49
56{
57 public:
58 static constexpr uint64_t INVALID_TRIGGER_ID = std::numeric_limits<uint64_t>::max();
59
60 Trigger() noexcept = delete;
61 Trigger(const Trigger&) = delete;
62 Trigger& operator=(const Trigger&) = delete;
63
77 template <typename T, typename UserType>
79 T* const stateOrigin,
80 const cxx::ConstMethodCallback<bool>& hasTriggeredCallback,
81 const cxx::MethodCallback<void, uint64_t>& resetCallback,
82 const uint64_t notificationId,
84 const uint64_t uniqueId,
85 const uint64_t stateType,
86 const uint64_t stateTypeHash) noexcept;
87
99 template <typename T, typename UserType>
101 T* const notificationOrigin,
102 const cxx::MethodCallback<void, uint64_t>& resetCallback,
103 const uint64_t notificationId,
104 const NotificationCallback<T, UserType>& callback,
105 const uint64_t uniqueId,
106 const uint64_t notificationType,
107 const uint64_t notificationTypeHash) noexcept;
108
109 Trigger(Trigger&& rhs) noexcept;
110 Trigger& operator=(Trigger&& rhs) noexcept;
111
113 ~Trigger() noexcept;
114
119 explicit operator bool() const noexcept;
120
122 bool isValid() const noexcept;
123
126 bool isStateConditionSatisfied() const noexcept;
127
129 void reset() noexcept;
130
132 void invalidate() noexcept;
133
135 uint64_t getUniqueId() const noexcept;
136
142 bool isLogicalEqualTo(const void* const notificationOrigin,
143 const uint64_t originTriggerType,
144 const uint64_t originTriggerTypeHash) const noexcept;
145
148 template <typename T>
149 void updateOrigin(T& newOrigin) noexcept;
150
152 const NotificationInfo& getNotificationInfo() const noexcept;
153
155 TriggerType getTriggerType() const noexcept;
156
157 private:
158 template <typename T, typename ContextDataType>
159 Trigger(T* const notificationOrigin,
160 const cxx::ConstMethodCallback<bool>& hasTriggeredCallback,
161 const cxx::MethodCallback<void, uint64_t>& resetCallback,
162 const uint64_t notificationId,
163 const NotificationCallback<T, ContextDataType>& callback,
164 const uint64_t uniqueId,
165 const TriggerType triggerType,
166 const uint64_t originTriggerType,
167 const uint64_t originTriggerTypeHash) noexcept;
168
169 private:
170 NotificationInfo m_notificationInfo;
171
172 cxx::ConstMethodCallback<bool> m_hasTriggeredCallback;
173 cxx::MethodCallback<void, uint64_t> m_resetCallback;
174 uint64_t m_uniqueId = INVALID_TRIGGER_ID;
175
176 TriggerType m_triggerType = TriggerType::STATE_BASED;
177 uint64_t m_originTriggerType = INVALID_TRIGGER_ID;
178 uint64_t m_originTriggerTypeHash = INVALID_TRIGGER_ID;
179};
180
181
182} // namespace popo
183} // namespace iox
184
185#include "iceoryx_posh/internal/popo/trigger.inl"
186
187#endif
NotificationInfo holds the state of a trigger like the pointer to the triggerOrigin,...
Definition: notification_info.hpp:35
The Trigger class is usually managed by a factory class like a WaitSet and acquired by classes which ...
Definition: trigger.hpp:56
void invalidate() noexcept
invalidates the Trigger without calling the reset callback
void reset() noexcept
resets and invalidates the Trigger
bool isStateConditionSatisfied() const noexcept
returns the result of the provided hasTriggeredCallback
TriggerType getTriggerType() const noexcept
returns the type of trigger
bool isValid() const noexcept
returns true if the trigger is valid otherwise false
const NotificationInfo & getNotificationInfo() const noexcept
returns the NotificationInfo
~Trigger() noexcept
calls reset on destruction
Trigger(EventBasedTrigger_t, T *const notificationOrigin, const cxx::MethodCallback< void, uint64_t > &resetCallback, const uint64_t notificationId, const NotificationCallback< T, UserType > &callback, const uint64_t uniqueId, const uint64_t notificationType, const uint64_t notificationTypeHash) noexcept
Creates an event based Trigger.
bool isLogicalEqualTo(const void *const notificationOrigin, const uint64_t originTriggerType, const uint64_t originTriggerTypeHash) const noexcept
returns true if the Triggers are logical equal otherwise false. Two Triggers are logical equal when
uint64_t getUniqueId() const noexcept
returns the internal unique id of the trigger
Trigger(StateBasedTrigger_t, T *const stateOrigin, const cxx::ConstMethodCallback< bool > &hasTriggeredCallback, const cxx::MethodCallback< void, uint64_t > &resetCallback, const uint64_t notificationId, const NotificationCallback< T, UserType > &callback, const uint64_t uniqueId, const uint64_t stateType, const uint64_t stateTypeHash) noexcept
Creates a state based Trigger.
void updateOrigin(T &newOrigin) noexcept
sets a new origin of the trigger
Definition: trigger.hpp:39
the struct describes a callback with a user defined type which can be attached to a WaitSet or a List...
Definition: notification_callback.hpp:58
Definition: trigger.hpp:34