GCC Code Coverage Report


Directory: ./
File: tmp_project/PhoenixSocket/src/PGenericSocketManager_impl.h
Date: 2025-03-14 12:18:05
Exec Total Coverage
Lines: 50 54 92.6%
Branches: 16 26 61.5%

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