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