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 <memory>
17#include <string>
18#include <map>
19
20namespace dunedaq {
21namespace datahandlinglibs {
22
24public:
25 explicit CallbackConcept(std::string id)
26 : m_id(id)
27 {
28 }
29 virtual ~CallbackConcept() = default;
30 std::string id() const { return m_id; }
31protected:
32 std::string m_id;
33};
34
35template<typename DataType>
37{
38public:
39 DataMoveCallback(std::string id, std::function<void(DataType&&)> callback)
41 {
42 m_callback = std::make_shared<std::function<void(DataType&&)>>(callback);
43 }
44 std::shared_ptr<std::function<void(DataType&&)>> m_callback;
45};
46
48{
49public:
50 static std::shared_ptr<DataMoveCallbackRegistry> get()
51 {
52 if (!s_instance)
53 s_instance = std::shared_ptr<DataMoveCallbackRegistry>(new DataMoveCallbackRegistry());
54
55 return s_instance;
56 }
57
62
63
64
72 template<typename DataType>
73 void register_callback(const appmodel::DataMoveCallbackConf* conf, std::function<void(DataType&&)> callback);
74
83 template<typename DataType>
84 std::shared_ptr<std::function<void(DataType&&)>> get_callback(const appmodel::DataMoveCallbackConf* conf);
85
86private:
88 std::mutex m_mutex;
89 std::map<std::string, std::shared_ptr<CallbackConcept>> m_callback_map;
90 static std::shared_ptr<DataMoveCallbackRegistry> s_instance;
91};
92
93} // namespace datahandlinglibs
94} // namespace dunedaq
95
97
98#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)
Including Qt Headers.