Line data Source code
1 : /**
2 : * @file GenericReceiverModel.hpp Generic IOManager Receiver model
3 : *
4 : * This is part of the DUNE DAQ , copyright 2020.
5 : * Licensing/copyright details are in the COPYING file that you should have
6 : * received with this code.
7 : */
8 : #ifndef ASIOLIBS_SRC_GENERICRECEIVERMODEL_HPP_
9 : #define ASIOLIBS_SRC_GENERICRECEIVERMODEL_HPP_
10 :
11 : #include "GenericReceiverConcept.hpp"
12 :
13 : #include <string>
14 : #include <utility>
15 : #include <memory>
16 :
17 : namespace dunedaq::asiolibs {
18 :
19 : template<class TargetPayloadType>
20 : class GenericReceiverModel : public GenericReceiverConcept
21 : {
22 : public:
23 0 : explicit GenericReceiverModel(const std::string& receiver_connection_name)
24 0 : : m_receiver(get_iom_receiver<TargetPayloadType>(receiver_connection_name))
25 0 : {}
26 :
27 0 : std::optional<TypeErasedPayload> try_receive(dunedaq::iomanager::Receiver::timeout_t timeout) override {
28 0 : auto opt_payload = m_receiver->try_receive(timeout);
29 0 : if (opt_payload) {
30 : // Allocate the received payload on the heap with shared ownership,
31 : // so its lifetime can outlive this function and be tied to async sends.
32 0 : auto payload = std::make_shared<TargetPayloadType>(std::move(*opt_payload));
33 0 : return TypeErasedPayload{ std::reinterpret_pointer_cast<const void>(payload), payload.get(), sizeof(*payload) };
34 0 : }
35 0 : return std::nullopt;
36 0 : }
37 :
38 : private:
39 : /**
40 : * @brief Generic IOManager Receiver
41 : */
42 : std::shared_ptr<iomanager::ReceiverConcept<TargetPayloadType>> m_receiver;
43 : };
44 :
45 : } // namespace dunedaq::asiolibs
46 :
47 : #endif // ASIOLIBS_SRC_GENERICRECEIVERMODEL_HPP_
|