PhoenixSocket  4.0.1
Library which integrates socket unix use in Phoenix
Loading...
Searching...
No Matches
PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend > Class Template Reference

Socket manager for PGenericSocket. More...

#include <PGenericSocketManager.h>

Public Types

typedef _TBackend Backend
 
typedef _TMockBackend Mock
 

Public Member Functions

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.
 
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.
 
PSocketMode::PSocketMode getMode () const
 Get if the current PGenericSocketManager is a mock.
 
PGenericSocket< _TBackend, _TMockBackend > * getSocket (const _TSocketKey &name)
 Get a socket by name (or key)
 
bool isConnected (const _TSocketKey &name) const
 Say if the given socket is connected.
 
bool isSocketExist (const _TSocketKey &name) const
 Say if the socket exist with the given name.
 
 PGenericSocketManager (PSocketMode::PSocketMode mode=PSocketMode::NO_MOCK)
 Default constructor of PGenericSocketManager.
 
template<typename U>
PRecvStatus::PRecvStatus recvData (const _TSocketKey &name, U &data, PRecvFlag::PRecvFlag flag=PRecvFlag::BLOCK)
 Receive data from the given socket.
 
PRecvStatus::PRecvStatus recvMsg (const _TSocketKey &name, typename _TBackend::Message &msg, PRecvFlag::PRecvFlag flag=PRecvFlag::BLOCK)
 Receive message from the given socket.
 
void removeSocket (const _TSocketKey &name)
 Remove the given socket.
 
template<typename U>
PSendStatus::PSendStatus sendData (const _TSocketKey &name, const U &data, PSendFlag::PSendFlag flag=PSendFlag::BLOCK)
 Send data on the given socket.
 
PSendStatus::PSendStatus sendMsg (const _TSocketKey &name, typename _TBackend::Message &msg, PSendFlag::PSendFlag flag=PSendFlag::BLOCK)
 Send message on the given socket.
 
void setMode (PSocketMode::PSocketMode mode)
 Set if the current PGenericSocketManager is a mock.
 
virtual ~PGenericSocketManager ()
 Destructor of PGenericSocketManager.
 

Private Member Functions

void initialisationPGenericSocketManager (PSocketMode::PSocketMode mode)
 Initialisation function of the class PGenericSocketManager.
 

Private Attributes

_TBackend p_backend
 Instance of the backend.
 
std::map< _TSocketKey, PGenericSocket< _TBackend, _TMockBackend > * > p_mapSocket
 Map of the zmq sockets to be used by the manager.
 
_TMockBackend p_mockBackend
 Instance of the mock backend.
 
PSocketMode::PSocketMode p_mode
 Mode of the Socket (no mock, mock, mock_record)
 

Detailed Description

template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
class PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >

Socket manager for PGenericSocket.

Definition at line 17 of file PGenericSocketManager.h.

Member Typedef Documentation

◆ Backend

template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
typedef _TBackend PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::Backend

Definition at line 19 of file PGenericSocketManager.h.

◆ Mock

template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
typedef _TMockBackend PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::Mock

Definition at line 20 of file PGenericSocketManager.h.

Constructor & Destructor Documentation

◆ PGenericSocketManager()

template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::PGenericSocketManager ( PSocketMode::PSocketMode mode = PSocketMode::NO_MOCK)

Default constructor of PGenericSocketManager.

Parameters
mode: Mode of the Socket (no mock, mock, mock_record)

Definition at line 16 of file PGenericSocketManager_impl.h.

16 {
18}
Socket manager for PGenericSocket.
void initialisationPGenericSocketManager(PSocketMode::PSocketMode mode)
Initialisation function of the class PGenericSocketManager.

References initialisationPGenericSocketManager().

+ Here is the call graph for this function:

◆ ~PGenericSocketManager()

template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::~PGenericSocketManager ( )
virtual

Destructor of PGenericSocketManager.

Definition at line 22 of file PGenericSocketManager_impl.h.

22 {
23 clear();
24}
void clear()
Clear the map of socket.

References clear().

+ Here is the call graph for this function:

Member Function Documentation

◆ addClientSocket()

template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
bool 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 )

Create a client socket.

Parameters
name: name (key) to get the socket
socketParam: parameters of the socket (host, port, send/recv timeout)
param: extra customisable parameters for the creation of the socket (depends on the backend)
mockPrefix: prefix to find and szve the mock
mockParam: parameters to initialise the mock
Returns
true if the socket has been created, false otherwise

Definition at line 54 of file PGenericSocketManager_impl.h.

55{
57 bool b(socket != NULL);
58 if(b){
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}
std::map< _TSocketKey, PGenericSocket< _TBackend, _TMockBackend > * > p_mapSocket
Map of the zmq sockets to be used by the manager.
PSocketMode::PSocketMode p_mode
Mode of the Socket (no mock, mock, mock_record)
_TMockBackend p_mockBackend
Instance of the mock backend.
_TBackend p_backend
Instance of the backend.

References PGenericSocket< _TBackend, _TMockBackend >::createClientSocket(), p_backend, p_mapSocket, p_mockBackend, and p_mode.

+ Here is the call graph for this function:

◆ addServerSocket()

template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
bool 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 )

