LCOV - code coverage report
Current view: top level - daphnemodules/src - DaphneV3Interface.hpp (source / functions) Coverage Total Hit
Test: code.result Lines: 88.9 % 9 8
Test Date: 2026-10-11 15:05:20 Functions: 16.7 % 66 11

            Line data    Source code
       1              : /**
       2              :  * @file DaphneV2Interface.hpp
       3              :  *
       4              :  * Definition of the interface protocol to the daphne V3 boards
       5              :  *  It's basically just a wrapper around a zmq socket
       6              :  *
       7              :  * This is part of the DUNE DAQ Software Suite, copyright 2020.
       8              :  * Licensing/copyright details are in the COPYING file that you should have
       9              :  * received with this code.
      10              :  *
      11              :  */
      12              : 
      13              : #ifndef DAPHNEMODULES_SRC_DAPHNEV3INTERFACE_HPP_
      14              : #define DAPHNEMODULES_SRC_DAPHNEV3INTERFACE_HPP_
      15              : 
      16              : #include "logging/Logging.hpp" // NOTE: if ISSUES ARE DECLARED BEFORE include logging/Logging.hpp, TLOG_DEBUG<<issue wont work.
      17              : #include <ers/ers.hpp>
      18              : 
      19              : #include "daphnemodules/CommonIssues.hpp"
      20              : #include "daphnemodules/daphne_control_high.pb.h"
      21              : #include <zmq.hpp>
      22              : 
      23              : #include <functional>
      24              : #include <memory>
      25              : #include <mutex>
      26              : #include <string>
      27              : 
      28              : namespace dunedaq {
      29              : 
      30            3 : ERS_DECLARE_ISSUE(daphnemodules, SocketCreationError, "Failed to create a socket", ERS_EMPTY)
      31              : 
      32            5 : ERS_DECLARE_ISSUE(daphnemodules,
      33              :                   FailedPing,
      34              :                   "Failed to ping daphne board at " << ip << ':' << port,
      35              :                   ((std::string)ip)((int)port))
      36              : 
      37            7 : ERS_DECLARE_ISSUE(daphnemodules, FailedSend, "Failed to send message of type " << type, ((std::string)type))
      38              : 
      39            3 : ERS_DECLARE_ISSUE(daphnemodules,
      40              :                   FailedReceive,
      41              :                   "Failed to receive message from " << connection,
      42              :                   ((std::string)connection))
      43              : 
      44            3 : ERS_DECLARE_ISSUE(daphnemodules, EmptyPayload, "Empty payload received from " << connection, ((std::string)connection))
      45              : 
      46            3 : ERS_DECLARE_ISSUE(daphnemodules,
      47              :                   TypeMismatch,
      48              :                   "Received message of type " << type << " instead of " << expected,
      49              :                   ((std::string)type)((std::string)expected))
      50              : 
      51            3 : ERS_DECLARE_ISSUE(daphnemodules,
      52              :                   FailedDecoding,
      53              :                   "Failed to de-serialise to " << type << ". Message: " << message,
      54              :                   ((std::string)type)((std::string)message))
      55              : 
      56            3 : ERS_DECLARE_ISSUE(daphnemodules,
      57              :                   UnexpectedDirection,
      58              :                   "Message received with unexpeted properties. Version: " << version << ", direction "
      59              :                                                                           << ". Message: " << message,
      60              :                   ((uint32_t)version)((std::string)direction)((std::string)message))
      61              : 
      62              : } // namespace dunedaq
      63              : 
      64              : namespace dunedaq::daphnemodules {
      65              : 
      66              : class DaphneV3Interface
      67              : {
      68              : 
      69              : public:
      70              :   DaphneV3Interface(std::string address, // it can contain the port or not
      71              :                     std::string routing, // this should be the name of the controller module
      72              :                     std::chrono::milliseconds timeout = std::chrono::milliseconds(500));
      73              : 
      74            0 :   ~DaphneV3Interface() { close(); }
      75              : 
      76              :   DaphneV3Interface(const DaphneV3Interface&) = delete;
      77              :   DaphneV3Interface& operator=(const DaphneV3Interface&) = delete;
      78              :   DaphneV3Interface(DaphneV3Interface&&) = delete;
      79              :   DaphneV3Interface& operator=(DaphneV3Interface&&) = delete;
      80              : 
      81              :   // this takes the serilised message and encodes it into the envelope
      82              :   // It returns the serialised reply
      83              : 
      84              :   daphne::ControlEnvelopeV2 send(std::string&& message, daphne::MessageTypeV2);
      85              : 
      86              :   // this takes the serilised message and encodes it into the envelope
      87              :   // It returns the de-serialised objects
      88              :   template<class T>
      89              :   T send(std::string&& message, daphne::MessageTypeV2 sent_type, daphne::MessageTypeV2 received_type);
      90              : 
      91              :   bool validate_connection();
      92              : 
      93              : protected:
      94              :   void _send(std::string&& message, daphne::MessageTypeV2);
      95              :   daphne::ControlEnvelopeV2 _receive();
      96              : 
      97              :   void close();
      98              : 
      99              : private:
     100              :   zmq::context_t m_context;
     101              : 
     102              :   zmq::socket_t m_socket;
     103              :   mutable std::mutex m_access_mutex;
     104              : 
     105              :   std::string m_connection;
     106              : 
     107              :   std::chrono::milliseconds m_timeout{ 1000 };
     108              : 
     109              :   uint64_t m_message_counter = 0;
     110              : 
     111              :   inline static const size_t s_default_control_port = 40001;
     112              : };
     113              : 
     114              : } // namespce  dunedaq::daphnemodules
     115              : 
     116              : #include <DaphneV3Interface.hxx>
     117              : 
     118              : #endif // DAPHNEMODULES_SRC_DAPHNEV3INTERFACE_HPP_
        

Generated by: LCOV version 2.0-1