DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
CallbackAdapter.hpp
Go to the documentation of this file.
1
13#ifndef IPM_SRC_CALLBACKADAPTER_HPP_
14#define IPM_SRC_CALLBACKADAPTER_HPP_
15
16#include "ipm/Receiver.hpp"
17
18#include <atomic>
19#include <functional>
20#include <memory>
21#include <mutex>
22#include <thread>
23
24namespace dunedaq::ipm {
25
27{
28public:
29 CallbackAdapter() = default; // Explicitly defaulted
30
31 virtual ~CallbackAdapter() noexcept;
32
33 void set_receiver(Receiver* receiver_ptr);
34 void set_callback(std::function<void(Receiver::Response&)> callback);
35 void clear_callback();
36
37private:
38 void startup();
39 void shutdown();
40 void thread_loop();
41
42 Receiver* m_receiver_ptr{ nullptr }; // Bare pointer used here as CallbackAdapter does not own the Receiver instance,
43 // and until set_receiver is called, this will be null.
44 std::function<void(Receiver::Response&)> m_callback{ nullptr };
45 mutable std::mutex m_callback_mutex;
46 std::unique_ptr<std::thread> m_thread{ nullptr };
47 std::atomic<bool> m_is_listening{ false };
48};
49} // namespace dunedaq::ipm
50
51#endif // IPM_SRC_CALLBACKADAPTER_HPP_
std::function< void(Receiver::Response &)> m_callback
void set_callback(std::function< void(Receiver::Response &)> callback)
virtual ~CallbackAdapter() noexcept
std::unique_ptr< std::thread > m_thread
std::atomic< bool > m_is_listening
void set_receiver(Receiver *receiver_ptr)
An ERS Error indicating that an exception was thrown from ZMQ while performing an operation.