PhoenixZMQ  6.0.0
Library which integrates zeromq use
Loading...
Searching...
No Matches
PZmqBackend.h
Go to the documentation of this file.
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
29
30PZmqParam pzmq_createParamClient(int type, int nbBufferMessage = 10000, int bufferSizeByte = 1000000, size_t threadAffinity = 0lu, ssize_t dataRate = 200000l);
31PZmqParam pzmq_createParamServer(int type, int nbBufferMessage = 10000, int bufferSizeByte = 1000000, size_t threadAffinity = 0lu, ssize_t dataRate = 200000l);
32template <typename T>
33std::string statusToStr(T status);
34PSendStatus::PSendStatus checkSendStatus(zmq::send_result_t res);
35PRecvStatus::PRecvStatus checkRecvStatus(zmq::recv_result_t res);
36
39 public:
41 typedef zmq::message_t Message;
44
45 PZmqSocket();
46 virtual ~PZmqSocket();
47
48 bool createClientSocket(zmq::context_t & context, const PSocketParam & socketParam, const Param & extraParam);
49 bool createServerSocket(zmq::context_t & context, const PSocketParam & socketParam, const Param & extraParam);
50
51 template<typename T>
52 PSendStatus::PSendStatus sendData(const T & data, PSendFlag::PSendFlag flag = PSendFlag::BLOCK);
53 PSendStatus::PSendStatus sendMsg(Message & msg, PSendFlag::PSendFlag flag = PSendFlag::BLOCK);
54
55 template<typename T>
56 PRecvStatus::PRecvStatus recvData(T & data, PRecvFlag::PRecvFlag flag = PRecvFlag::BLOCK);
57 PRecvStatus::PRecvStatus recvMsg(Message & msg, PRecvFlag::PRecvFlag flag = PRecvFlag::BLOCK);
58
59 bool isConnected() const;
60 void close();
61 private:
63 zmq::socket_t* p_socket;
64};
65
68 public:
72 typedef zmq::message_t Message;
75
77
78 static Param client();
79 static Param server();
80
81 bool createClientSocket(Socket & socket, const PSocketParam & socketParam, const PZmqParam & param);
82 bool createServerSocket(Socket & socket, const PSocketParam & socketParam, const PZmqParam & param);
83
84 void msgToMock(DataStreamMsg & mockMsg, const Message & msg);
85 void mockToMsg(Message & msg, DataStreamMsg & mockMsg);
86
87 private:
89 zmq::context_t p_context;
90};
91
92#include "PZmqBackend_impl.h"
93
94#endif
95
std::string statusToStr(T status)
Convert PSendStatus into string.
PRecvStatus::PRecvStatus checkRecvStatus(zmq::recv_result_t res)
Check the recv result and convert it into PRecvStatus.
PZmqParam pzmq_createParamServer(int type, int nbBufferMessage=10000, int bufferSizeByte=1000000, size_t threadAffinity=0lu, ssize_t dataRate=200000l)
Create param for a client socket.
PZmqParam pzmq_createParamClient(int type, int nbBufferMessage=10000, int bufferSizeByte=1000000, size_t threadAffinity=0lu, ssize_t dataRate=200000l)
Create param for a client socket.
PSendStatus::PSendStatus checkSendStatus(zmq::send_result_t res)
Check the send result and convert it into PSendStatus.
zmq::context_t p_context
Context ZMQ.
Definition PZmqBackend.h:89
PZmqParam Param
Define the type of extra parameters which can be used to create a Socket used by the PAbstractSocketM...
Definition PZmqBackend.h:74
PZmqBackend()
Default constructor of PZmqBackend setting the number of threads for zmq I/O to 1.
void msgToMock(DataStreamMsg &mockMsg, const Message &msg)
Copy current backend message data into mock message.
bool createClientSocket(Socket &socket, const PSocketParam &socketParam, const PZmqParam &param)
Create a client socket.
static Param client()
Create a client parameter.
bool createServerSocket(Socket &socket, const PSocketParam &socketParam, const PZmqParam &param)
Create a server socket.
PZmqSocket Socket
Define the socket of the backend used by the PAbstractSocketManager.
Definition PZmqBackend.h:70
void mockToMsg(Message &msg, DataStreamMsg &mockMsg)
Copy mock message data into current backend message.
static Param server()
Create a server parameter.
zmq::message_t Message
Define the type of message used by the PAbstractSocketManager.
Definition PZmqBackend.h:72
PhoenixSocket API bridge to ZMQ socket.
Definition PZmqBackend.h:38
zmq::socket_t * p_socket
ZMQ Socket.
Definition PZmqBackend.h:63
PZmqSocket()
Default constructor of PZmqSocket.
bool isConnected() const
Check if the socket is connected.
bool createClientSocket(zmq::context_t &context, const PSocketParam &socketParam, const Param &extraParam)
Create a client socket.
PSendStatus::PSendStatus sendData(const T &data, PSendFlag::PSendFlag flag=PSendFlag::BLOCK)
Send data with the socket.
PSendStatus::PSendStatus sendMsg(Message &msg, PSendFlag::PSendFlag flag=PSendFlag::BLOCK)
Send data with the socket.
void close()
Close the socket.
bool createServerSocket(zmq::context_t &context, const PSocketParam &socketParam, const Param &extraParam)
Create a server socket.
PZmqParam Param
Define the type of extra parameters which can be used to create a Socket used by the PAbstractSocketM...
Definition PZmqBackend.h:43
virtual ~PZmqSocket()
Destructor of PZmqSocket.
PRecvStatus::PRecvStatus recvData(T &data, PRecvFlag::PRecvFlag flag=PRecvFlag::BLOCK)
Recieved data with the socket.
PRecvStatus::PRecvStatus recvMsg(Message &msg, PRecvFlag::PRecvFlag flag=PRecvFlag::BLOCK)
Receive data with the socket.
zmq::message_t Message
Define the type of message used by the PAbstractSocketManager.
Definition PZmqBackend.h:41
Set of parameters to be passed to create a socket with zmq backend.
Definition PZmqBackend.h:17
ssize_t dataRate
Data rate.
Definition PZmqBackend.h:27
int nbBufferMessage
Number of messages in the buffer.
Definition PZmqBackend.h:21
int bufferSizeByte
Size of the message buffer in bytes.
Definition PZmqBackend.h:23
int type
Socket type.
Definition PZmqBackend.h:19
size_t threadAffinity
Mask of threads which deal with reconnection.
Definition PZmqBackend.h:25