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 std::string &id, std::function< void(DataType &&)> callback)
 
template<typename DataType >
std::shared_ptr< std::function< void(DataType &&)> > get_callback (const std::string &id)
 Gets the callback function registered with the given ID.
 

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 45 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 77 of file DataMoveCallbackRegistry.hpp.

77{}

Member Function Documentation

◆ get()

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

Definition at line 48 of file DataMoveCallbackRegistry.hpp.

49 {
50 if (!s_instance)
51 s_instance = std::shared_ptr<DataMoveCallbackRegistry>(new DataMoveCallbackRegistry());
52
53 return s_instance;
54 }
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 std::string & id)
inline

Gets the callback function registered with the given ID.

Template Parameters
DataTypeThe expected parameter type of the callback function
Parameters
idThe 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 23 of file DataMoveCallbackRegistry.hxx.

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}
#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 std::string & id,
std::function< void(DataType &&)> callback )
inline

Definition at line 11 of file DataMoveCallbackRegistry.hxx.

11 {
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}

Member Data Documentation

◆ m_callback_map

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

Definition at line 79 of file DataMoveCallbackRegistry.hpp.

◆ m_mutex

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

Definition at line 78 of file DataMoveCallbackRegistry.hpp.

◆ s_instance

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

Definition at line 80 of file DataMoveCallbackRegistry.hpp.


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