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_ */
Base class for data consumers.
Definition: sink.h:46
boost::signals2::connection Connection
Tracks connections from sources to sinks.
Definition: types.h:31
static constexpr std::size_t NUM_INPUTS
Number of input arguments.
Definition: sink.h:51
void receive_cb(const Connection &, const Inputs &... in)
Definition: sink_impl.h:76
virtual void receive(const Inputs &... in)=0
Process incoming data.
Base class for data providers.
Definition: sink.h:33
friend class Source
Definition: sink.h:48
void disconnect_from_all_sources() noexcept
Disconnect from all connected sources.
Definition: sink_impl.h:63
Group multiple data types as filter input or output.
Definition: io.h:27
Connection connect_to_source(Source< Inputs... > &src) noexcept
Connect this sink to a source.
Definition: sink_impl.h:54
std::vector< boost::signals2::scoped_connection > conn_
Definition: sink.h:96
Base class for filters.
Definition: filter_base.h:57
Primary namespace.
Definition: buffer.h:33
virtual void disconnect() noexcept override
Disconnect from all connected sources.
Definition: sink_impl.h:70
std::set< std::thread::id > running_
Definition: sink.h:98
std::mutex mutex_
Definition: sink.h:97


fkie_message_filters
Author(s): Timo Röhling
autogenerated on Mon Feb 28 2022 22:21:43