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>
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:
146  Combiner* parent_{nullptr};
147  };
148  std::mutex combiner_mutex_;
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_ */
std::tuple_element_t< N, std::tuple< Ts... > > select_nth
Definition: tuple.h:31
Base class for data consumers.
Definition: sink.h:46
helpers::io_tuple_t< helpers::io_concat_t< IOs... > > OutgoingTuple
Definition: combiner.h:133
std::tuple< typename IOs::template Rewrap< CombinerSink >... > sinks_
Definition: combiner.h:150
Base class for data providers.
Definition: sink.h:33
std::function< void(std::unique_lock< std::mutex > &, const Tuple &)> PolicyInFunc
Definition: combiner.h:139
std::array< Connection, NUM_SINKS > Connections
Array of connection objects.
Definition: combiner.h:82
typename io_rewrap< IO, Wrap >::type io_rewrap_t
Definition: io.h:75
Primary namespace.
Definition: buffer.h:33
helpers::io_rewrap_t< helpers::select_nth< N, IOs... >, Sink > SinkType
Base class for the Nth sink.
Definition: combiner.h:85
string template
typename io_tuple< IO >::type io_tuple_t
Definition: io.h:111
Combine multiple sources into a single one.
Definition: combiner.h:72
std::tuple< typename helpers::io_tuple_t< IOs >... > IncomingTuples
Definition: combiner.h:132
typename io_concat< Ts... >::type io_concat_t
Definition: io.h:102
PolicyTmpl< IOs... > Policy
Class type of the policy that applies to the combiner.
Definition: combiner.h:87


fkie_message_filters
Author(s): Timo Röhling
autogenerated on Sun Sep 12 2021 02:52:12