DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
DataMoveCallbackRegistry.hpp
Go to the documentation of this file.
1
8#ifndef DATAHANDLINGLIBS_INCLUDE_DATAHANDLINGLIBS_DATAMOVECALLBACKREGISTRY_HPP_
9#define DATAHANDLINGLIBS_INCLUDE_DATAHANDLINGLIBS_DATAMOVECALLBACKREGISTRY_HPP_
10
11#include "logging/Logging.hpp"
12
14
15#include <functional>
16#include <map>
17#include <memory>
18#include <string>
19
20namespace dunedaq {
21namespace datahandlinglibs {
22
24{
25public:
26 explicit CallbackConcept(std::string id)
27 : m_id(id)
28 {
29 }
30 virtual ~CallbackConcept() = default;
31 std::string id() const { return m_id; }
32
33protected:
34 std::string m_id;
35};
36
37template<typename DataType>
39{
40public:
41 DataMoveCallback(std::string id, std::function<void(DataType&&)> callback)
43 {
44 m_callback = std::make_shared<std::function<void(DataType&&)>>(callback);
45 }
46 std::shared_ptr<std::function<void(DataType&&)>> m_callback;
47};
48
50{
51public:
52 static std::shared_ptr<DataMoveCallbackRegistry> get()
53 {
54 if (!s_instance)
55 s_instance = std::shared_ptr<DataMoveCallbackRegistry>(new DataMoveCallbackRegistry());
56
57 return s_instance;
58 }
59
61 delete;
63 delete;
66 delete;
67
75 template<typename DataType>
76 void register_callback(const appmodel::DataMoveCallbackConf* conf, std::function<void(DataType&&)> callback);
77
86 template<typename DataType>
87 std::shared_ptr<std::function<void(DataType&&)>> get_callback(const appmodel::DataMoveCallbackConf* conf);
88
89private:
91 std::mutex m_mutex;
92 std::map<std::string, std::shared_ptr<CallbackConcept>> m_callback_map;
93 static std::shared_ptr<DataMoveCallbackRegistry> s_instance;
94};
95
96} // namespace datahandlinglibs
97} // namespace dunedaq
98
100
101#endif // DATAHANDLINGLIBS_INCLUDE_DATAHANDLINGLIBS_DATAMOVECALLBACKREGISTRY_HPP_
static std::shared_ptr< DataMoveCallbackRegistry > s_instance
DataMoveCallbackRegistry(DataMoveCallbackRegistry &&)=delete
DataMoveCallbackRegistry is not move-constructible.
DataMoveCallbackRegistry & operator=(DataMoveCallbackRegistry &&)=delete
DataMoveCallbackRegistry is not move-assignable.
DataMoveCallbackRegistry(const DataMoveCallbackRegistry &)=delete
DataMoveCallbackRegistry is not copy-constructible.
static std::shared_ptr< DataMoveCallbackRegistry > get()
DataMoveCallbackRegistry & operator=(const DataMoveCallbackRegistry &)=delete
DataMoveCallbackRegistry is not copy-assignable.
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.
std::shared_ptr< std::function< void(DataType &&)> > m_callback
DataMoveCallback(std::string id, std::function< void(DataType &&)> callback)
The DUNE-DAQ namespace.