DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::datahandlinglibs::DataMoveCallbackRegistry Class Reference

#include <DataMoveCallbackRegistry.hpp>

Public Member Functions

 DataMoveCallbackRegistry (const DataMoveCallbackRegistry &)=delete
 DataMoveCallbackRegistry is not copy-constructible.
 
DataMoveCallbackRegistryoperator= (const DataMoveCallbackRegistry &)=delete
 DataMoveCallbackRegistry is not copy-assignable.
 
 DataMoveCallbackRegistry (DataMoveCallbackRegistry &&)=delete
 DataMoveCallbackRegistry is not move-constructible.
 
DataMoveCallbackRegistryoperator= (DataMoveCallbackRegistry &&)=delete
 DataMoveCallbackRegistry is not move-assignable.
 
template<typename DataType >
void register_callback (const appmodel::DataMoveCallbackConf *conf, std::function< void(DataType &&)> callback)
 Registers a callback function with a configuration object.
 
template<typename DataType >
std::shared_ptr< std::function< void(DataType &&)> > get_callback (const appmodel::DataMoveCallbackConf *conf)
 Gets the callback function registered with the given configuration.
 

Static Public Member Functions

static std::shared_ptr< DataMoveCallbackRegistryget ()
 

Private Member Functions

 DataMoveCallbackRegistry ()
 

Private Attributes

std::mutex m_mutex
 
std::map< std::string, std::shared_ptr< CallbackConcept > > m_callback_map
 

Static Private Attributes

static std::shared_ptr< DataMoveCallbackRegistrys_instance = nullptr
 

Detailed Description

Definition at line 47 of file DataMoveCallbackRegistry.hpp.

Constructor & Destructor Documentation

◆ DataMoveCallbackRegistry() [1/3]

dunedaq::datahandlinglibs::DataMoveCallbackRegistry::DataMoveCallbackRegistry ( const DataMoveCallbackRegistry & )
delete

DataMoveCallbackRegistry is not copy-constructible.

◆ DataMoveCallbackRegistry() [2/3]

dunedaq::datahandlinglibs::DataMoveCallbackRegistry::DataMoveCallbackRegistry ( DataMoveCallbackRegistry && )
delete

DataMoveCallbackRegistry is not move-constructible.

◆ DataMoveCallbackRegistry() [3/3]

dunedaq::datahandlinglibs::DataMoveCallbackRegistry::DataMoveCallbackRegistry ( )
inlineprivate

Definition at line 87 of file DataMoveCallbackRegistry.hpp.

87{}

Member Function Documentation

◆ get()

static std::shared_ptr< DataMoveCallbackRegistry > dunedaq::datahandlinglibs::DataMoveCallbackRegistry::get ( )
inlinestatic

Definition at line 50 of file DataMoveCallbackRegistry.hpp.

51 {
52 if (!s_instance)
53 s_instance = std::shared_ptr<DataMoveCallbackRegistry>(new DataMoveCallbackRegistry());
54
55 return s_instance;
56 }
static std::shared_ptr< DataMoveCallbackRegistry > s_instance

◆ get_callback()

template<typename DataType >
std::shared_ptr< std::function< void(DataType &&)> > dunedaq::datahandlinglibs::DataMoveCallbackRegistry::get_callback ( const appmodel::DataMoveCallbackConf * conf)
inline

Gets the callback function registered with the given configuration.

Template Parameters
DataTypeThe expected parameter type of the callback function
Parameters
confThe configuration object containing the unique identifier for the callback
Returns
A shared pointer to the callback function
Exceptions
GenericConfigurationErrorif the registered callback function's parameter type does not match DataType

Definition at line 25 of file DataMoveCallbackRegistry.hxx.

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}
#define ERS_HERE
static std::shared_ptr< DataMoveCallbackRegistry > get()
std::map< std::string, std::shared_ptr< CallbackConcept > > m_callback_map
#define TLOG(...)
Definition macro.hpp:22
SourceID[" << sourceid << "] Command daqdataformats::SourceID Readout Initialization std::string initerror Configuration std::string conferror GenericConfigurationError

◆ operator=() [1/2]

DataMoveCallbackRegistry & dunedaq::datahandlinglibs::DataMoveCallbackRegistry::operator= ( const DataMoveCallbackRegistry & )
delete

DataMoveCallbackRegistry is not copy-assignable.

◆ operator=() [2/2]

DataMoveCallbackRegistry & dunedaq::datahandlinglibs::DataMoveCallbackRegistry::operator= ( DataMoveCallbackRegistry && )
delete

DataMoveCallbackRegistry is not move-assignable.

◆ register_callback()

template<typename DataType >
void dunedaq::datahandlinglibs::DataMoveCallbackRegistry::register_callback ( const appmodel::DataMoveCallbackConf * conf,
std::function< void(DataType &&)> callback )
inline

Registers a callback function with a configuration object.

Template Parameters
DataTypeThe parameter type of the callback function
Parameters
confThe configuration object containing the unique identifier for the callback
callbackThe callback function to register

Definition at line 11 of file DataMoveCallbackRegistry.hxx.

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}

Member Data Documentation

◆ m_callback_map

std::map<std::string, std::shared_ptr<CallbackConcept> > dunedaq::datahandlinglibs::DataMoveCallbackRegistry::m_callback_map
private

Definition at line 89 of file DataMoveCallbackRegistry.hpp.

◆ m_mutex

std::mutex dunedaq::datahandlinglibs::DataMoveCallbackRegistry::m_mutex
private

Definition at line 88 of file DataMoveCallbackRegistry.hpp.

◆ s_instance

std::shared_ptr< dunedaq::datahandlinglibs::DataMoveCallbackRegistry > dunedaq::datahandlinglibs::DataMoveCallbackRegistry::s_instance = nullptr
staticprivate

Definition at line 90 of file DataMoveCallbackRegistry.hpp.


The documentation for this class was generated from the following files: