PhoenixZMQ  2.0.0
Library which integrates zeromq use in Phoenix
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 
14 struct PMockParam{
16  std::string address;
18  size_t port;
22  std::string mockDirectory;
23 };
24 
26 struct PMockSocket{
30  std::string fileNameMessage;
34  size_t eventIndex;
35 };
36 
39  public:
45  typedef PMockParam Param;
46 
47  PMockBackend();
48 
49  static Param client(const std::string & address, size_t port, bool isMockRecord, const std::string & mockDirectory);
50  static Param server(const std::string & address, size_t port, bool isMockRecord, const std::string & mockDirectory);
51 
52  static bool createClientSocket(Socket & socket, const PMockParam & param);
53  static bool createServerSocket(Socket & socket, const PMockParam & param);
54 
55  static bool send(Socket & socket, const Message& msg, PSendFlag::PSendFlag flag);
56  static bool recv(Socket & socket, Message& msg, PRecvFlag::PRecvFlag flag);
57 
58  static void msgResize(Message& msg, size_t sizeMsg);
59  static size_t msgSize(const Message& msg);
60  static const DataStreamIter msgData(const Message& msg);
61  static DataStreamIter msgData(Message& msg);
62 
63  static void close(Socket & socket);
64  static bool isConnected(const Socket & socket);
65 
66  static void msgToMock(DataStreamMsg & mockMsg, const Message & msg);
67  static void mockToMsg(Message & msg, DataStreamMsg & mockMsg);
68 };
69 
70 
71 #endif
72 
Backend to use Mock library with PAbtractSocket.
Definition: PMockBackend.h:38
static void msgToMock(DataStreamMsg &mockMsg, const Message &msg)
Copy current backend message data into mock message.
static bool createClientSocket(Socket &socket, const PMockParam &param)
Create a client socket.
static const DataStreamIter msgData(const Message &msg)
Get the data of a message.
static Param client(const std::string &address, size_t port, bool isMockRecord, const std::string &mockDirectory)
Create param for a client socket.
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 bool createServerSocket(Socket &socket, const PMockParam &param)
Create a client socket.
PMockParam Param
Define the type of extra parameters which can be used to create a Socket used by the PAbstractSocketM...
Definition: PMockBackend.h:45
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.
Definition: PMockBackend.h:41
static void close(Socket &socket)
Close the given socket.
static Param server(const std::string &address, size_t port, bool isMockRecord, const std::string &mockDirectory)
Create param for a server socket.
static size_t msgSize(const Message &msg)
Get the size of a message.
DataStreamMsg Message
Define the type of message used by the PAbstractSocketManager.
Definition: PMockBackend.h:43
std::vector< DataStreamType > DataStreamMsg
DataStreamType * DataStreamIter
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.
Definition: PMockBackend.h:14
size_t port
Connection port.
Definition: PMockBackend.h:18
std::string address
Host address.
Definition: PMockBackend.h:16
std::string mockDirectory
Directory where to find/save mock files.
Definition: PMockBackend.h:22
bool isMockRecord
True to record the activity of the backend durring real use to make reusable mock.
Definition: PMockBackend.h:20
Data to be used to handle the mock socket.
Definition: PMockBackend.h:26
PMockParam param
Parameters of the mock.
Definition: PMockBackend.h:28
std::string fileNameMessage
Name of the file to read messages.
Definition: PMockBackend.h:30
PVecMockMessage vecMessage
Vector of messages.
Definition: PMockBackend.h:32
size_t eventIndex
Index of the current message.
Definition: PMockBackend.h:34