PhoenixZMQ  2.0.0
Library which integrates zeromq use in Phoenix
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 typename _TBackend::Param &param, const typename _TMockBackend::Param &mockParam)
 Create a client socket. More...
 
bool addServerSocket (const _TSocketKey &name, const typename _TBackend::Param &param, const typename _TMockBackend::Param &mockParam)
 Create a server socket. More...
 
void clear ()
 Clear the map of socket. More...
 
PSocketMode::PSocketMode getMode () const
 Get if the current PGenericSocketManager is a mock. More...
 
PGenericSocket< _TBackend, _TMockBackend > * getSocket (const _TSocketKey &name)
 Get a socket by name (or key) More...
 
bool isConnected (const _TSocketKey &name) const
 Say if the given socket is connected. More...
 
bool isSocketExist (const _TSocketKey &name) const
 Say if the socket exist with the given name. More...
 
 PGenericSocketManager (PSocketMode::PSocketMode mode=PSocketMode::NO_MOCK)
 Default constructor of PGenericSocketManager. More...
 
template<typename U >
bool recvData (const _TSocketKey &name, U &data, PRecvFlag::PRecvFlag flag=PRecvFlag::BLOCK)
 Recieve data from the given socket. More...
 
bool recvMsg (const _TSocketKey &name, typename _TBackend::Message &msg, PRecvFlag::PRecvFlag flag=PRecvFlag::BLOCK)
 Recieve message from the given socket. More...
 
void removeSocket (const _TSocketKey &name)
 Remove the given socket. More...
 
template<typename U >
bool sendData (const _TSocketKey &name, const U &data, PSendFlag::PSendFlag flag=PSendFlag::BLOCK)
 Send data on the given socket. More...
 
bool sendMsg (const _TSocketKey &name, typename _TBackend::Message &msg, PSendFlag::PSendFlag flag=PSendFlag::BLOCK)
 Send message on the given socket. More...
 
void setMode (PSocketMode::PSocketMode mode)
 Set if the current PGenericSocketManager is a mock. More...
 
virtual ~PGenericSocketManager ()
 Destructor of PGenericSocketManager. More...
 

Private Member Functions

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

Private Attributes

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

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 }
void initialisationPGenericSocketManager(PSocketMode::PSocketMode mode)
Initialisation function of the class PGenericSocketManager.

◆ ~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.

Member Function Documentation

◆ addClientSocket()

template<typename _TSocketKey , typename _TBackend , typename _TMockBackend >
bool PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::addClientSocket ( const _TSocketKey &  name,
const typename _TBackend::Param &  param,
const typename _TMockBackend::Param &  mockParam 
)

Create a client socket.

Parameters
name: name (key) to get the socket
param: extra customisable parameters for the creation of the socket (depends on the backend)
mockParam: parameters to initialise the mock
Returns
true if the socket has been created, false otherwise

Definition at line 49 of file PGenericSocketManager_impl.h.

50 {
52  bool b(socket != NULL);
53  if(b){
54  b &= socket->createClientSocket(param, mockParam);
55  if(b){
56  p_mapSocket[name] = socket;
57  }
58  }
59  return b;
60 }
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)
Abstract socket which has a mock mode to avoid heavy socket backend for unit tests.
bool createClientSocket(const typename _TBackend::Param &param, const typename _TMockBackend::Param &mockParam)
Create a client socket.

References PGenericSocket< _TBackend, _TMockBackend >::createClientSocket().

Referenced by threadRecievedData(), and threadRecievedMessage().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addServerSocket()

template<typename _TSocketKey , typename _TBackend , typename _TMockBackend >
bool PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::addServerSocket ( const _TSocketKey &  name,
const typename _TBackend::Param &  param,
const typename _TMockBackend::Param &  mockParam 
)

Create a server socket.

Parameters
name: name (key) to get the socket
param: extra customisable parameters for the creation of the socket (depends on the backend)
mockParam: parameters to initialise the mock
Returns
true if the socket has been created, false otherwise

