24 #include "cheetah/exporters/DataExport.h" 25 #include "cheetah/exporters/ExporterType.h" 26 #include <panda/Log.h> 27 #include <type_traits> 37 template<
typename DataExporterType,
typename T>
38 class ExportInitialiser {
41 typedef std::function<void(T&)> HandlerType;
42 typedef std::function<std::function<void(T&)>(DataExportStreamConfig
const&)> FactoryType;
45 ExportInitialiser(DataExporterType&
object)
50 void init_exporter(DataExportStreamConfig
const& config)
52 auto it = _type_lookup.find(config.type());
53 if( it == _type_lookup.end() ) {
58 std::string
const&
id = config.sink_config().id();
59 auto id_it = _id_lookup.find(
id);
60 if( id_it == _id_lookup.end() ) {
61 PANDA_LOG_DEBUG <<
"Creating sink of type " << config.type().to_string() <<
" (id=" <<
id <<
")";
62 _id_lookup.insert(std::pair<std::string, HandlerType*>(
id, &_obj.template add<T>(config.channel_name(), std::move((it->second).operator()(config)) )));
65 _obj.template add<T>(config.channel_name(), *(*id_it).second );
69 void add_factory(ExporterType
const& type, FactoryType factory) {
70 _type_lookup.emplace(type, std::move(factory));
74 DataExporterType& _obj;
75 std::map<ExporterType, FactoryType> _type_lookup;
76 std::map<std::string, HandlerType*> _id_lookup;
79 template<
typename... DataTypes>
80 DataExport<DataTypes...>::DataExport(exporters::DataExportConfig
const& config)
81 : DataExport<DataTypes...>::BaseT(config.switch_config())
83 , _initialisers(ExportInitialiser<typename
std::remove_reference<decltype(*this)>::type, DataTypes>(*this)...)
88 template<
typename... DataTypes>
89 DataExport<DataTypes...>::~DataExport()
93 template<
typename... DataTypes>
94 template<
typename DataType,
typename FactoryType>
95 void DataExport<DataTypes...>::set_factory(ExporterType
const& type_id, FactoryType factory)
97 if(_types.find(type_id) == _types.end()) _types.insert(type_id);
98 typedef std::tuple<ExportInitialiser<DataExport<DataTypes...>,
typename std::remove_const<DataTypes>::type>...> ConstRemovedTupleType;
100 std::get<panda::Index<ExportInitialiser<DataExport<DataTypes...>,
typename std::remove_const<DataType>::type>, ConstRemovedTupleType>::value>(_initialisers).add_factory(type_id, std::move(factory));
104 template<
typename ConfigType >
110 void operator()(T& initialiser) {
111 initialiser.init_exporter(_config);
115 ConfigType
const& _config;
118 template<
typename... DataTypes>
121 for(
auto const &exporter : _config.exporters()) {
126 template<
typename... DataTypes>
132 template<
typename... DataTypes>
133 template<
typename DataType>
137 this->
template activate<DataType>(id);
140 assert(rv !=
nullptr);
std::set< ExporterType > const & available() const
return the exporter types available in this class
Some limits and constants for FLDO.
void init()
initialise the output handlers using the factories supplied by set_factory(). Only call after all fac...
Attach to a stream to record the data sent.
TestProbe< DataType > & activate_test_probe(panda::ChannelId const &)
activates a TestProbe object for monitoring the streamed data of DataType to a specific ...