GCC Code Coverage Report


Directory: ./
File: tmp_project/PhoenixSocket/src/PGenericSocketManager.h
Date: 2025-03-14 12:18:05
Exec Total Coverage
Lines: 8 10 80.0%
Branches: 2 4 50.0%

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 typename _TBackend::Param & param, const typename _TMockBackend::Param & mockParam);
27 bool addServerSocket(const _TSocketKey & name, const typename _TBackend::Param & param, 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 22 bool sendData(const _TSocketKey & name, const U & data, PSendFlag::PSendFlag flag = PSendFlag::BLOCK){
40 22 PGenericSocket<_TBackend, _TMockBackend> * socket = getSocket(name);
41
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(socket != NULL){
42 22 return socket->sendData(data, flag);
43 }else{
44 return false;
45 }
46 }
47
48 bool sendMsg(const _TSocketKey & name, typename _TBackend::Message & msg, PSendFlag::PSendFlag flag = PSendFlag::BLOCK);
49
50 ///Recieve data from the given socket
51 /** @param name : name of the socket to be used
52 * @param data : data to be recieved
53 * @param flag : flags to be used to send the message (BLOCK, NON_BLOCK, etc)
54 * @return true on success, false otherwise
55 */
56 template<typename U>
57 28 bool recvData(const _TSocketKey & name, U & data, PRecvFlag::PRecvFlag flag = PRecvFlag::BLOCK){
58 28 PGenericSocket<_TBackend, _TMockBackend> * socket = getSocket(name);
59
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 if(socket != NULL){
60 28 return socket->recvData(data, flag);
61 }else{
62 return false;
63 }
64 }
65
66 bool 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
81 };
82
83 #include "PGenericSocketManager_impl.h"
84
85
86 #endif
87
88