Definition at line 69 of file PGenericSocketManager_impl.h.

70 {
72  bool b(socket != NULL);
73  if(b){
74  b &= socket->createServerSocket(param, mockParam);
75  if(b){
76  p_mapSocket[name] = socket;
77  }
78  }
79  return b;
80 }
bool createServerSocket(const typename _TBackend::Param &param, const typename _TMockBackend::Param &mockParam)
Create a server socket.

References PGenericSocket< _TBackend, _TMockBackend >::createServerSocket().

Referenced by threadSendData(), and threadSendMessage().

+ Here is the call graph for this function:
+ Here is the caller 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 96 of file PGenericSocketManager_impl.h.

96  {
97  for(typename std::map<_TSocketKey, PGenericSocket<_TBackend, _TMockBackend>* >::iterator it(p_mapSocket.begin()); it != p_mapSocket.end(); ++it){
98  delete it->second;
99  }
100  p_mapSocket.clear();
101 }

◆ getMode()

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

Get if the current PGenericSocketManager is a mock.

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

Definition at line 38 of file PGenericSocketManager_impl.h.

38  {
39  return p_mode;
40 }

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

141 {
142  typename std::map<_TSocketKey, PGenericSocket<_TBackend, _TMockBackend>* >::iterator it(p_mapSocket.find(name));
143  if(it != p_mapSocket.end()){
144  return it->second;
145  }else{
146  return NULL;
147  }
148 }

Referenced by PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::recvData(), and PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::sendData().

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

178  {
179  p_mode = mode;
180 }

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

165  {
166  typename std::map<_TSocketKey, PGenericSocket<_TBackend, _TMockBackend>* >::const_iterator it(p_mapSocket.find(name));
167  if(it != p_mapSocket.end()){
168  return it->second->isConnected();
169  }
170  return false;
171 }

Referenced by threadSendData(), and threadSendMessage().

+ Here is the caller graph for this function:

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

155  {
156  typename std::map<_TSocketKey, PGenericSocket<_TBackend, _TMockBackend>* >::const_iterator it(p_mapSocket.find(name));
157  return it != p_mapSocket.end();
158 }

◆ 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  }
PGenericSocket< _TBackend, _TMockBackend > * getSocket(const _TSocketKey &name)
Get a socket by name (or key)
bool recvData(U &data, PRecvFlag::PRecvFlag flag)
Recieve message from the given socket.

References PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::getSocket(), and PGenericSocket< _TBackend, _TMockBackend >::recvData().

Referenced by threadRecievedData().

+ Here is the call graph for this function:
+ Here is the caller 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 126 of file PGenericSocketManager_impl.h.

126  {
128  if(socket != NULL){
129  return socket->recvMsg(msg, flag);
130  }else{
131  return false;
132  }
133 }
bool recvMsg(typename _TBackend::Message &msg, PRecvFlag::PRecvFlag flag)
Recieve message from the given socket.

References PGenericSocket< _TBackend, _TMockBackend >::recvMsg().

Referenced by threadRecievedMessage().

+ Here is the call graph for this function:
+ Here is the caller 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 86 of file PGenericSocketManager_impl.h.

86  {
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 }

◆ 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 U &data, PSendFlag::PSendFlag flag)
Send message on the given socket.

References PGenericSocketManager< _TSocketKey, _TBackend, _TMockBackend >::getSocket(), and PGenericSocket< _TBackend, _TMockBackend >::sendData().

Referenced by threadSendData().

+ Here is the call graph for this function:
+ Here is the caller 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 110 of file PGenericSocketManager_impl.h.

110  {
112  if(socket != NULL){
113  return socket->sendMsg(msg, flag);
114  }else{
115  return false;
116  }
117 }
bool sendMsg(typename _TBackend::Message &msg, PSendFlag::PSendFlag flag)
Send message on the given socket.

References PGenericSocket< _TBackend, _TMockBackend >::sendMsg().

Referenced by threadSendMessage().

+ Here is the call graph for this function:
+ Here is the caller 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;
32 }

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.

◆ 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.


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