SRS-control 0.1.4
 
Loading...
Searching...
No Matches
DataConverterBase.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <boost/asio/experimental/coro.hpp>
4#include <fmt/ranges.h>
5
8
9namespace srs::process
10{
11 template <typename Input, typename Output>
13 {
14 public:
15 using InputType = Input;
16 using OutputType = Output;
17 using InputFuture = boost::shared_future<std::optional<InputType>>;
18 using OutputFuture = boost::shared_future<std::optional<OutputType>>;
19 using CoroType = asio::experimental::coro<OutputType(std::optional<InputType>)>;
20
21 using enum DataConvertOptions;
22
23 explicit DataConverterBase(auto coro)
24 : coro_(std::move(coro))
25 {
26 common::coro_sync_start(coro_, std::optional<InputType>{}, asio::use_awaitable);
27 }
28
29 auto create_future(this auto&& self, InputFuture& pre_fut, writer::Manager& writers) -> OutputFuture
30 {
31 constexpr auto converter_options = std::remove_cvref_t<decltype(self)>::ConverterOption;
32 auto is_needed = std::ranges::any_of(
33 converter_options, [&writers](auto option) { return writers.is_convert_required(option); });
34 return is_needed ? common::create_coro_future(self.coro_, pre_fut) : OutputFuture{};
35 }
36
37 private:
39 };
40} // namespace srs
asio::experimental::coro< OutputType(std::optional< InputType >)> CoroType
boost::shared_future< std::optional< InputType > > InputFuture
auto create_future(this auto &&self, InputFuture &pre_fut, writer::Manager &writers) -> OutputFuture
boost::shared_future< std::optional< OutputType > > OutputFuture
auto create_coro_future(auto &coro, auto &&pre_fut)
void coro_sync_start(auto &coro, auto &&... args)