PhoenixSocket  4.0.1
Library which integrates socket unix use in Phoenix
Loading...
Searching...
No Matches
PMockBackend.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 __PMOCKBACKEND_H__
8#define __PMOCKBACKEND_H__
9
10#include "PSocketFlag.h"
11#include "phoenix_generic_mock.h"
12
14struct PMockParam{};
15
18 public:
20 typedef DataStreamMsg Message;
23
25 virtual ~PMockSocket();
26
27 bool createClientSocket(const PSocketParam & socketParam, const Param & extraParam);
28 bool createServerSocket(const PSocketParam & socketParam, const Param & extraParam);
29
30 void setMockPrefix(const std::string & mockPrefix);
31 void setIsMockRecord(bool isMockRecord);
32
33 template<typename T>
36
37 template<typename T>
40
41 bool isConnected() const;
42 void close();
43 private:
45 PGenericVecMock<DataStreamMsg> p_mock;
50};
51
54 public:
58 typedef DataStreamMsg Message;
61
63
64 static Param client();
65 static Param server();
66
67 bool createClientSocket(Socket & socket, const PSocketParam & socketParam, const PMockParam & param);
68 bool createServerSocket(Socket & socket, const PSocketParam & socketParam, const PMockParam & param);
69
70 static void msgResize(Message& msg, size_t sizeMsg);
71 static size_t msgSize(const Message& msg);
72 static const DataStreamIter msgData(const Message& msg);
73 static DataStreamIter msgData(Message& msg);
74
75 static void msgToMock(DataStreamMsg & mockMsg, const Message & msg);
76 static void mockToMsg(Message & msg, DataStreamMsg & mockMsg);
77};
78
79bool phoenix_createMockBackend(PMockSocket & mock, const PSocketParam & socketParam, const std::string & prefix = "", const PMockParam & extraParam = PMockParam());
80
81#include "PMockBackend_impl.h"
82
83#endif
84
bool phoenix_createMockBackend(PMockSocket &mock, const PSocketParam &socketParam, const std::string &prefix="", const PMockParam &extraParam=PMockParam())
Create a mock backend.
static void msgToMock(DataStreamMsg &mockMsg, const Message &msg)
Copy current backend message data into mock message.
static const DataStreamIter msgData(const Message &msg)
Get the data of a message.
PMockBackend()
Default constructor of PMockBackend.
static void msgResize(Message &msg, size_t sizeMsg)
Resize a message.
static Param server()
Create param for a server socket.
PMockParam Param
Define the type of extra parameters which can be used to create a Socket used by the PAbstractSocketM...
bool createClientSocket(Socket &socket, const PSocketParam &socketParam, const PMockParam &param)
Create a client socket.
static void mockToMsg(Message &msg, DataStreamMsg &mockMsg)
Copy mock message data into current backend message.
PMockSocket Socket
Define the socket of the backend used by the PAbstractSocketManager.
static Param client()
Create param for a client socket.
static size_t msgSize(const Message &msg)
Get the size of a message.
bool createServerSocket(Socket &socket, const PSocketParam &socketParam, const PMockParam &param)
Create a client socket.
DataStreamMsg Message
Define the type of message used by the PAbstractSocketManager.
Example of a mock socket with vector of messages.
PSendStatus::PSendStatus sendData(const T &data, PSendFlag::PSendFlag flag=PSendFlag::BLOCK)
Send data with the socket.
PGenericVecMock< DataStreamMsg > p_mock
Mock handler.
PMockSocket()
Default constructor of hte PMockSocket.
Param p_extraParam
Extra parameters of the socket.
PMockParam Param
Define the type of extra parameters which can be used to create a Socket used by the PAbstractSocketM...
PSocketParam p_socketParam
Parameters of the socket.
void close()
Close the PMockSocket.
PSendStatus::PSendStatus sendMsg(const Message &msg, PSendFlag::PSendFlag flag=PSendFlag::BLOCK)
Specialisation to send a Message with the socket.
DataStreamMsg Message
Define the type of message used by the PAbstractSocketManager.
bool createServerSocket(const PSocketParam &socketParam, const Param &extraParam)
Initialise a server socket.
bool createClientSocket(const PSocketParam &socketParam, const Param &extraParam)
Initialise a client socket.
PRecvStatus::PRecvStatus recvMsg(Message &msg, PRecvFlag::PRecvFlag flag=PRecvFlag::BLOCK)
Recieved data with the socket.
bool isConnected() const
Say if the PMockSocket is connected.
PRecvStatus::PRecvStatus recvData(T &data, PRecvFlag::PRecvFlag flag=PRecvFlag::BLOCK)
Recieved data with the socket.
void setIsMockRecord(bool isMockRecord)
Set the mock prefix (where to find/save it)
virtual ~PMockSocket()
Default destructor of hte PMockSocket.
void setMockPrefix(const std::string &mockPrefix)
Set the mock prefix (where to find/save it)
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
Set of parameters to be passed to create a socket with mock backend.
Parameters to create a socket.
Definition PSocketFlag.h:68