GCC Code Coverage Report


Directory: ./
File: src/PGenericSocketManager_impl.h
Date: 2025-09-10 13:03:48
Exec Total Coverage
Lines: 51 56 91.1%
Functions: 11 12 91.7%
Branches: 20 37 54.1%

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_IMPL__
8 #define __PGENERIC_SOCKET_MANAGER_H_IMPL__
9
10 #include "PGenericSocketManager.h"
11
12 ///Default constructor of PGenericSocketManager
13 /** @param mode : Mode of the Socket (no mock, mock, mock_record)
14 */
15 template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
16 4 PGenericSocketManager<_TSocketKey, _TBackend, _TMockBackend>::PGenericSocketManager(PSocketMode::PSocketMode mode){
17 4 initialisationPGenericSocketManager(mode);
18 4 }
19
20 ///Destructor of PGenericSocketManager
21 template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
22 4 PGenericSocketManager<_TSocketKey, _TBackend, _TMockBackend>::~PGenericSocketManager(){
23 4 clear();
24 4 }
25
26 ///Set if the current PGenericSocketManager is a mock
27 /** @param mode : Mode of the Socket (no mock, mock, mock_record)
28 */
29 template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
30 1 void PGenericSocketManager<_TSocketKey, _TBackend, _TMockBackend>::setMode(PSocketMode::PSocketMode mode){
31 1 p_mode = mode;
32
1/2
✗ Branch 0 (8→3) not taken.
✓ Branch 1 (8→9) taken 1 times.
1 for(typename std::map<_TSocketKey, PGenericSocket<_TBackend, _TMockBackend>* >::iterator it(p_mapSocket.begin()); it != p_mapSocket.end(); ++it){
33 it->second->setMode(mode);
34 }
35 1 }
36
37 ///Get if the current PGenericSocketManager is a mock
38 /** @return Mode of the Socket (no mock, mock, mock_record)
39 */
40 template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
41 PSocketMode::PSocketMode PGenericSocketManager<_TSocketKey, _TBackend, _TMockBackend>::getMode() const{
42 return p_mode;
43 }
44
45 ///Create a client socket
46 /** @param name : name (key) to get the socket
47 * @param address : address of the server, the client has to connect to
48 * @param port : port to be used for the connection
49 * @param param : extra customisable parameters for the creation of the socket (depends on the backend)
50 * @param mockPrefix : prefix to find and szve the mock
51 * @param mockParam : parameters to initialise the mock
52 * @return true if the socket has been created, false otherwise
53 */
54 template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
55 2 bool PGenericSocketManager<_TSocketKey, _TBackend, _TMockBackend>::addClientSocket(const _TSocketKey & name, const std::string & host, size_t port, const typename _TBackend::Param & param, const std::string & mockPrefix, const typename _TMockBackend::Param & mockParam)
56 {
57
2/5
✓ Branch 0 (3→4) taken 2 times.
✗ Branch 2 (4→5) not taken.
✓ Branch 3 (4→6) taken 2 times.
✗ Branch 4 (13→14) not taken.
✗ Branch 5 (13→15) not taken.
2 PGenericSocket<_TBackend, _TMockBackend>* socket = new PGenericSocket<_TBackend, _TMockBackend>(p_mode);
58 2 bool b(socket != NULL);
59
1/2
✓ Branch 0 (6→7) taken 2 times.
✗ Branch 1 (6→11) not taken.
2 if(b){
60 2 b &= socket->createClientSocket(host, port, param, mockPrefix, mockParam);
61
1/2
✓ Branch 0 (8→9) taken 2 times.
✗ Branch 1 (8→11) not taken.
2 if(b){
62 2 p_mapSocket[name] = socket;
63 }
64 }
65 2 return b;
66 }
67
68 ///Create a server socket
69 /** @param name : name (key) to get the socket
70 * @param address : address of the server, the client has to connect to
71 * @param port : port to be used for the connection
72 * @param param : extra customisable parameters for the creation of the socket (depends on the backend)
73 * @param mockPrefix : prefix to find and szve the mock
74 * @param mockParam : parameters to initialise the mock
75 * @return true if the socket has been created, false otherwise
76 */
77 template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
78 2 bool PGenericSocketManager<_TSocketKey, _TBackend, _TMockBackend>::addServerSocket(const _TSocketKey & name, const std::string & host, size_t port, const typename _TBackend::Param & param, const std::string & mockPrefix, const typename _TMockBackend::Param & mockParam)
79 {
80
2/5
✓ Branch 0 (3→4) taken 2 times.
✗ Branch 2 (4→5) not taken.
✓ Branch 3 (4→6) taken 2 times.
✗ Branch 4 (13→14) not taken.
✗ Branch 5 (13→15) not taken.
2 PGenericSocket<_TBackend, _TMockBackend>* socket = new PGenericSocket<_TBackend, _TMockBackend>(p_mode);
81 2 bool b(socket != NULL);
82
1/2
✓ Branch 0 (6→7) taken 2 times.
✗ Branch 1 (6→11) not taken.
2 if(b){
83 2 b &= socket->createServerSocket(host, port, param, mockPrefix, mockParam);
84
1/2
✓ Branch 0 (8→9) taken 2 times.
✗ Branch 1 (8→11) not taken.
2 if(b){
85 2 p_mapSocket[name] = socket;
86 }
87 }
88 2 return b;
89 }
90
91 ///Remove the given socket
92 /** @param name : name (key) of the socket to be removed
93 */
94 template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
95 void PGenericSocketManager<_TSocketKey, _TBackend, _TMockBackend>::removeSocket(const _TSocketKey & name){
96 typename std::map<_TSocketKey, PGenericSocket<_TBackend, _TMockBackend>* >::iterator it(p_mapSocket.find(name));
97 if(it != p_mapSocket.end()){
98 delete it->second;
99 p_mapSocket.erase(it);
100 }
101 }
102
103 ///Clear the map of socket
104 template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
105 4 void PGenericSocketManager<_TSocketKey, _TBackend, _TMockBackend>::clear(){
106
2/2
✓ Branch 0 (11→3) taken 4 times.
✓ Branch 1 (11→12) taken 4 times.
8 for(typename std::map<_TSocketKey, PGenericSocket<_TBackend, _TMockBackend>* >::iterator it(p_mapSocket.begin()); it != p_mapSocket.end(); ++it){
107
1/1
✓ Branch 0 (4→5) taken 4 times.
4 it->second->close();
108
1/2
✓ Branch 0 (6→7) taken 4 times.
✗ Branch 1 (6→8) not taken.
4 delete it->second;
109 }
110 4 p_mapSocket.clear();
111 4 }
112
113 ///Send message on the given socket
114 /** @param name : name of the socket to be used
115 * @param msg : message to be sent
116 * @param flag : flags to be used to send the message (BLOCK, NON_BLOCK, etc)
117 * @return true on success, false otherwise
118 */
119 template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
120 10 bool PGenericSocketManager<_TSocketKey, _TBackend, _TMockBackend>::sendMsg(const _TSocketKey & name, typename _TBackend::Message & msg, PSendFlag::PSendFlag flag){
121 10 PGenericSocket<_TBackend, _TMockBackend> * socket = getSocket(name);
122
1/2
✓ Branch 0 (3→4) taken 10 times.
✗ Branch 1 (3→6) not taken.
10 if(socket != NULL){
123 10 return socket->sendMsg(msg, flag);
124 }else{
125 return false;
126 }
127 }
128
129 ///Recieve message from the given socket
130 /** @param name : name of the socket to be used
131 * @param msg : message to be recieved
132 * @param flag : flags to be used to send the message (BLOCK, NON_BLOCK, etc)
133 * @return true on success, false otherwise
134 */
135 template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
136 10 bool PGenericSocketManager<_TSocketKey, _TBackend, _TMockBackend>::recvMsg(const _TSocketKey & name, typename _TBackend::Message & msg, PRecvFlag::PRecvFlag flag){
137 10 PGenericSocket<_TBackend, _TMockBackend> * socket = getSocket(name);
138
1/2
✓ Branch 0 (3→4) taken 10 times.
✗ Branch 1 (3→6) not taken.
10 if(socket != NULL){
139 10 return socket->recvMsg(msg, flag);
140 }else{
141 return false;
142 }
143 }
144
145 ///Get a socket by name (or key)
146 /** @param name : of the socket to be used
147 * @return pointer to the found socket, or NULL if the socket does not exist
148 */
149 template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
150 40 PGenericSocket<_TBackend, _TMockBackend>* PGenericSocketManager<_TSocketKey, _TBackend, _TMockBackend>::getSocket(const _TSocketKey & name)
151 {
152
1/1
✓ Branch 0 (2→3) taken 40 times.
40 typename std::map<_TSocketKey, PGenericSocket<_TBackend, _TMockBackend>* >::iterator it(p_mapSocket.find(name));
153
1/2
✓ Branch 0 (5→6) taken 40 times.
✗ Branch 1 (5→8) not taken.
40 if(it != p_mapSocket.end()){
154 40 return it->second;
155 }else{
156 return NULL;
157 }
158 }
159
160 ///Say if the socket exist with the given name
161 /** @param name : of the socket to be used
162 * @return true if the socket exists, false otherwise
163 */
164 template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
165 bool PGenericSocketManager<_TSocketKey, _TBackend, _TMockBackend>::isSocketExist(const _TSocketKey & name) const{
166 typename std::map<_TSocketKey, PGenericSocket<_TBackend, _TMockBackend>* >::const_iterator it(p_mapSocket.find(name));
167 return it != p_mapSocket.end();
168 }
169
170 ///Say if the given socket is connected
171 /** @param name : name of the socket to be checked
172 * @return true if the socket exists and is connected, false otherwise
173 */
174 template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
175 2 bool PGenericSocketManager<_TSocketKey, _TBackend, _TMockBackend>::isConnected(const _TSocketKey & name) const{
176
1/1
✓ Branch 0 (2→3) taken 2 times.
2 typename std::map<_TSocketKey, PGenericSocket<_TBackend, _TMockBackend>* >::const_iterator it(p_mapSocket.find(name));
177
1/2
✓ Branch 0 (5→6) taken 2 times.
✗ Branch 1 (5→9) not taken.
2 if(it != p_mapSocket.end()){
178
1/1
✓ Branch 0 (7→8) taken 2 times.
2 return it->second->isConnected();
179 }
180 return false;
181 }
182
183
184 ///Initialisation function of the class PGenericSocketManager
185 /** @param mode : Mode of the Socket (no mock, mock, mock_record)
186 */
187 template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
188 4 void PGenericSocketManager<_TSocketKey, _TBackend, _TMockBackend>::initialisationPGenericSocketManager(PSocketMode::PSocketMode mode){
189 4 p_mode = mode;
190 4 }
191
192
193
194
195
196 #endif
197
198
199
200