PhoenixSocket  1.0.0
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 std::string &host, size_t port, const typename _TBackend::Param &param, const std::string &mockPrefix, const typename _TMockBackend::Param &mockParam)
 Create a client socket.
 
bool 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)
 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>
bool recvData (const _TSocketKey &name, U &data, PRecvFlag::PRecvFlag flag=PRecvFlag::BLOCK)
 Recieve data from the given socket.
 
bool recvMsg (const _TSocketKey &name, typename _TBackend::Message &msg, PRecvFlag::PRecvFlag flag=PRecvFlag::BLOCK)
 Recieve message from the given socket.
 
void removeSocket (const _TSocketKey &name)
 Remove the given socket.
 
template<typename U>
bool sendData (const _TSocketKey &name, const U &data, PSendFlag::PSendFlag flag=PSendFlag::BLOCK)
 Send data on the given socket.
 
bool 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

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)
 

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 std::string & host,
size_t port,
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
address: address of the server, the client has to connect to
port: port to be used for the connection
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 55 of file PGenericSocketManager_impl.h.

56{
58 bool b(socket != NULL);
59 if(b){
60 b &= socket->createClientSocket(host, port, param, mockPrefix, mockParam);
61 if(b){
63 }
64 }
65 return b;
66}
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)

References PGenericSocket< _TBackend, _TMockBackend >::createClientSocket(), p_mapSocket, 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 std::string & host,
size_t port,
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
address: address of the server, the client has to connect to
port: port to be used for the connection
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 78 of file PGenericSocketManager_impl.h.

79{
81 bool b(socket != NULL);
82 if(b){
83 b &= socket->createServerSocket(host, port, param, mockPrefix, mockParam);
84 if(b){
86 }
87 }
88 return b;
89}

References PGenericSocket< _TBackend, _TMockBackend >::createServerSocket(), p_mapSocket, 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 105 of file PGenericSocketManager_impl.h.

105 {
107 it->second->close();
108 delete it->second;
109 }
110 p_mapSocket.clear();
111}

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 150 of file PGenericSocketManager_impl.h.

151{
153 if(it != p_mapSocket.end()){
154 return it->second;
155 }else{
156 return NULL;
157 }
158}

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 188 of file PGenericSocketManager_impl.h.

188 {
189 p_mode = mode;
190}

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 175 of file PGenericSocketManager_impl.h.

175 {
177 if(it != p_mapSocket.end()){
178 return it->second->isConnected();
179 }
180 return false;
181}
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 165 of file PGenericSocketManager_impl.h.

References p_mapSocket.

◆ recvData()

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

Recieve data from the given socket.

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

Definition at line 57 of file PGenericSocketManager.h.

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

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

+ Here is the call graph for this function:

◆ recvMsg()

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

Recieve message from the given socket.

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

Definition at line 136 of file PGenericSocketManager_impl.h.

136 {
138 if(socket != NULL){
139 return socket->recvMsg(msg, flag);
140 }else{
141 return false;
142 }
143}
bool recvMsg(const _TSocketKey &name, typename _TBackend::Message &msg, PRecvFlag::PRecvFlag flag=PRecvFlag::BLOCK)
Recieve message from the given socket.

References 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 95 of file PGenericSocketManager_impl.h.

95 {
97 if(it != p_mapSocket.end()){
98 delete it->second;
99 p_mapSocket.erase(it);
100 }
101}

References p_mapSocket.

◆ sendData()

template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
template<typename U>
bool 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{
44 return false;
45 }
46 }
bool sendData(const _TSocketKey &name, const U &data, PSendFlag::PSendFlag flag=PSendFlag::BLOCK)
Send data on the given socket.

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

+ Here is the call graph for this function:

◆ sendMsg()

template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
bool 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
true on success, false otherwise

Definition at line 120 of file PGenericSocketManager_impl.h.

120 {
122 if(socket != NULL){
123 return socket->sendMsg(msg, flag);
124 }else{
125 return false;
126 }
127}
bool sendMsg(const _TSocketKey &name, typename _TBackend::Message &msg, PSendFlag::PSendFlag flag=PSendFlag::BLOCK)
Send message on the given socket.

References 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_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_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: