DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
DataMoveCallbackRegistry.hxx
Go to the documentation of this file.
2
3#include <functional>
4
5namespace dunedaq {
6
7namespace datahandlinglibs {
8
9template<typename DataType>
10inline void
11DataMoveCallbackRegistry::register_callback(const appmodel::DataMoveCallbackConf* conf, std::function<void(DataType&&)> callback)
12{
13 std::lock_guard<std::mutex> guard(m_mutex);
14 std::string id = conf->UID();
15 if (m_callback_map.count(id) == 0) {
16 TLOG() << "Registering DataMoveCallback with ID: " << id;
17 m_callback_map[id] = std::make_shared<DataMoveCallback<DataType>>(DataMoveCallback(id, callback));
18 } else {
19 TLOG() << "Callback is already registered with ID: " << id << " Ignoring this registration.";
20 }
21}
22
23template<typename DataType>
24inline std::shared_ptr<std::function<void(DataType&&)>>
26{
27 std::lock_guard<std::mutex> guard(m_mutex);
28 std::string id = conf->UID();
29 if (m_callback_map.contains(id)) {
30 TLOG() << "Providing DataMoveCallback with ID: " << id;
31 if (auto callback = dynamic_cast<DataMoveCallback<DataType>*>(m_callback_map[id].get()); callback != nullptr) {
32 return callback->m_callback;
33 } else {
34 // As this can happen due to a very bad config error and wherever the acquire is called will lead to undefined
35 // behavior
38 std::format("Callback cast failed for function signature with datatypes (expected vs. registered) : {} vs. {}",
39 typeid(DataMoveCallback<DataType>).name(),
40 typeid(*m_callback_map[id]).name()));
41 }
42 } else {
43 TLOG() << "No callback registered with ID: " << id << " Returning nullptr.";
44 return nullptr;
45 }
46}
47}
48}
#define ERS_HERE
const std::string & UID() const noexcept
static std::shared_ptr< DataMoveCallbackRegistry > get()
std::map< std::string, std::shared_ptr< CallbackConcept > > m_callback_map
std::shared_ptr< std::function< void(DataType &&)> > get_callback(const appmodel::DataMoveCallbackConf *conf)
Gets the callback function registered with the given configuration.
void register_callback(const appmodel::DataMoveCallbackConf *conf, std::function< void(DataType &&)> callback)
Registers a callback function with a configuration object.
#define TLOG(...)
Definition macro.hpp:22
Including Qt Headers.
SourceID[" << sourceid << "] Command daqdataformats::SourceID Readout Initialization std::string initerror Configuration std::string conferror GenericConfigurationError