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
13#include <functional>
14#include <memory>
15#include <string>
16#include <map>
17
18namespace dunedaq {
19namespace datahandlinglibs {
20
22public:
23 explicit CallbackConcept(std::string id)
24 : m_id(id)
25 {
26 }
27 virtual ~CallbackConcept() = default;
28 std::string id() const { return m_id; }
29protected:
30 std::string m_id;
31};
32
33template<typename DataType>
35{
36public:
37 DataMoveCallback(std::string id, std::function<void(DataType&&)> callback)
39 {
40 m_callback = std::make_shared<std::function<void(DataType&&)>>(callback);
41 }
42 std::shared_ptr<std::function<void(DataType&&)>> m_callback;
43};
44
46{
47public:
48 static std::shared_ptr<DataMoveCallbackRegistry> get()
49 {
50 if (!s_instance)
51 s_instance = std::shared_ptr<DataMoveCallbackRegistry>(new DataMoveCallbackRegistry());
52
53 return s_instance;
54 }
55
60
61 template<typename DataType>
62 void register_callback(const std::string& id, std::function<void(DataType&&)> callback);
63
72 template<typename DataType>
73 std::shared_ptr<std::function<void(DataType&&)>>
74 get_callback(const std::string& id);
75
76private:
78 std::mutex m_mutex;
79 std::map<std::string, std::shared_ptr<CallbackConcept>> m_callback_map;
80 static std::shared_ptr<DataMoveCallbackRegistry> s_instance;
81};
82
83} // namespace datahandlinglibs
84} // namespace dunedaq
85
87
88#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.
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
std::shared_ptr< std::function< void(DataType &&)> > m_callback
DataMoveCallback(std::string id, std::function< void(DataType &&)> callback)
Including Qt Headers.