PhoenixSocket  1.0.0
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_mock_socket.h"
12
16 std::string address;
18 size_t port;
22 std::string mockPrefix;
23};
24
36
39 public:
43 typedef DataStreamMsg Message;
46
48
49 static Param client();
50 static Param server();
51
52 static bool createClientSocket(Socket & socket, const std::string & address, size_t port, const PMockParam & param);
53 static bool createServerSocket(Socket & socket, const std::string & address, size_t port, const PMockParam & param);
54
55 static void setMockPrefix(Socket & socket, const std::string & mockPrefix);
56 static void setIsMockRecord(Socket & socket, bool isMockRecord);
57
58 static bool send(Socket & socket, const Message& msg, PSendFlag::PSendFlag flag);
59 static bool recv(Socket & socket, Message& msg, PRecvFlag::PRecvFlag flag);
60
61 static void msgResize(Message& msg, size_t sizeMsg);
62 static size_t msgSize(const Message& msg);
63 static const DataStreamIter msgData(const Message& msg);
64 static DataStreamIter msgData(Message& msg);
65
66 static void close(Socket & socket);
67 static bool isConnected(const Socket & socket);
68
69 static void msgToMock(DataStreamMsg & mockMsg, const Message & msg);
70 static void mockToMsg(Message & msg, DataStreamMsg & mockMsg);
71};
72
73bool phoenix_loadMockSocket(const std::string & prefix, const std::string & host, size_t port, PVecMockMessage & vecMessage);
74bool phoenix_saveMockSocket(const std::string & prefix, const std::string & host, size_t port, const PVecMockMessage & vecMessage);
75
76#endif
77
bool phoenix_loadMockSocket(const std::string &prefix, const std::string &host, size_t port, PVecMockMessage &vecMessage)
Load a mock of socket.
bool phoenix_saveMockSocket(const std::string &prefix, const std::string &host, size_t port, const PVecMockMessage &vecMessage)
Save a mock of socket.
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.
static bool send(Socket &socket, const Message &msg, PSendFlag::PSendFlag flag)
Send message on the given socket.
PMockBackend()
Default constructor of PMockBackend.
static void msgResize(Message &msg, size_t sizeMsg)
Resize a message.
static bool isConnected(const Socket &socket)
Say if the given socket is connected.
static Param server()
Create param for a server socket.
static void setIsMockRecord(Socket &socket, bool isMockRecord)
Set the mock prefix (where to find/save it)
PMockParam Param
Define the type of extra parameters which can be used to create a Socket used by the PAbstractSocketM...
static void setMockPrefix(Socket &socket, const std::string &mockPrefix)
Set the mock prefix (where to find/save it)
static void mockToMsg(Message &msg, DataStreamMsg &mockMsg)
Copy mock message data into current backend message.
static bool recv(Socket &socket, Message &msg, PRecvFlag::PRecvFlag flag)
Recieve message from the given socket.
PMockSocket Socket
Define the socket of the backend used by the PAbstractSocketManager.
static void close(Socket &socket)
Close the given socket.
static bool createClientSocket(Socket &socket, const std::string &address, size_t port, const PMockParam &param)
Create a client socket.
static Param client()
Create param for a client socket.
static size_t msgSize(const Message &msg)
Get the size of a message.
static bool createServerSocket(Socket &socket, const std::string &address, size_t port, const PMockParam &param)
Create a client socket.
DataStreamMsg Message
Define the type of message used by the PAbstractSocketManager.
PRecvFlag
describe the recieving flag of the Socket
Definition PSocketFlag.h:20
PSendFlag
describe the sending flag of the Socket
Definition PSocketFlag.h:12
std::vector< DataStreamMsg > PVecMockMessage
Vector of messages.
Set of parameters to be passed to create a socket with mock backend.
size_t port
Connection port.
std::string mockPrefix
Prefix where to find/save mock files.
std::string address
Host address.
bool isMockRecord
True to record the activity of the backend durring real use to make reusable mock.
Data to be used to handle the mock socket.
PMockParam param
Parameters of the mock.
std::string fileNameMessage
Name of the file to read messages.
PVecMockMessage vecMessage
Vector of messages.
size_t eventIndex
Index of the current message.