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.
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 << " milliseconds)",
47 ((std::string)connection_name)((int)timeout)) // NOLINT
48
49// Reenable coverage collection LCOV_EXCL_STOP
50} // namespace dunedaq
51
52#ifndef EXTERN_C_FUNC_DECLARE_START
53// NOLINTNEXTLINE(build/define_used)
54#define EXTERN_C_FUNC_DECLARE_START \
55 extern "C" \
56 {
57#endif
58
63// NOLINTNEXTLINE
64#define DEFINE_DUNE_IPM_SENDER(klass) \
65 EXTERN_C_FUNC_DECLARE_START \
66 std::shared_ptr<dunedaq::ipm::Sender> make() \
67 { \
68 return std::shared_ptr<dunedaq::ipm::Sender>(new klass()); \
69 } \
70 }
71
72namespace dunedaq::ipm {
73
75{
76
77public:
79 {
80 std::string connection_name{ "" };
81 std::string connection_string{ "inproc://default" };
82 int capacity{ 0 };
83 };
84 using duration_t = std::chrono::milliseconds;
85 static constexpr duration_t s_block = duration_t::max();
86 static constexpr duration_t s_no_block = duration_t::zero();
87
88 using message_size_t = int;
89
90 Sender() = default;
91 virtual ~Sender() = default;
92
93 virtual std::string connect_for_sends(const ConnectionInfo& connection_info) = 0;
94
95 virtual bool can_send() const noexcept = 0;
96
97 // send() will perform some universally-desirable checks before calling user-implemented send_()
98 // -Throws KnownStateForbidsSend if can_send() == false
99 // -Throws NullPointerPassedToSend if message is a null pointer
100 // -If message_size == 0, function is a no-op
101
102 bool send(const void* message,
103 message_size_t message_size,
104 const duration_t& timeout,
105 std::string const& metadata = "",
106 bool no_tmoexcept_mode = false);
107
108 Sender(const Sender&) = delete;
109 Sender& operator=(const Sender&) = delete;
110
111 Sender(Sender&&) = delete;
112 Sender& operator=(Sender&&) = delete;
113
114protected:
115 ConnectionInfo m_connection_info;
116 void generate_opmon_data() override;
117
118 virtual bool send_(const void* message,
120 const duration_t& timeout,
121 std::string const& metadata,
122 bool no_tmoexcept_mode) = 0;
123
124private:
125 mutable std::atomic<size_t> m_bytes = { 0 };
126 mutable std::atomic<size_t> m_messages = { 0 };
127};
128
129inline std::shared_ptr<Sender>
130make_ipm_sender(std::string const& plugin_name)
131{
132 static cet::BasicPluginFactory bpf("duneIPM", "make");
133 return bpf.makePlugin<std::shared_ptr<Sender>>(plugin_name);
134}
135
136} // namespace dunedaq::ipm
137
138#endif // IPM_INCLUDE_IPM_SENDER_HPP_
std::chrono::milliseconds duration_t
Definition Sender.hpp:84
virtual std::string connect_for_sends(const ConnectionInfo &connection_info)=0
virtual ~Sender()=default
virtual bool can_send() const noexcept=0
#define ERS_DECLARE_ISSUE( namespace_name, class_name, message_, attributes)
Definition macro.hpp:65
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:130
Including Qt Headers.
SendTimeoutExpired
Definition Sender.hpp:45
Both frame_count_limit and tp_count_limit were set to(disabled) in the TPCRawDataProcessor config. TPs will not send."