Line |
Branch |
Exec |
Source |
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 |
|
|
|
13 |
|
|
///@brief Set of parameters to be passed to create a socket with mock backend |
14 |
|
|
struct PMockParam{ |
15 |
|
|
///Host address |
16 |
|
|
std::string address; |
17 |
|
|
///Connection port |
18 |
|
|
size_t port; |
19 |
|
|
///True to record the activity of the backend durring real use to make reusable mock |
20 |
|
|
bool isMockRecord; |
21 |
|
|
///Prefix where to find/save mock files |
22 |
|
|
std::string mockPrefix; |
23 |
|
|
}; |
24 |
|
|
|
25 |
|
|
///@brief Data to be used to handle the mock socket |
26 |
|
|
struct PMockSocket{ |
27 |
|
|
///Parameters of the mock |
28 |
|
|
PMockParam param; |
29 |
|
|
///Name of the file to read messages |
30 |
|
|
std::string fileNameMessage; |
31 |
|
|
///Vector of messages |
32 |
|
|
PVecMockMessage vecMessage; |
33 |
|
|
///Index of the current message |
34 |
|
|
size_t eventIndex; |
35 |
|
|
}; |
36 |
|
|
|
37 |
|
|
///@brief Backend to use Mock library with PAbtractSocket |
38 |
|
|
class PMockBackend{ |
39 |
|
|
public: |
40 |
|
|
///Define the socket of the backend used by the PAbstractSocketManager |
41 |
|
|
typedef PMockSocket Socket; |
42 |
|
|
///Define the type of message used by the PAbstractSocketManager |
43 |
|
|
typedef DataStreamMsg Message; |
44 |
|
|
///Define the type of extra parameters which can be used to create a Socket used by the PAbstractSocketManager |
45 |
|
|
typedef PMockParam Param; |
46 |
|
|
|
47 |
|
|
PMockBackend(); |
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 |
|
|
|
73 |
|
|
bool phoenix_loadMockSocket(const std::string & prefix, const std::string & host, size_t port, PVecMockMessage & vecMessage); |
74 |
|
|
bool phoenix_saveMockSocket(const std::string & prefix, const std::string & host, size_t port, const PVecMockMessage & vecMessage); |
75 |
|
|
|
76 |
|
|
#endif |
77 |
|
|
|
78 |
|
|
|