PhoenixSocket  4.0.1
Library which integrates socket unix use in Phoenix
Loading...
Searching...
No Matches
PGenericSocketManager_impl.h
Go to the documentation of this file.
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
11
13
15template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
19
21template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
25
27
29template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
31 p_mode = mode;
32 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}
36
38
40template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
44
46
53template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
54bool PGenericSocketManager<_TSocketKey, _TBackend, _TMockBackend>::addClientSocket(const _TSocketKey & name, const PSocketParam & socketParam, const typename _TBackend::Param & param, const std::string & mockPrefix, const typename _TMockBackend::Param & mockParam)
55{
57 bool b(socket != NULL);
58 if(b){
59 b &= socket->createClientSocket(p_backend, p_mockBackend, socketParam, param, mockPrefix, mockParam);
60 //Add socket in any case to be able to destroy it in the destructor
61 p_mapSocket[name] = socket; //Check if there is no problem with failed socket creation which are destroyed afterward
62 }
63 return b;
64}
65
67
74template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
75bool PGenericSocketManager<_TSocketKey, _TBackend, _TMockBackend>::addServerSocket(const _TSocketKey & name, const PSocketParam & socketParam, const typename _TBackend::Param & param, const std::string & mockPrefix, const typename _TMockBackend::Param & mockParam)
76{
78 bool b(socket != NULL);
79 if(b){
80 b &= socket->createServerSocket(p_backend, p_mockBackend, socketParam, param, mockPrefix, mockParam);
81 //Add socket in any case to be able to destroy it in the destructor
82 p_mapSocket[name] = socket; //Check if there is not problem with failed socket creation which are destroyed afterward
83 }
84 return b;
85}
86
88
90template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
92 typename std::map<_TSocketKey, PGenericSocket<_TBackend, _TMockBackend>* >::iterator it(p_mapSocket.find(name));
93 if(it != p_mapSocket.end()){
94 delete it->second;
95 p_mapSocket.erase(it);
96 }
97}
98
100template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
102 for(typename std::map<_TSocketKey, PGenericSocket<_TBackend, _TMockBackend>* >::iterator it(p_mapSocket.begin()); it != p_mapSocket.end(); ++it){
103 it->second->close();
104 delete it->second;
105 }
106 p_mapSocket.clear();
107}
108
110
115template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
118 if(socket != NULL){
119 return socket->sendMsg(msg, flag);
120 }else{
122 }
123}
124
126
131template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
134 if(socket != NULL){
135 return socket->recvMsg(msg, flag);
136 }else{
138 }
139}
140
142
145template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
147{
148 typename std::map<_TSocketKey, PGenericSocket<_TBackend, _TMockBackend>* >::iterator it(p_mapSocket.find(name));
149 if(it != p_mapSocket.end()){
150 return it->second;
151 }else{
152 return NULL;
153 }
154}
155
157
160template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
162 typename std::map<_TSocketKey, PGenericSocket<_TBackend, _TMockBackend>* >::const_iterator it(p_mapSocket.find(name));
163 return it != p_mapSocket.end();
164}
165
167
170template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
172 typename std::map<_TSocketKey, PGenericSocket<_TBackend, _TMockBackend>* >::const_iterator it(p_mapSocket.find(name));
173 if(it != p_mapSocket.end()){
174 return it->second->isConnected();
175 }
176 return false;
177}
178
179
181
183template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
187
188
189
190
191
192#endif
193
194
195
bool isSocketExist(const _TSocketKey &name) const
Say if the socket exist with the given name.
bool isConnected(const _TSocketKey &name) const
Say if the given socket is connected.
std::map< _TSocketKey, PGenericSocket< _TBackend, _TMockBackend > * > p_mapSocket
Map of the zmq sockets to be used by the manager.
PGenericSocket< _TBackend, _TMockBackend > * getSocket(const _TSocketKey &name)
Get a socket by name (or key)
PSocketMode::PSocketMode p_mode
Mode of the Socket (no mock, mock, mock_record)
bool addClientSocket(const _TSocketKey &name, const PSocketParam &socketParam, const typename _TBackend::Param &param, const std::string &mockPrefix, const typename _TMockBackend::Param &mockParam)
Create a client socket.
void removeSocket(const _TSocketKey &name)
Remove the given socket.
PGenericSocketManager(PSocketMode::PSocketMode mode=PSocketMode::NO_MOCK)
Default constructor of PGenericSocketManager.
void setMode(PSocketMode::PSocketMode mode)
Set if the current PGenericSocketManager is a mock.
_TMockBackend p_mockBackend
Instance of the mock backend.
_TBackend p_backend
Instance of the backend.
virtual ~PGenericSocketManager()
Destructor of PGenericSocketManager.
PSendStatus::PSendStatus sendMsg(const _TSocketKey &name, typename _TBackend::Message &msg, PSendFlag::PSendFlag flag=PSendFlag::BLOCK)
Send message on the given socket.
PSocketMode::PSocketMode getMode() const
Get if the current PGenericSocketManager is a mock.
PRecvStatus::PRecvStatus recvMsg(const _TSocketKey &name, typename _TBackend::Message &msg, PRecvFlag::PRecvFlag flag=PRecvFlag::BLOCK)
Receive message from the given socket.
bool addServerSocket(const _TSocketKey &name, const PSocketParam &socketParam, const typename _TBackend::Param &param, const std::string &mockPrefix, const typename _TMockBackend::Param &mockParam)
Create a server socket.
void clear()
Clear the map of socket.
void initialisationPGenericSocketManager(PSocketMode::PSocketMode mode)
Initialisation function of the class PGenericSocketManager.
Abstract socket which has a mock mode to avoid heavy socket backend for unit tests.
PSendStatus::PSendStatus sendMsg(typename _TBackend::Message &msg, PSendFlag::PSendFlag flag)
Send message on the given socket.
PRecvStatus::PRecvStatus recvMsg(typename _TBackend::Message &msg, PRecvFlag::PRecvFlag flag)
Receive message from the given socket.
bool createClientSocket(_TBackend &backend, _TMockBackend &mockBackend, const PSocketParam &socketParam, const typename _TBackend::Param &param, const std::string &mockPrefix, const typename _TMockBackend::Param &mockParam)
Create a client socket.
bool createServerSocket(_TBackend &backend, _TMockBackend &mockBackend, const PSocketParam &socketParam, const typename _TBackend::Param &param, const std::string &mockPrefix, const typename _TMockBackend::Param &mockParam)
Create a server socket.
PRecvFlag
describe the receiving flag of the Socket
Definition PSocketFlag.h:41
PRecvStatus
describe the result of the recv
Definition PSocketFlag.h:52
PSendFlag
describe the sending flag of the Socket
Definition PSocketFlag.h:14
PSendStatus
describe the result of the send
Definition PSocketFlag.h:25
PSocketMode
describe the mode of the Socket
Definition PSocketMode.h:12
Parameters to create a socket.
Definition PSocketFlag.h:68