PhoenixZMQ  6.0.0
Library which integrates zeromq use
Loading...
Searching...
No Matches
PZmqBackend_impl.h
Go to the documentation of this file.
1/***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5****************************************/
6
7#ifndef __PZMQ_BACKEND_IMPL_H__
8#define __PZMQ_BACKEND_IMPL_H__
9
10#include <string>
11#include "phoenix_data_stream.h"
12#include "PZmqBackend.h"
13
15
18template <typename T>
19std::string statusToStr(T status) {
20 if constexpr (std::is_same_v<T, PSendStatus::PSendStatus>) {
21 switch (status) {
22 case PSendStatus::OK: return "OK";
23 case PSendStatus::SOCKET_NOT_AVAILABLE: return "SOCKET_NOT_AVAILABLE";
24 case PSendStatus::NO_ROUTE_TO_RECEIVER: return "NO_ROUTE_TO_RECEIVER";
25 case PSendStatus::SIGNAL_INTERRUPTION: return "SIGNAL_INTERRUPTION";
26 case PSendStatus::BROKEN_BACKEND: return "BROKEN_BACKEND";
27 case PSendStatus::BROKEN_SOCKET: return "BROKEN_SOCKET";
28 case PSendStatus::CANNOT_SERIALIZE_DATA: return "CANNOT_SERIALIZE_DATA";
29 default: return "UNKNOWN_SEND_STATUS";
30 }
31 } else if constexpr (std::is_same_v<T, PRecvStatus::PRecvStatus>) {
32 switch (status) {
33 case PRecvStatus::OK: return "OK";
34 case PRecvStatus::SOCKET_NOT_AVAILABLE: return "SOCKET_NOT_AVAILABLE";
35 case PRecvStatus::SIGNAL_INTERRUPTION: return "SIGNAL_INTERRUPTION";
36 case PRecvStatus::BROKEN_BACKEND: return "BROKEN_BACKEND";
37 case PRecvStatus::BROKEN_SOCKET: return "BROKEN_SOCKET";
38 case PRecvStatus::NO_MESSAGE_RECEIVED: return "NO_MESSAGE_RECEIVED";
39 case PRecvStatus::CANNOT_DESERIALIZE_DATA: return "CANNOT_DESERIALIZE_DATA";
40 default: return "UNKNOWN_RECV_STATUS";
41 }
42 } else {
43 return "UNKNOWN_STATUS_TYPE";
44 }
45}
46
48
52template<typename T>
53PSendStatus::PSendStatus PZmqSocket::sendData(const T & data, PSendFlag::PSendFlag flag){
54 size_t dataSize(data_size<T>(data));
55 Message msg;
56 msg.rebuild(dataSize);
57 DataStreamIter iter = (DataStreamIter)msg.data();
58 if(data_message_save<T>(iter, data)){ //Save the message
59 return sendMsg(msg, flag);
60 }else{
61 return PSendStatus::CANNOT_SERIALIZE_DATA;
62 }
63}
64
66
70template<typename T>
71PRecvStatus::PRecvStatus PZmqSocket::recvData(T & data, PRecvFlag::PRecvFlag flag){
72 PRecvStatus::PRecvStatus recvStatus = PRecvStatus::OK;
73 Message msg;
74 recvStatus = recvMsg(msg, flag);
75 if(recvStatus == PRecvStatus::OK){
76 //If the message is empty we cannot initialise the given data, so, this is an error
77 if(msg.size() != 0lu){
78 DataStreamIter iter = (DataStreamIter)msg.data();
79 if(!data_message_load<T>(iter, data)){
80 return PRecvStatus::CANNOT_DESERIALIZE_DATA;
81 }
82 }else{
83 return PRecvStatus::NO_MESSAGE_RECEIVED;
84 }
85 }
86
87 return recvStatus;
88}
89
90
91#endif
92
std::string statusToStr(T status)
Convert PSendStatus into string.
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.
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