Create a server socket.

Parameters
name: name (key) to get the socket
socketParam: parameters of the socket (host, port, send/recv timeout)
param: extra customisable parameters for the creation of the socket (depends on the backend)
mockPrefix: prefix to find and szve the mock
mockParam: parameters to initialise the mock
Returns
true if the socket has been created, false otherwise

Definition at line 75 of file PGenericSocketManager_impl.h.

76{
78 bool b(socket != NULL);
79 if(b){
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}

References PGenericSocket< _TBackend, _TMockBackend >::createServerSocket(), p_backend, p_mapSocket, p_mockBackend, and p_mode.

+ Here is the call graph for this function:

◆ clear()

template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
void PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::clear ( )

Clear the map of socket.

Definition at line 101 of file PGenericSocketManager_impl.h.

101 {
103 it->second->close();
104 delete it->second;
105 }
106 p_mapSocket.clear();
107}

References p_mapSocket.

Referenced by ~PGenericSocketManager().

+ Here is the caller graph for this function:

◆ getMode()

template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
PSocketMode::PSocketMode PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::getMode ( ) const

Get if the current PGenericSocketManager is a mock.

Returns
Mode of the Socket (no mock, mock, mock_record)

Definition at line 41 of file PGenericSocketManager_impl.h.

41 {
42 return p_mode;
43}

References p_mode.

◆ getSocket()

template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
PGenericSocket< _TBackend, _TMockBackend > * PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::getSocket ( const _TSocketKey & name)

Get a socket by name (or key)

Parameters
name: of the socket to be used
Returns
pointer to the found socket, or NULL if the socket does not exist

Definition at line 146 of file PGenericSocketManager_impl.h.

147{
149 if(it != p_mapSocket.end()){
150 return it->second;
151 }else{
152 return NULL;
153 }
154}

References p_mapSocket.

Referenced by recvData(), recvMsg(), sendData(), and sendMsg().

+ Here is the caller graph for this function:

◆ initialisationPGenericSocketManager()

template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
void PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::initialisationPGenericSocketManager ( PSocketMode::PSocketMode mode)
private

Initialisation function of the class PGenericSocketManager.

Parameters
mode: Mode of the Socket (no mock, mock, mock_record)

Definition at line 184 of file PGenericSocketManager_impl.h.

184 {
185 p_mode = mode;
186}

References p_mode.

Referenced by PGenericSocketManager().

+ Here is the caller graph for this function:

◆ isConnected()

template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
bool PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::isConnected ( const _TSocketKey & name) const

Say if the given socket is connected.

Parameters
name: name of the socket to be checked
Returns
true if the socket exists and is connected, false otherwise

Definition at line 171 of file PGenericSocketManager_impl.h.

171 {
173 if(it != p_mapSocket.end()){
174 return it->second->isConnected();
175 }
176 return false;
177}
bool isConnected(const _TSocketKey &name) const
Say if the given socket is connected.

References p_mapSocket.

◆ isSocketExist()

template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
bool PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::isSocketExist ( const _TSocketKey & name) const

Say if the socket exist with the given name.

Parameters
name: of the socket to be used
Returns
true if the socket exists, false otherwise

Definition at line 161 of file PGenericSocketManager_impl.h.

References p_mapSocket.

◆ recvData()

template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
template<typename U>
PRecvStatus::PRecvStatus PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::recvData ( const _TSocketKey & name,
U & data,
PRecvFlag::PRecvFlag flag = PRecvFlag::BLOCK )
inline

Receive data from the given socket.

Parameters
name: name of the socket to be used
data: data to be received
flag: flags to be used to send the message (BLOCK, NON_BLOCK, etc)
Returns
PRecvStatus::PRecvStatus

Definition at line 57 of file PGenericSocketManager.h.

57 {
59 if(socket != NULL){
60 return socket->recvData(data, flag);
61 }else{
63 }
64 }
PGenericSocket< _TBackend, _TMockBackend > * getSocket(const _TSocketKey &name)
Get a socket by name (or key)
PRecvStatus::PRecvStatus recvData(const _TSocketKey &name, U &data, PRecvFlag::PRecvFlag flag=PRecvFlag::BLOCK)
Receive data from the given socket.

References PRecvFlag::BLOCK, PRecvStatus::BROKEN_SOCKET, getSocket(), and PGenericSocket< _TBackend, _TMockBackend >::recvData().

+ Here is the call graph for this function:

◆ recvMsg()

template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
PRecvStatus::PRecvStatus PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::recvMsg ( const _TSocketKey & name,
typename _TBackend::Message & msg,
PRecvFlag::PRecvFlag flag = PRecvFlag::BLOCK )

Receive message from the given socket.

