DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
Sender.hpp
Go to the documentation of this file.
1
23#ifndef IPM_INCLUDE_IPM_SENDER_HPP_
24#define IPM_INCLUDE_IPM_SENDER_HPP_
25
26#include "cetlib/BasicPluginFactory.h"
27#include "cetlib/compiler_macros.h"
28#include "ers/Issue.hpp"
29#include "logging/Logging.hpp" // NOTE: if ISSUES ARE DECLARED BEFORE include logging/Logging.hpp, TLOG_DEBUG<<issue wont work.
30#include "nlohmann/json.hpp"
32
33#include <atomic>
34#include <memory>
35#include <string>
36#include <vector>
37
38namespace dunedaq {
39// Disable coverage collection LCOV_EXCL_START
40ERS_DECLARE_ISSUE(ipm, KnownStateForbidsSend, "Sender not in a state to send data", )
41ERS_DECLARE_ISSUE(ipm, NullPointerPassedToSend, "An null pointer to memory was passed to Sender::send", )
43 SendTimeoutExpired,
44 "Unable to send within timeout period (timeout period was " << timeout << " milliseconds)",
45 ((int)timeout)) // NOLINT
46
47// Reenable coverage collection LCOV_EXCL_STOP
48} // namespace dunedaq
49
50#ifndef EXTERN_C_FUNC_DECLARE_START
51// NOLINTNEXTLINE(build/define_used)
52#define EXTERN_C_FUNC_DECLARE_START \
53 extern "C" \
54 {
55#endif
56
61// NOLINTNEXTLINE
62#define DEFINE_DUNE_IPM_SENDER(klass) \
63 EXTERN_C_FUNC_DECLARE_START \
64 std::shared_ptr<dunedaq::ipm::Sender> make() \
65 { \
66 return std::shared_ptr<dunedaq::ipm::Sender>(new klass()); \
67 } \
68 }
69
70namespace dunedaq::ipm {
71
73{
74
75public:
76 using duration_t = std::chrono::milliseconds;
77 static constexpr duration_t s_block = duration_t::max();
78 static constexpr duration_t s_no_block = duration_t::zero();
79
80 using message_size_t = int;
81
82 Sender() = default;
83 virtual ~Sender() = default;
84
85 virtual std::string connect_for_sends(const nlohmann::json& connection_info) = 0;
86
87 virtual bool can_send() const noexcept = 0;
88
89 // send() will perform some universally-desirable checks before calling user-implemented send_()
90 // -Throws KnownStateForbidsSend if can_send() == false
91 // -Throws NullPointerPassedToSend if message is a null pointer
92 // -If message_size == 0, function is a no-op
93
94 bool send(const void* message,
95 message_size_t message_size,
96 const duration_t& timeout,
97 std::string const& metadata = "",
98 bool no_tmoexcept_mode = false);
99
100 Sender(const Sender&) = delete;
101 Sender& operator=(const Sender&) = delete;
102
103 Sender(Sender&&) = delete;
104 Sender& operator=(Sender&&) = delete;
105
106protected:
107 void generate_opmon_data() override;
108
109 virtual bool send_(const void* message,
111 const duration_t& timeout,
112 std::string const& metadata,
113 bool no_tmoexcept_mode) = 0;
114
115private:
116 mutable std::atomic<size_t> m_bytes = { 0 };
117 mutable std::atomic<size_t> m_messages = { 0 };
118};
119
120inline std::shared_ptr<Sender>
121make_ipm_sender(std::string const& plugin_name)
122{
123 static cet::BasicPluginFactory bpf("duneIPM", "make");
124 return bpf.makePlugin<std::shared_ptr<Sender>>(plugin_name);
125}
126
127} // namespace dunedaq::ipm
128
129#endif // IPM_INCLUDE_IPM_SENDER_HPP_
#define ERS_DECLARE_ISSUE(namespace_name, class_name, message, attributes)
std::chrono::milliseconds duration_t
Definition Sender.hpp:76
virtual ~Sender()=default
virtual std::string connect_for_sends(const nlohmann::json &connection_info)=0
virtual bool can_send() const noexcept=0
An ERS Error indicating that an exception was thrown from ZMQ while performing an operation.
std::shared_ptr< Sender > make_ipm_sender(std::string const &plugin_name)
Definition Sender.hpp:121
The DUNE-DAQ namespace.
Definition DataStore.hpp:57
Unable to receive within timeout period(timeout period was " << timeout << " milliseconds)"