DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
Sender.hpp
Go to the documentation of this file.
1
22
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.
31
32#include <atomic>
33#include <memory>
34#include <string>
35#include <vector>
36
37namespace dunedaq {
38// Disable coverage collection LCOV_EXCL_START
39ERS_DECLARE_ISSUE(ipm, KnownStateForbidsSend, "Sender not in a state to send data", )
41 NullPointerPassedToSend,
42 connection_name << ": An null pointer to memory was passed to Sender::send",
43 ((std::string)connection_name))
46 connection_name << ": Unable to send within timeout period (timeout period was " << timeout
47 << " milliseconds)",
48 ((std::string)connection_name)((int)timeout)) // NOLINT
49
50// Reenable coverage collection LCOV_EXCL_STOP
51} // namespace dunedaq
52
53#ifndef EXTERN_C_FUNC_DECLARE_START
54// NOLINTNEXTLINE(build/define_used)
55#define EXTERN_C_FUNC_DECLARE_START \
56 extern "C" \
57 {
58#endif
59
64// NOLINTNEXTLINE
65#define DEFINE_DUNE_IPM_SENDER(klass) \
66 EXTERN_C_FUNC_DECLARE_START \
67 std::shared_ptr<dunedaq::ipm::Sender> make() \
68 { \
69 return std::shared_ptr<dunedaq::ipm::Sender>(new klass()); \
70 } \
71 }
72
73namespace dunedaq::ipm {
74
76{
77
78public:
80 {
81 std::string connection_name{ "" };
82 std::string connection_string{ "inproc://default" };
83 int capacity{ 0 };
84 };
85 using duration_t = std::chrono::milliseconds;
86 static constexpr duration_t s_block = duration_t::max();
87 static constexpr duration_t s_no_block = duration_t::zero();
88
89 using message_size_t = int;
90
91 Sender() = default;
92 virtual ~Sender() = default;
93
94 virtual std::string connect_for_sends(const ConnectionInfo& connection_info) = 0;
95
96 virtual bool can_send() const noexcept = 0;
97
98 // send() will perform some universally-desirable checks before calling user-implemented send_()
99 // -Throws KnownStateForbidsSend if can_send() == false
100 // -Throws NullPointerPassedToSend if message is a null pointer
101 // -If message_size == 0, function is a no-op
102
103 bool send(const void* message,
104 message_size_t message_size,
105 const duration_t& timeout,
106 std::string const& metadata = "",
107 bool no_tmoexcept_mode = false);
108
109 Sender(const Sender&) = delete;
110 Sender& operator=(const Sender&) = delete;
111
112 Sender(Sender&&) = delete;
113 Sender& operator=(Sender&&) = delete;
114
115protected:
117 void generate_opmon_data() override;
118
119 virtual bool send_(const void* message,
121 const duration_t& timeout,
122 std::string const& metadata,
123 bool no_tmoexcept_mode) = 0;
124
125private:
126 mutable std::atomic<size_t> m_bytes = { 0 };
127 mutable std::atomic<size_t> m_messages = { 0 };
128};
129
130inline std::shared_ptr<Sender>
131make_ipm_sender(std::string const& plugin_name)
132{
133 static cet::BasicPluginFactory bpf("duneIPM", "make");
134 return bpf.makePlugin<std::shared_ptr<Sender>>(plugin_name);
135}
136
137} // namespace dunedaq::ipm
138
139#endif // IPM_INCLUDE_IPM_SENDER_HPP_
static constexpr duration_t s_block
Definition Sender.hpp:86
std::chrono::milliseconds duration_t
Definition Sender.hpp:85
std::atomic< size_t > m_messages
Definition Sender.hpp:127
virtual std::string connect_for_sends(const ConnectionInfo &connection_info)=0
static constexpr duration_t s_no_block
Definition Sender.hpp:87
virtual ~Sender()=default
void generate_opmon_data() override
Definition Sender.cpp:44
std::atomic< size_t > m_bytes
Definition Sender.hpp:126
bool send(const void *message, message_size_t message_size, const duration_t &timeout, std::string const &metadata="", bool no_tmoexcept_mode=false)
Definition Sender.cpp:17
virtual bool send_(const void *message, message_size_t N, const duration_t &timeout, std::string const &metadata, bool no_tmoexcept_mode)=0
ConnectionInfo m_connection_info
Definition Sender.hpp:116
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:131
The DUNE-DAQ namespace.
ERS_DECLARE_ISSUE(cibmodules, CIBCommunicationError, " CIB Hardware Communication Error: "<< descriptor,((std::string) descriptor)) ERS_DECLARE_ISSUE(cibmodules
SendTimeoutExpired
Definition Sender.hpp:45