PhoenixSocket  1.0.0
Library which integrates socket unix use in Phoenix
Loading...
Searching...
No Matches
PGenericSocketManager.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__
8#define __PGENERIC_SOCKET_MANAGER_H__
9
10#include <map>
11#include "PGenericSocket.h"
12#include "PEmptyBackend.h"
13#include "PMockBackend.h"
14
16template<typename _TSocketKey, typename _TBackend, typename _TMockBackend>
18 public:
19 typedef _TBackend Backend;
20 typedef _TMockBackend Mock;
22 virtual ~PGenericSocketManager();
23
26 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);
27 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);
28
29 void removeSocket(const _TSocketKey & name);
30 void clear();
31
33
38 template<typename U>
39 bool sendData(const _TSocketKey & name, const U & data, PSendFlag::PSendFlag flag = PSendFlag::BLOCK){
41 if(socket != NULL){
42 return socket->sendData(data, flag);
43 }else{
44 return false;
45 }
46 }
47
48 bool sendMsg(const _TSocketKey & name, typename _TBackend::Message & msg, PSendFlag::PSendFlag flag = PSendFlag::BLOCK);
49
51
56 template<typename U>
57 bool recvData(const _TSocketKey & name, U & data, PRecvFlag::PRecvFlag flag = PRecvFlag::BLOCK){
59 if(socket != NULL){
60 return socket->recvData(data, flag);
61 }else{
62 return false;
63 }
64 }
65
66 bool recvMsg(const _TSocketKey & name, typename _TBackend::Message & msg, PRecvFlag::PRecvFlag flag = PRecvFlag::BLOCK);
67
68 PGenericSocket<_TBackend, _TMockBackend>* getSocket(const _TSocketKey & name);
69 bool isSocketExist(const _TSocketKey & name) const;
70 bool isConnected(const _TSocketKey & name) const;
71
72 private:
74
77
79 std::map<_TSocketKey, PGenericSocket<_TBackend, _TMockBackend> *> p_mapSocket;
80
81};
82
84
85
86#endif
87
bool recvData(const _TSocketKey &name, U &data, PRecvFlag::PRecvFlag flag=PRecvFlag::BLOCK)
Recieve data from the given socket.
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.
bool sendMsg(const _TSocketKey &name, typename _TBackend::Message &msg, PSendFlag::PSendFlag flag=PSendFlag::BLOCK)
Send message on the given socket.
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 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.
bool sendData(const _TSocketKey &name, const U &data, PSendFlag::PSendFlag flag=PSendFlag::BLOCK)
Send data on the given 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.
virtual ~PGenericSocketManager()
Destructor of PGenericSocketManager.
PSocketMode::PSocketMode getMode() const
Get if the current PGenericSocketManager is a mock.
bool recvMsg(const _TSocketKey &name, typename _TBackend::Message &msg, PRecvFlag::PRecvFlag flag=PRecvFlag::BLOCK)
Recieve message from the given socket.
void clear()
Clear the map of socket.
void initialisationPGenericSocketManager(PSocketMode::PSocketMode mode)
Initialisation function of the class PGenericSocketManager.
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.
Abstract socket which has a mock mode to avoid heavy socket backend for unit tests.
bool recvData(U &data, PRecvFlag::PRecvFlag flag)
Recieve message from the given socket.
bool sendData(const U &data, PSendFlag::PSendFlag flag)
Send message on the given socket.
PRecvFlag
describe the recieving flag of the Socket
Definition PSocketFlag.h:20
PSendFlag
describe the sending flag of the Socket
Definition PSocketFlag.h:12
PSocketMode
describe the mode of the Socket
Definition PSocketMode.h:12