sink.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * fkie_message_filters
4  * Copyright © 2018-2020 Fraunhofer FKIE
5  * Author: Timo Röhling
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ****************************************************************************/
20 #ifndef INCLUDE_FKIE_MESSAGE_FILTERS_SINK_H_
21 #define INCLUDE_FKIE_MESSAGE_FILTERS_SINK_H_
22 
23 #include "types.h"
24 #include "filter_base.h"
25 #include <vector>
26 #include <set>
27 #include <mutex>
28 #include <thread>
29 
30 namespace fkie_message_filters
31 {
32 
33 template<typename...> class Source;
34 
45 template<typename... Inputs>
46 class Sink : public virtual FilterBase
47 {
48  template<typename...> friend class Source;
49 public:
51  static constexpr std::size_t NUM_INPUTS = sizeof...(Inputs);
56  using Input = IO<Inputs...>;
57 
58  virtual ~Sink() {}
77  void disconnect_from_all_sources() noexcept;
84  virtual void disconnect() noexcept override;
85 protected:
92  virtual void receive(const Inputs&... in) = 0;
93 private:
94  class ReentryProtector;
95  void receive_cb (const Connection&, const Inputs&... in);
96  std::vector<boost::signals2::scoped_connection> conn_;
97  std::mutex mutex_;
98  std::set<std::thread::id> running_;
99 };
100 
101 template<typename... Inputs>
102 class Sink<IO<Inputs...>> : public Sink<Inputs...>
103 {
104 };
105 
106 } // namespace fkie_message_filters
107 
108 #include "source.h"
109 #include "sink_impl.h"
110 
111 #endif /* INCLUDE_FKIE_MESSAGE_FILTERS_SINK_H_ */
fkie_message_filters
Definition: buffer.h:33
fkie_message_filters::Sink::receive
virtual void receive(const Inputs &... in)=0
Process incoming data.
fkie_message_filters::Sink::mutex_
std::mutex mutex_
Definition: sink.h:115
types.h
fkie_message_filters::IO
Group multiple data types as filter input or output.
Definition: io.h:45
fkie_message_filters::Sink::Input
IO< Inputs... > Input
Grouped input types.
Definition: sink.h:74
fkie_message_filters::Sink::Source
friend class Source
Definition: sink.h:66
boost
source.h
fkie_message_filters::Sink::connect_to_source
Connection connect_to_source(Source< Inputs... > &src) noexcept
Connect this sink to a source.
Definition: sink_impl.h:72
fkie_message_filters::Sink::NUM_INPUTS
static constexpr std::size_t NUM_INPUTS
Number of input arguments.
Definition: sink.h:69
sink_impl.h
fkie_message_filters::Sink::disconnect_from_all_sources
void disconnect_from_all_sources() noexcept
Disconnect from all connected sources.
Definition: sink_impl.h:81
filter_base.h
fkie_message_filters::Connection
boost::signals2::connection Connection
Tracks connections from sources to sinks.
Definition: types.h:49
fkie_message_filters::Sink::conn_
std::vector< boost::signals2::scoped_connection > conn_
Definition: sink.h:114
fkie_message_filters::Sink::running_
std::set< std::thread::id > running_
Definition: sink.h:116
std
fkie_message_filters::Sink
Base class for data consumers.
Definition: sink.h:64
fkie_message_filters::Sink::~Sink
virtual ~Sink()
Definition: sink.h:76
fkie_message_filters::Sink::receive_cb
void receive_cb(const Connection &, const Inputs &... in)
Definition: sink_impl.h:94
fkie_message_filters::Source
Base class for data providers.
Definition: sink.h:51
fkie_message_filters::Sink::disconnect
virtual void disconnect() noexcept override
Disconnect from all connected sources.
Definition: sink_impl.h:88


fkie_message_filters
Author(s): Timo Röhling
autogenerated on Wed Mar 2 2022 00:18:57