| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Pierre Aubert | ||
| 3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
| 4 | Licence : CeCILL-C | ||
| 5 | ****************************************/ | ||
| 6 | |||
| 7 | #ifndef __PGENERIC_SOCKET_MANAGER_H__ | ||
| 8 | #define __PGENERIC_SOCKET_MANAGER_H__ | ||
| 9 | |||
| 10 | #include <map> | ||
| 11 | #include "PGenericSocket.h" | ||
| 12 | #include "PEmptyBackend.h" | ||
| 13 | #include "PMockBackend.h" | ||
| 14 | |||
| 15 | ///@brief Socket manager for PGenericSocket | ||
| 16 | template<typename _TSocketKey, typename _TBackend, typename _TMockBackend> | ||
| 17 | class PGenericSocketManager{ | ||
| 18 | public: | ||
| 19 | typedef _TBackend Backend; | ||
| 20 | typedef _TMockBackend Mock; | ||
| 21 | PGenericSocketManager(PSocketMode::PSocketMode mode = PSocketMode::NO_MOCK); | ||
| 22 | virtual ~PGenericSocketManager(); | ||
| 23 | |||
| 24 | void setMode(PSocketMode::PSocketMode mode); | ||
| 25 | PSocketMode::PSocketMode getMode() const; | ||
| 26 | bool addClientSocket(const _TSocketKey & name, const PSocketParam & socketParam, const typename _TBackend::Param & param, const std::string & mockPrefix, const typename _TMockBackend::Param & mockParam); | ||
| 27 | bool addServerSocket(const _TSocketKey & name, const PSocketParam & socketParam, const typename _TBackend::Param & param, const std::string & mockPrefix, const typename _TMockBackend::Param & mockParam); | ||
| 28 | |||
| 29 | void removeSocket(const _TSocketKey & name); | ||
| 30 | void clear(); | ||
| 31 | |||
| 32 | ///Send data on the given socket | ||
| 33 | /** @param name : name of the socket to be used | ||
| 34 | * @param data : data to be sent | ||
| 35 | * @param flag : flag to be used to send the message (BLOCK, NON_BLOCK, etc) | ||
| 36 | * @return true on success, false otherwise | ||
| 37 | */ | ||
| 38 | template<typename U> | ||
| 39 | 10 | PSendStatus::PSendStatus sendData(const _TSocketKey & name, const U & data, PSendFlag::PSendFlag flag = PSendFlag::BLOCK){ | |
| 40 | 10 | PGenericSocket<_TBackend, _TMockBackend> * socket = getSocket(name); | |
| 41 |
1/2✓ Branch 0 (3→4) taken 10 times.
✗ Branch 1 (3→6) not taken.
|
10 | if(socket != NULL){ |
| 42 | 10 | return socket->sendData(data, flag); | |
| 43 | }else{ | ||
| 44 | ✗ | return PSendStatus::BROKEN_SOCKET; | |
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 48 | PSendStatus::PSendStatus sendMsg(const _TSocketKey & name, typename _TBackend::Message & msg, PSendFlag::PSendFlag flag = PSendFlag::BLOCK); | ||
| 49 | |||
| 50 | ///Receive data from the given socket | ||
| 51 | /** @param name : name of the socket to be used | ||
| 52 | * @param data : data to be received | ||
| 53 | * @param flag : flags to be used to send the message (BLOCK, NON_BLOCK, etc) | ||
| 54 | * @return PRecvStatus::PRecvStatus | ||
| 55 | */ | ||
| 56 | template<typename U> | ||
| 57 | 10 | PRecvStatus::PRecvStatus recvData(const _TSocketKey & name, U & data, PRecvFlag::PRecvFlag flag = PRecvFlag::BLOCK){ | |
| 58 | 10 | PGenericSocket<_TBackend, _TMockBackend> * socket = getSocket(name); | |
| 59 |
1/2✓ Branch 0 (3→4) taken 10 times.
✗ Branch 1 (3→6) not taken.
|
10 | if(socket != NULL){ |
| 60 | 10 | return socket->recvData(data, flag); | |
| 61 | }else{ | ||
| 62 | ✗ | return PRecvStatus::BROKEN_SOCKET; | |
| 63 | } | ||
| 64 | } | ||
| 65 | |||
| 66 | PRecvStatus::PRecvStatus recvMsg(const _TSocketKey & name, typename _TBackend::Message & msg, PRecvFlag::PRecvFlag flag = PRecvFlag::BLOCK); | ||
| 67 | |||
| 68 | PGenericSocket<_TBackend, _TMockBackend>* getSocket(const _TSocketKey & name); | ||
| 69 | bool isSocketExist(const _TSocketKey & name) const; | ||
| 70 | bool isConnected(const _TSocketKey & name) const; | ||
| 71 | |||
| 72 | private: | ||
| 73 | void initialisationPGenericSocketManager(PSocketMode::PSocketMode mode); | ||
| 74 | |||
| 75 | ///Mode of the Socket (no mock, mock, mock_record) | ||
| 76 | PSocketMode::PSocketMode p_mode; | ||
| 77 | |||
| 78 | ///Map of the zmq sockets to be used by the manager | ||
| 79 | std::map<_TSocketKey, PGenericSocket<_TBackend, _TMockBackend> *> p_mapSocket; | ||
| 80 | ///Instance of the backend | ||
| 81 | _TBackend p_backend; | ||
| 82 | ///Instance of the mock backend | ||
| 83 | _TMockBackend p_mockBackend; | ||
| 84 | |||
| 85 | }; | ||
| 86 | |||
| 87 | #include "PGenericSocketManager_impl.h" | ||
| 88 | |||
| 89 | |||
| 90 | #endif | ||
| 91 | |||
| 92 |