| Line | Branch | Exec | Source |
|---|---|---|---|
| 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 | |||
| 14 | ///Convert PSendStatus into string | ||
| 15 | /** @param status : PSendStatus to be converted | ||
| 16 | * @return corresponding string | ||
| 17 | */ | ||
| 18 | template <typename T> | ||
| 19 | 7 | std::string statusToStr(T status) { | |
| 20 | if constexpr (std::is_same_v<T, PSendStatus::PSendStatus>) { | ||
| 21 |
3/8✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→8) taken 1 times.
✗ Branch 2 (2→13) not taken.
✗ Branch 3 (2→18) not taken.
✓ Branch 4 (2→23) taken 1 times.
✓ Branch 5 (2→28) taken 1 times.
✗ Branch 6 (2→33) not taken.
✗ Branch 7 (2→38) not taken.
|
3 | switch (status) { |
| 22 | ✗ | case PSendStatus::OK: return "OK"; | |
| 23 |
1/1✓ Branch 0 (10→11) taken 1 times.
|
3 | 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 |
1/1✓ Branch 0 (25→26) taken 1 times.
|
3 | case PSendStatus::BROKEN_BACKEND: return "BROKEN_BACKEND"; |
| 27 |
1/1✓ Branch 0 (30→31) taken 1 times.
|
3 | 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 |
3/8✗ Branch 0 (2→3) not taken.
✗ Branch 1 (2→8) not taken.
✗ Branch 2 (2→13) not taken.
✓ Branch 3 (2→18) taken 2 times.
✓ Branch 4 (2→23) taken 1 times.
✓ Branch 5 (2→28) taken 1 times.
✗ Branch 6 (2→33) not taken.
✗ Branch 7 (2→38) not taken.
|
4 | 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 |
1/1✓ Branch 0 (20→21) taken 2 times.
|
6 | case PRecvStatus::BROKEN_BACKEND: return "BROKEN_BACKEND"; |
| 37 |
1/1✓ Branch 0 (25→26) taken 1 times.
|
3 | case PRecvStatus::BROKEN_SOCKET: return "BROKEN_SOCKET"; |
| 38 |
1/1✓ Branch 0 (30→31) taken 1 times.
|
3 | 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 | |||
| 47 | ///Send data with the socket | ||
| 48 | /** @param data : data to be sent with the socket | ||
| 49 | * @param flag : sending flag (BLOCK, NON_BLOCK) | ||
| 50 | * @return status of the send | ||
| 51 | */ | ||
| 52 | template<typename T> | ||
| 53 | 194 | PSendStatus::PSendStatus PZmqSocket::sendData(const T & data, PSendFlag::PSendFlag flag){ | |
| 54 |
1/1✓ Branch 0 (2→3) taken 194 times.
|
194 | size_t dataSize(data_size<T>(data)); |
| 55 | 194 | Message msg; | |
| 56 |
1/1✓ Branch 0 (4→5) taken 194 times.
|
194 | msg.rebuild(dataSize); |
| 57 | 194 | DataStreamIter iter = (DataStreamIter)msg.data(); | |
| 58 |
2/3✓ Branch 0 (6→7) taken 194 times.
✓ Branch 2 (7→8) taken 194 times.
✗ Branch 3 (7→10) not taken.
|
194 | if(data_message_save<T>(iter, data)){ //Save the message |
| 59 |
1/1✓ Branch 0 (8→9) taken 194 times.
|
194 | return sendMsg(msg, flag); |
| 60 | }else{ | ||
| 61 | ✗ | return PSendStatus::CANNOT_SERIALIZE_DATA; | |
| 62 | } | ||
| 63 | 194 | } | |
| 64 | |||
| 65 | ///Recieved data with the socket | ||
| 66 | /** @param[out] data : data to be recieved with the socket | ||
| 67 | * @param flag : recieving flag (BLOCK, NON_BLOCK) | ||
| 68 | * @return status of the recv | ||
| 69 | */ | ||
| 70 | template<typename T> | ||
| 71 | 197 | PRecvStatus::PRecvStatus PZmqSocket::recvData(T & data, PRecvFlag::PRecvFlag flag){ | |
| 72 | 197 | PRecvStatus::PRecvStatus recvStatus = PRecvStatus::OK; | |
| 73 | 197 | Message msg; | |
| 74 |
1/1✓ Branch 0 (3→4) taken 197 times.
|
197 | recvStatus = recvMsg(msg, flag); |
| 75 |
2/2✓ Branch 0 (4→5) taken 20 times.
✓ Branch 1 (4→13) taken 177 times.
|
197 | if(recvStatus == PRecvStatus::OK){ |
| 76 | //If the message is empty we cannot initialise the given data, so, this is an error | ||
| 77 |
1/2✓ Branch 0 (6→7) taken 20 times.
✗ Branch 1 (6→12) not taken.
|
20 | if(msg.size() != 0lu){ |
| 78 | 20 | DataStreamIter iter = (DataStreamIter)msg.data(); | |
| 79 |
2/3✓ Branch 0 (8→9) taken 20 times.
✗ Branch 2 (9→10) not taken.
✓ Branch 3 (9→11) taken 20 times.
|
20 | 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 | 197 | return recvStatus; | |
| 88 | 197 | } | |
| 89 | |||
| 90 | |||
| 91 | #endif | ||
| 92 | |||
| 93 |