GCC Code Coverage Report


Directory: ./
File: src/PZmqBackend.h
Date: 2026-06-23 10:44:39
Exec Total Coverage
Lines: 0 0 -%
Functions: 0 0 -%
Branches: 0 0 -%

Line Branch Exec Source
1 /***************************************
2 Auteur : Thibaut Oprinsen
3 Mail : thibaut.oprinsen@lapp.in2p3.fr
4 Licence : CeCILL-C
5 ****************************************/
6
7 #ifndef __PZMQBACKEND_H__
8 #define __PZMQBACKEND_H__
9
10 #include <string>
11 #include "PSocketFlag.h"
12 #include "phoenix_generic_mock.h"
13 #include "phoenix_data_stream.h"
14 #include "phoenix_zmq.h"
15
16 ///@brief Set of parameters to be passed to create a socket with zmq backend
17 struct PZmqParam{
18 ///Socket type
19 int type;
20 ///Number of messages in the buffer
21 int nbBufferMessage;
22 ///Size of the message buffer in bytes
23 int bufferSizeByte;
24 ///Mask of threads which deal with reconnection
25 size_t threadAffinity;
26 ///Data rate
27 ssize_t dataRate;
28 ///linger period for socket shutdown
29 int linger;
30 ///Immediate flag for socket connexion (EAGAIN if no peer connected)
31 int immediate;
32 };
33
34 PZmqParam pzmq_createParamClient(int type, int nbBufferMessage = 10000, int bufferSizeByte = 1000000, size_t threadAffinity = 0lu, ssize_t dataRate = 200000l, int linger = -1, int immediate = 0);
35 PZmqParam pzmq_createParamServer(int type, int nbBufferMessage = 10000, int bufferSizeByte = 1000000, size_t threadAffinity = 0lu, ssize_t dataRate = 200000l, int linger = -1, int immediate = 0);
36 template <typename T>
37 std::string statusToStr(T status);
38 PSendStatus::PSendStatus checkSendStatus(zmq::send_result_t res);
39 PRecvStatus::PRecvStatus checkRecvStatus(zmq::recv_result_t res);
40
41 ///@brief PhoenixSocket API bridge to ZMQ socket
42 class PZmqSocket{
43 public:
44 ///Define the type of message used by the PAbstractSocketManager
45 typedef zmq::message_t Message;
46 ///Define the type of extra parameters which can be used to create a Socket used by the PAbstractSocketManager
47 typedef PZmqParam Param;
48
49 PZmqSocket();
50 virtual ~PZmqSocket();
51
52 bool createClientSocket(zmq::context_t & context, const PSocketParam & socketParam, const Param & extraParam);
53 bool createServerSocket(zmq::context_t & context, const PSocketParam & socketParam, const Param & extraParam);
54
55 template<typename T>
56 PSendStatus::PSendStatus sendData(const T & data, PSendFlag::PSendFlag flag = PSendFlag::BLOCK);
57 PSendStatus::PSendStatus sendMsg(Message & msg, PSendFlag::PSendFlag flag = PSendFlag::BLOCK);
58
59 template<typename T>
60 PRecvStatus::PRecvStatus recvData(T & data, PRecvFlag::PRecvFlag flag = PRecvFlag::BLOCK);
61 PRecvStatus::PRecvStatus recvMsg(Message & msg, PRecvFlag::PRecvFlag flag = PRecvFlag::BLOCK);
62
63 bool isConnected() const;
64 void close();
65 private:
66 ///ZMQ Socket
67 zmq::socket_t* p_socket;
68 };
69
70 ///@brief Backend to use Mock library with PAbstractSocket
71 class PZmqSocketGenerator{
72 public:
73 ///Define the socket of the backend used by the PAbstractSocketManager
74 typedef PZmqSocket Socket;
75 ///Define the type of message used by the PAbstractSocketManager
76 typedef zmq::message_t Message;
77 ///Define the type of extra parameters which can be used to create a Socket used by the PAbstractSocketManager
78 typedef PZmqParam Param;
79
80 PZmqSocketGenerator();
81
82 static Param client();
83 static Param server();
84
85 bool createClientSocket(Socket & socket, const PSocketParam & socketParam, const PZmqParam & param);
86 bool createServerSocket(Socket & socket, const PSocketParam & socketParam, const PZmqParam & param);
87
88 static void msgToMock(DataStreamMsg & mockMsg, const Message & msg);
89 static void mockToMsg(Message & msg, DataStreamMsg & mockMsg);
90
91 private:
92 ///Context ZMQ
93 zmq::context_t p_context;
94 };
95
96 #include "PZmqBackend_impl.h"
97
98 #endif
99
100