SRS-control 0.1.4
 
Loading...
Searching...
No Matches
DataWriter.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <boost/thread/future.hpp>
4#include <spdlog/spdlog.h>
5
9
10namespace srs::workflow
11{
12 class Handler;
13} // namespace srs::workflow
14
15namespace srs::writer
16{
17 class RootFile;
18 class BinaryFile;
19 class UDP;
20 class Json;
21
22 class Manager
23 {
24 public:
25 using enum DataWriterOption;
27
28 explicit Manager(workflow::Handler* processor);
29
31 Manager(const Manager&) = delete;
32 Manager& operator=(const Manager&) = delete;
33 Manager(Manager&&) = default;
34 Manager& operator=(Manager&&) = default;
35
36 void write_with(auto make_future);
37 void wait_for_finished();
38 void reset() { write_futures_.clear(); }
39 void set_output_filenames(const std::vector<std::string>& filenames);
40
41 // Getter:
42 [[nodiscard]] auto is_convert_required(process::DataConvertOptions dependee) const -> bool;
43
44 private:
45 std::map<process::DataConvertOptions, int> convert_count_map_{ process::EMPTY_CONVERT_OPTION_COUNT_MAP.begin(),
47 std::map<std::string, std::unique_ptr<BinaryFile>> binary_files_;
48 std::map<std::string, std::unique_ptr<UDP>> udp_files_;
49 std::map<std::string, std::unique_ptr<Json>> json_files_;
50#ifdef HAS_ROOT
51 std::map<std::string, std::unique_ptr<RootFile>> root_files_;
52#endif
54 std::vector<boost::unique_future<std::optional<int>>> write_futures_;
55
56 auto add_binary_file(const std::string& filename, process::DataConvertOptions deser_mode) -> bool;
57 auto add_udp_file(const std::string& filename, process::DataConvertOptions deser_mode) -> bool;
58 auto add_root_file(const std::string& filename) -> bool;
59 auto add_json_file(const std::string& filename) -> bool;
60
61 template <typename WriterType>
62 void write_to_files(std::map<std::string, std::unique_ptr<WriterType>>& writers, auto make_future)
63 {
64 for (auto& [key, writer] : writers)
65 {
66 auto fut = make_future(*writer);
67 write_futures_.emplace_back(std::move(fut));
68 }
69 }
70 };
71
72 void Manager::write_with(auto make_future)
73 {
74 write_to_files(binary_files_, make_future);
75 write_to_files(udp_files_, make_future);
76 write_to_files(json_files_, make_future);
77#ifdef HAS_ROOT
78 write_to_files(root_files_, make_future);
79#endif
80 }
81} // namespace srs::writer
Manager(Manager &&)=default
Manager(workflow::Handler *processor)
Manager & operator=(Manager &&)=default
Manager(const Manager &)=delete
std::map< std::string, std::unique_ptr< BinaryFile > > binary_files_
auto add_binary_file(const std::string &filename, process::DataConvertOptions deser_mode) -> bool
auto add_root_file(const std::string &filename) -> bool
auto is_convert_required(process::DataConvertOptions dependee) const -> bool
std::map< std::string, std::unique_ptr< Json > > json_files_
Manager & operator=(const Manager &)=delete
void set_output_filenames(const std::vector< std::string > &filenames)
std::vector< boost::unique_future< std::optional< int > > > write_futures_
std::map< process::DataConvertOptions, int > convert_count_map_
std::map< std::string, std::unique_ptr< UDP > > udp_files_
void write_to_files(std::map< std::string, std::unique_ptr< WriterType > > &writers, auto make_future)
workflow::Handler * workflow_handler_
auto add_udp_file(const std::string &filename, process::DataConvertOptions deser_mode) -> bool
void write_with(auto make_future)
auto add_json_file(const std::string &filename) -> bool
constexpr auto EMPTY_CONVERT_OPTION_COUNT_MAP