| 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 | }; | ||
| 31 | |||
| 32 | PZmqParam pzmq_createParamClient(int type, int nbBufferMessage = 10000, int bufferSizeByte = 1000000, size_t threadAffinity = 0lu, ssize_t dataRate = 200000l, int linger = -1); | ||
| 33 | PZmqParam pzmq_createParamServer(int type, int nbBufferMessage = 10000, int bufferSizeByte = 1000000, size_t threadAffinity = 0lu, ssize_t dataRate = 200000l, int linger = -1); | ||
| 34 | template <typename T> | ||
| 35 | std::string statusToStr(T status); | ||
| 36 | PSendStatus::PSendStatus checkSendStatus(zmq::send_result_t res); | ||
| 37 | PRecvStatus::PRecvStatus checkRecvStatus(zmq::recv_result_t res); | ||
| 38 | |||
| 39 | ///@brief PhoenixSocket API bridge to ZMQ socket | ||
| 40 | class PZmqSocket{ | ||
| 41 | public: | ||
| 42 | ///Define the type of message used by the PAbstractSocketManager | ||
| 43 | typedef zmq::message_t Message; | ||
| 44 | ///Define the type of extra parameters which can be used to create a Socket used by the PAbstractSocketManager | ||
| 45 | typedef PZmqParam Param; | ||
| 46 | |||
| 47 | PZmqSocket(); | ||
| 48 | virtual ~PZmqSocket(); | ||
| 49 | |||
| 50 | bool createClientSocket(zmq::context_t & context, const PSocketParam & socketParam, const Param & extraParam); | ||
| 51 | bool createServerSocket(zmq::context_t & context, const PSocketParam & socketParam, const Param & extraParam); | ||
| 52 | |||
| 53 | template<typename T> | ||
| 54 | PSendStatus::PSendStatus sendData(const T & data, PSendFlag::PSendFlag flag = PSendFlag::BLOCK); | ||
| 55 | PSendStatus::PSendStatus sendMsg(Message & msg, PSendFlag::PSendFlag flag = PSendFlag::BLOCK); | ||
| 56 | |||
| 57 | template<typename T> | ||
| 58 | PRecvStatus::PRecvStatus recvData(T & data, PRecvFlag::PRecvFlag flag = PRecvFlag::BLOCK); | ||
| 59 | PRecvStatus::PRecvStatus recvMsg(Message & msg, PRecvFlag::PRecvFlag flag = PRecvFlag::BLOCK); | ||
| 60 | |||
| 61 | bool isConnected() const; | ||
| 62 | void close(); | ||
| 63 | private: | ||
| 64 | ///ZMQ Socket | ||
| 65 | zmq::socket_t* p_socket; | ||
| 66 | }; | ||
| 67 | |||
| 68 | ///@brief Backend to use Mock library with PAbstractSocket | ||
| 69 | class PZmqSocketGenerator{ | ||
| 70 | public: | ||
| 71 | ///Define the socket of the backend used by the PAbstractSocketManager | ||
| 72 | typedef PZmqSocket Socket; | ||
| 73 | ///Define the type of message used by the PAbstractSocketManager | ||
| 74 | typedef zmq::message_t Message; | ||
| 75 | ///Define the type of extra parameters which can be used to create a Socket used by the PAbstractSocketManager | ||
| 76 | typedef PZmqParam Param; | ||
| 77 | |||
| 78 | PZmqSocketGenerator(); | ||
| 79 | |||
| 80 | static Param client(); | ||
| 81 | static Param server(); | ||
| 82 | |||
| 83 | bool createClientSocket(Socket & socket, const PSocketParam & socketParam, const PZmqParam & param); | ||
| 84 | bool createServerSocket(Socket & socket, const PSocketParam & socketParam, const PZmqParam & param); | ||
| 85 | |||
| 86 | static void msgToMock(DataStreamMsg & mockMsg, const Message & msg); | ||
| 87 | static void mockToMsg(Message & msg, DataStreamMsg & mockMsg); | ||
| 88 | |||
| 89 | private: | ||
| 90 | ///Context ZMQ | ||
| 91 | zmq::context_t p_context; | ||
| 92 | }; | ||
| 93 | |||
| 94 | #include "PZmqBackend_impl.h" | ||
| 95 | |||
| 96 | #endif | ||
| 97 | |||
| 98 |