Parameters
name: name of the socket to be used
msg: message to be received
flag: flags to be used to send the message (BLOCK, NON_BLOCK, etc)
Returns
PRecvStatus::PRecvStatus

Definition at line 132 of file PGenericSocketManager_impl.h.

132 {
134 if(socket != NULL){
135 return socket->recvMsg(msg, flag);
136 }else{
138 }
139}
PRecvStatus::PRecvStatus recvMsg(const _TSocketKey &name, typename _TBackend::Message &msg, PRecvFlag::PRecvFlag flag=PRecvFlag::BLOCK)
Receive message from the given socket.

References PRecvStatus::BROKEN_SOCKET, getSocket(), and PGenericSocket< _TBackend, _TMockBackend >::recvMsg().

+ Here is the call graph for this function:

◆ removeSocket()

template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
void PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::removeSocket ( const _TSocketKey & name)

Remove the given socket.

Parameters
name: name (key) of the socket to be removed

Definition at line 91 of file PGenericSocketManager_impl.h.

91 {
93 if(it != p_mapSocket.end()){
94 delete it->second;
95 p_mapSocket.erase(it);
96 }
97}

References p_mapSocket.

◆ sendData()

template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
template<typename U>
PSendStatus::PSendStatus PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::sendData ( const _TSocketKey & name,
const U & data,
PSendFlag::PSendFlag flag = PSendFlag::BLOCK )
inline

Send data on the given socket.

Parameters
name: name of the socket to be used
data: data to be sent
flag: flag to be used to send the message (BLOCK, NON_BLOCK, etc)
Returns
true on success, false otherwise

Definition at line 39 of file PGenericSocketManager.h.

39 {
41 if(socket != NULL){
42 return socket->sendData(data, flag);
43 }else{
45 }
46 }
PSendStatus::PSendStatus sendData(const _TSocketKey &name, const U &data, PSendFlag::PSendFlag flag=PSendFlag::BLOCK)
Send data on the given socket.

References PSendFlag::BLOCK, PSendStatus::BROKEN_SOCKET, getSocket(), and PGenericSocket< _TBackend, _TMockBackend >::sendData().

+ Here is the call graph for this function:

◆ sendMsg()

template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
PSendStatus::PSendStatus PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::sendMsg ( const _TSocketKey & name,
typename _TBackend::Message & msg,
PSendFlag::PSendFlag flag = PSendFlag::BLOCK )

Send message on the given socket.

Parameters
name: name of the socket to be used
msg: message to be sent
flag: flags to be used to send the message (BLOCK, NON_BLOCK, etc)
Returns
PSendStatus::PSendStatus

Definition at line 116 of file PGenericSocketManager_impl.h.

116 {
118 if(socket != NULL){
119 return socket->sendMsg(msg, flag);
120 }else{
122 }
123}
PSendStatus::PSendStatus sendMsg(const _TSocketKey &name, typename _TBackend::Message &msg, PSendFlag::PSendFlag flag=PSendFlag::BLOCK)
Send message on the given socket.

References PSendStatus::BROKEN_SOCKET, getSocket(), and PGenericSocket< _TBackend, _TMockBackend >::sendMsg().

+ Here is the call graph for this function:

◆ setMode()

template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
void PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::setMode ( PSocketMode::PSocketMode mode)

Set if the current PGenericSocketManager is a mock.

Parameters
mode: Mode of the Socket (no mock, mock, mock_record)

Definition at line 30 of file PGenericSocketManager_impl.h.

30 {
31 p_mode = mode;
33 it->second->setMode(mode);
34 }
35}
void setMode(PSocketMode::PSocketMode mode)
Set if the current PGenericSocketManager is a mock.

References p_mapSocket, and p_mode.

Member Data Documentation

◆ p_backend

template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
_TBackend PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::p_backend
private

Instance of the backend.

Definition at line 81 of file PGenericSocketManager.h.

Referenced by addClientSocket(), and addServerSocket().

◆ p_mapSocket

template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
std::map<_TSocketKey, PGenericSocket<_TBackend, _TMockBackend> *> PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::p_mapSocket
private

Map of the zmq sockets to be used by the manager.

Definition at line 79 of file PGenericSocketManager.h.

Referenced by addClientSocket(), addServerSocket(), clear(), getSocket(), isConnected(), isSocketExist(), removeSocket(), and setMode().

◆ p_mockBackend

template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
_TMockBackend PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::p_mockBackend
private

Instance of the mock backend.

Definition at line 83 of file PGenericSocketManager.h.

Referenced by addClientSocket(), and addServerSocket().

◆ p_mode

template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
PSocketMode::PSocketMode PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::p_mode
private

Mode of the Socket (no mock, mock, mock_record)

Definition at line 76 of file PGenericSocketManager.h.

Referenced by addClientSocket(), addServerSocket(), getMode(), initialisationPGenericSocketManager(), and setMode().


The documentation for this class was generated from the following files: