rmw_fastrtps_shared_cpp  master
Code shared on static and dynamic type support of rmw_fastrtps_cpp.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
custom_event_info.hpp
Go to the documentation of this file.
1 // Copyright 2019 Amazon.com, Inc. or its affiliates. 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 #ifndef RMW_FASTRTPS_SHARED_CPP__CUSTOM_EVENT_INFO_HPP_
16 #define RMW_FASTRTPS_SHARED_CPP__CUSTOM_EVENT_INFO_HPP_
17 
18 #include <atomic>
19 #include <condition_variable>
20 #include <list>
21 #include <memory>
22 #include <mutex>
23 #include <utility>
24 
25 #include "fastcdr/FastBuffer.h"
26 
27 #include "fastrtps/subscriber/SampleInfo.h"
28 #include "fastrtps/subscriber/Subscriber.h"
29 #include "fastrtps/subscriber/SubscriberListener.h"
30 #include "fastrtps/participant/Participant.h"
31 #include "fastrtps/publisher/Publisher.h"
32 #include "fastrtps/publisher/PublisherListener.h"
33 
34 #include "rmw/event.h"
35 
37 
38 
40 {
41 protected:
43 
44 public:
46  virtual void attachCondition(
47  std::mutex * conditionMutex,
48  std::condition_variable * conditionVariable) = 0;
49 
51  virtual void detachCondition() = 0;
52 
54 
58  virtual bool hasEvent(rmw_event_type_t event_type) const = 0;
59 
61 
67  virtual bool takeNextEvent(rmw_event_type_t event_type, void * event_info) = 0;
68 };
69 
71 {
72 public:
74  std::mutex * mutex,
75  std::condition_variable * condition_variable = nullptr)
76  : mutex_(mutex), cv_(condition_variable)
77  {
78  if (nullptr != mutex_) {
79  mutex_->lock();
80  }
81  }
82 
84  {
85  if (nullptr != mutex_) {
86  mutex_->unlock();
87  if (nullptr != cv_) {
88  cv_->notify_all();
89  }
90  }
91  }
92 
93 private:
94  std::mutex * mutex_;
96 };
97 
99 {
100  virtual EventListenerInterface * getListener() const = 0;
101 };
102 
103 #endif // RMW_FASTRTPS_SHARED_CPP__CUSTOM_EVENT_INFO_HPP_
std::mutex::lock
T lock(T... args)
event.h
EventListenerInterface::ConditionalScopedLock::ConditionalScopedLock
ConditionalScopedLock(std::mutex *mutex, std::condition_variable *condition_variable=nullptr)
Definition: custom_event_info.hpp:73
rmw_event_type_t
rmw_event_type_t
TypeSupport.hpp
EventListenerInterface::attachCondition
virtual void attachCondition(std::mutex *conditionMutex, std::condition_variable *conditionVariable)=0
Connect a condition variable so a waiter can be notified of new data.
std::mutex::unlock
T unlock(T... args)
EventListenerInterface::ConditionalScopedLock::~ConditionalScopedLock
~ConditionalScopedLock()
Definition: custom_event_info.hpp:83
EventListenerInterface::takeNextEvent
virtual bool takeNextEvent(rmw_event_type_t event_type, void *event_info)=0
Take ready data for an event type.
EventListenerInterface::ConditionalScopedLock
Definition: custom_event_info.hpp:70
std::condition_variable
std::mutex
EventListenerInterface::detachCondition
virtual void detachCondition()=0
Unset the information from attachCondition.
EventListenerInterface::hasEvent
virtual bool hasEvent(rmw_event_type_t event_type) const =0
Check if there is new data available for a specific event type.
CustomEventInfo::getListener
virtual EventListenerInterface * getListener() const =0
std::condition_variable::notify_all
T notify_all(T... args)
CustomEventInfo
Definition: custom_event_info.hpp:98
EventListenerInterface
Definition: custom_event_info.hpp:39