iceoryx_doc  1.0.1
condition_listener.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 #ifndef IOX_POSH_POPO_BUILDING_BLOCKS_CONDITION_LISTENER_HPP
18 #define IOX_POSH_POPO_BUILDING_BLOCKS_CONDITION_LISTENER_HPP
19 
20 #include "iceoryx_posh/internal/popo/building_blocks/condition_variable_data.hpp"
21 #include "iceoryx_posh/mepoo/memory_info.hpp"
22 #include "iceoryx_utils/cxx/helplets.hpp"
23 
24 namespace iox
25 {
26 namespace popo
27 {
30 {
31  public:
32  using NotificationVector_t = cxx::vector<cxx::BestFittingType_t<MAX_NUMBER_OF_NOTIFIERS_PER_CONDITION_VARIABLE>,
33  MAX_NUMBER_OF_NOTIFIERS_PER_CONDITION_VARIABLE>;
34 
35  explicit ConditionListener(ConditionVariableData& condVarData) noexcept;
36  ~ConditionListener() noexcept = default;
37  ConditionListener(const ConditionListener& rhs) = delete;
38  ConditionListener(ConditionListener&& rhs) noexcept = delete;
39  ConditionListener& operator=(const ConditionListener& rhs) = delete;
40  ConditionListener& operator=(ConditionListener&& rhs) noexcept = delete;
41 
44  bool wasNotified() const noexcept;
45 
50  void destroy() noexcept;
51 
57  NotificationVector_t wait() noexcept;
58 
66  NotificationVector_t timedWait(const units::Duration& timeToWait) noexcept;
67 
68  protected:
69  const ConditionVariableData* getMembers() const noexcept;
70  ConditionVariableData* getMembers() noexcept;
71 
72  private:
73  void reset(const uint64_t index) noexcept;
74  void resetSemaphore() noexcept;
75 
76  NotificationVector_t waitImpl(const cxx::function_ref<bool()>& waitCall) noexcept;
77 
78  private:
79  ConditionVariableData* m_condVarDataPtr{nullptr};
80  std::atomic_bool m_toBeDestroyed{false};
81 };
82 
83 } // namespace popo
84 } // namespace iox
85 
86 #endif // IOX_POSH_POPO_BUILDING_BLOCKS_CONDITION_VARIABLE_WAITER_HPP
ConditionListener allows one to wait using a shared memory condition variable.
Definition: condition_listener.hpp:30
NotificationVector_t timedWait(const units::Duration &timeToWait) noexcept
returns a sorted vector of indices of active notifications; blocking for the specified time if Condit...
NotificationVector_t wait() noexcept
returns a sorted vector of indices of active notifications; blocking if ConditionVariableData was not...
void destroy() noexcept
Used in classes to signal a thread which waits in wait() to return and stop working....
bool wasNotified() const noexcept
Was the ConditionListener notified by a ConditionNotifier?
Definition: service_description.hpp:29
Definition: condition_variable_data.hpp:31