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 std::string& id, std::function<void(DataType&&)> callback) {
12 std::lock_guard<std::mutex> guard(m_mutex);
13 if (m_callback_map.count(id) == 0) {
14 TLOG() << "Registering DataMoveCallback with ID: " << id;
15 m_callback_map[id] = std::make_shared<DataMoveCallback<DataType>>(DataMoveCallback(id, callback));
16 } else {
17 TLOG() << "Callback is already registered with ID: " << id << " Ignoring this registration.";
18 }
19}
20
21template<typename DataType>
22inline std::shared_ptr<std::function<void(DataType&&)>>
24{
25 std::lock_guard<std::mutex> guard(m_mutex);
26 if (m_callback_map.contains(id)) {
27 TLOG() << "Providing DataMoveCallback with ID: " << id;
28 if (auto callback = dynamic_cast<DataMoveCallback<DataType>*>(m_callback_map[id].get()); callback != nullptr) {
29 return callback->m_callback;
30 } else {
31 // As this can happen due to a very bad config error and wherever the acquire is called will lead to undefined behavior
34 std::format("Callback cast failed for function signature with datatypes (expected vs. registered) : {} vs. {}",
35 typeid(DataMoveCallback<DataType>).name(),
36 typeid(*m_callback_map[id]).name()));
37 }
38 } else {
39 TLOG() << "No callback registered with ID: " << id << " Returning nullptr.";
40 return nullptr;
41 }
42}
43
44}
45}
#define ERS_HERE
static std::shared_ptr< DataMoveCallbackRegistry > get()
void register_callback(const std::string &id, std::function< void(DataType &&)> callback)
std::shared_ptr< std::function< void(DataType &&)> > get_callback(const std::string &id)
Gets the callback function registered with the given ID.
std::map< std::string, std::shared_ptr< CallbackConcept > > m_callback_map
#define TLOG(...)
Definition macro.hpp:22
Including Qt Headers.
SourceID[" << sourceid << "] Command daqdataformats::SourceID Readout Initialization std::string initerror Configuration std::string conferror GenericConfigurationError