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(build/define_used)
62#define DEFINE_DUNE_IPM_SENDER(klass) \
63 EXTERN_C_FUNC_DECLARE_START \
64 std::shared_ptr<dunedaq::ipm::Sender> make() { return std::shared_ptr<dunedaq::ipm::Sender>(new klass()); } \
65 }
66
67namespace dunedaq::ipm {
68
70{
71
72public:
73 using duration_t = std::chrono::milliseconds;
74 static constexpr duration_t s_block = duration_t::max();
75 static constexpr duration_t s_no_block = duration_t::zero();
76
77 using message_size_t = int;
78
79 Sender() = default;
80 virtual ~Sender() = default;
81
82 virtual std::string connect_for_sends(const nlohmann::json& connection_info) = 0;
83
84 virtual bool can_send() const noexcept = 0;
85
86 // send() will perform some universally-desirable checks before calling user-implemented send_()
87 // -Throws KnownStateForbidsSend if can_send() == false
88 // -Throws NullPointerPassedToSend if message is a null pointer
89 // -If message_size == 0, function is a no-op
90
91 bool send(const void* message,
92 message_size_t message_size,
93 const duration_t& timeout,
94 std::string const& metadata = "",
95 bool no_tmoexcept_mode = false);
96
97 Sender(const Sender&) = delete;
98 Sender& operator=(const Sender&) = delete;
99
100 Sender(Sender&&) = delete;
101 Sender& operator=(Sender&&) = delete;
102
103protected:
104
105 void generate_opmon_data() override;
106
107 virtual bool send_(const void* message,
109 const duration_t& timeout,
110 std::string const& metadata,
111 bool no_tmoexcept_mode) = 0;
112
113private:
114 mutable std::atomic<size_t> m_bytes = { 0 };
115 mutable std::atomic<size_t> m_messages = { 0 };
116};
117
118inline std::shared_ptr<Sender>
119make_ipm_sender(std::string const& plugin_name)
120{
121 static cet::BasicPluginFactory bpf("duneIPM", "make");
122 return bpf.makePlugin<std::shared_ptr<Sender>>(plugin_name);
123}
124
125} // namespace dunedaq::ipm
126
127#endif // IPM_INCLUDE_IPM_SENDER_HPP_
#define ERS_DECLARE_ISSUE(namespace_name, class_name, message, attributes)
std::chrono::milliseconds duration_t
Definition Sender.hpp:73
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:119
Including Qt Headers.
Unable to receive within timeout period(timeout period was " << timeout << " milliseconds)"