combiner.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_COMBINER_H_
21 #define INCLUDE_FKIE_MESSAGE_FILTERS_COMBINER_H_
22 
23 #include "source.h"
24 #include "sink.h"
25 
26 namespace fkie_message_filters
27 {
28 
33 namespace combiner_policies
34 {
35 }
36 
70 #ifndef DOXYGEN
71 template<template<typename...> class PolicyTmpl, class... IOs>
72 class Combiner : public helpers::io_rewrap_t<helpers::io_concat_t<IOs...>, Source>
73 #else
74 template<template<typename...> class PolicyTmpl, class... IOs>
75 class Combiner : public Source<IOs...>
76 #endif
77 {
78 public:
80  static constexpr std::size_t NUM_SINKS = sizeof...(IOs);
82  using Connections = std::array<Connection, NUM_SINKS>;
84  template<std::size_t N>
85  using SinkType = helpers::io_rewrap_t<helpers::select_nth<N, IOs...>, Sink>;
87  using Policy = PolicyTmpl<IOs...>;
93  explicit Combiner (const Policy& policy = Policy()) noexcept;
95  template<std::size_t N>
96  SinkType<N>& sink() noexcept;
98  template<std::size_t N>
99  const SinkType<N>& sink() const noexcept;
101  const Policy& policy() const noexcept;
108  void set_policy(const Policy& policy) noexcept;
113  Connections connect_to_sources (helpers::io_rewrap_t<IOs, Source>&... sources) noexcept;
118  void disconnect_from_all_sources() noexcept;
125  void reset() noexcept override;
130  void disconnect() noexcept override;
131 private:
132  using IncomingTuples = std::tuple<typename helpers::io_tuple_t<IOs>...>;
133  using OutgoingTuple = helpers::io_tuple_t<helpers::io_concat_t<IOs...>>;
134  template<typename... Inputs>
135  class CombinerSink : public Sink<Inputs...>
136  {
137  public:
138  using Tuple = std::tuple<Inputs...>;
139  using PolicyInFunc = std::function<void(std::unique_lock<std::mutex>&, const Tuple&)>;
140  void set_parent(Combiner* parent) noexcept;
141  void set_policy_input(const PolicyInFunc& f) noexcept;
142  protected:
143  void receive(const Inputs&... in) override;
144  private:
145  PolicyInFunc forward_;
146  Combiner* parent_{nullptr};
147  };
148  std::mutex combiner_mutex_;
149  Policy policy_;
150  std::tuple<typename IOs::template Rewrap<CombinerSink>...> sinks_;
151  void connect_policy() noexcept;
152  template<std::size_t N, typename ThisSource, typename... OtherSources>
153  void connect_to_sources_impl(Connections& conn, ThisSource& src, OtherSources&... sources) noexcept;
154  template<std::size_t N>
155  void connect_to_sources_impl(Connections& conn) noexcept;
156 };
157 
158 } // namespace fkie_message_filters
159 
160 #include "combiner_impl.h"
161 
162 #endif /* INCLUDE_FKIE_MESSAGE_FILTERS_COMBINER_H_ */
fkie_message_filters::Combiner::disconnect
void disconnect() noexcept override
Disconnect from all connected sources and sinks.
Definition: combiner_impl.h:134
fkie_message_filters
Definition: buffer.h:33
fkie_message_filters::Combiner::disconnect_from_all_sources
void disconnect_from_all_sources() noexcept
Disconnect the sinks from their sources.
Definition: combiner_impl.h:123
fkie_message_filters::helpers::select_nth
std::tuple_element_t< N, std::tuple< Ts... > > select_nth
Definition: tuple.h:67
fkie_message_filters::Combiner::policy_
Policy policy_
Definition: combiner.h:167
fkie_message_filters::Combiner::policy
const Policy & policy() const noexcept
Access combiner policy.
Definition: combiner_impl.h:117
fkie_message_filters::Combiner::NUM_SINKS
static constexpr std::size_t NUM_SINKS
Number of sinks.
Definition: combiner.h:98
fkie_message_filters::Combiner::Policy
PolicyTmpl< IOs... > Policy
Class type of the policy that applies to the combiner.
Definition: combiner.h:105
fkie_message_filters::Combiner::set_policy
void set_policy(const Policy &policy) noexcept
Set combiner policy.
Definition: combiner_impl.h:88
fkie_message_filters::Combiner::reset
void reset() noexcept override
Reset filter.
Definition: combiner_impl.h:96
template
string template
fkie_message_filters::Combiner::CombinerSink
Definition: combiner.h:153
fkie_message_filters::Combiner::Connections
std::array< Connection, NUM_SINKS > Connections
Array of connection objects.
Definition: combiner.h:100
fkie_message_filters::Combiner::sinks_
std::tuple< typename IOs::template Rewrap< CombinerSink >... > sinks_
Definition: combiner.h:168
fkie_message_filters::Combiner::sink
SinkType< N > & sink() noexcept
Access the sink for the Nth input.
f
f
source.h
fkie_message_filters::Combiner::connect_policy
void connect_policy() noexcept
Definition: combiner_impl.h:61
fkie_message_filters::Combiner::connect_to_sources
Connections connect_to_sources(helpers::io_rewrap_t< IOs, Source > &... sources) noexcept
Convenience function to connect all sinks at once.
Definition: combiner_impl.h:155
fkie_message_filters::Combiner
Combine multiple sources into a single one.
Definition: combiner.h:90
fkie_message_filters::helpers::io_rewrap_t
typename io_rewrap< IO, Wrap >::type io_rewrap_t
Definition: io.h:93
fkie_message_filters::Combiner::IncomingTuples
std::tuple< typename helpers::io_tuple_t< IOs >... > IncomingTuples
Definition: combiner.h:150
sink.h
fkie_message_filters::Combiner::connect_to_sources_impl
void connect_to_sources_impl(Connections &conn, ThisSource &src, OtherSources &... sources) noexcept
Definition: combiner_impl.h:148
std
fkie_message_filters::Combiner::Combiner
Combiner(const Policy &policy=Policy()) noexcept
Constructor.
Definition: combiner_impl.h:48
fkie_message_filters::Sink
Base class for data consumers.
Definition: sink.h:64
fkie_message_filters::Combiner::combiner_mutex_
std::mutex combiner_mutex_
Definition: combiner.h:166
fkie_message_filters::Source
Base class for data providers.
Definition: sink.h:51
fkie_message_filters::Combiner::SinkType
helpers::io_rewrap_t< helpers::select_nth< N, IOs... >, Sink > SinkType
Base class for the Nth sink.
Definition: combiner.h:103
fkie_message_filters::Combiner::OutgoingTuple
helpers::io_tuple_t< helpers::io_concat_t< IOs... > > OutgoingTuple
Definition: combiner.h:151
fkie_message_filters::helpers::io_tuple_t
typename io_tuple< IO >::type io_tuple_t
Definition: io.h:129
fkie_message_filters::helpers::io_concat_t
typename io_concat< Ts... >::type io_concat_t
Definition: io.h:120


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