Line |
Branch |
Exec |
Source |
1 |
|
|
/*************************************** |
2 |
|
|
Auteur : Pierre Aubert |
3 |
|
|
Mail : pierre.aubert@lapp.in2p3.fr |
4 |
|
|
Licence : CeCILL-C |
5 |
|
|
****************************************/ |
6 |
|
|
|
7 |
|
|
#include "PEmptyBackend.h" |
8 |
|
|
|
9 |
|
|
|
10 |
|
|
///Default constructor of PEmptyBackend |
11 |
|
✗ |
PEmptyBackend::PEmptyBackend(){ |
12 |
|
|
|
13 |
|
✗ |
} |
14 |
|
|
|
15 |
|
|
///Create param for a client socket |
16 |
|
|
/** @return corresponding PEmptyParam |
17 |
|
|
*/ |
18 |
|
4 |
PEmptyBackend::Param PEmptyBackend::client(){ |
19 |
|
|
PEmptyBackend::Param param; |
20 |
|
4 |
return param; |
21 |
|
|
} |
22 |
|
|
|
23 |
|
|
///Create param for a server socket |
24 |
|
|
/** @return corresponding PEmptyParam |
25 |
|
|
*/ |
26 |
|
2 |
PEmptyBackend::Param PEmptyBackend::server(){ |
27 |
|
2 |
return PEmptyBackend::client(); |
28 |
|
|
} |
29 |
|
|
|
30 |
|
|
///Create a client socket |
31 |
|
|
/** @param[out] socket : socket to be created |
32 |
|
|
* @param address : address of the server, the client has to connect to |
33 |
|
|
* @param port : port to be used for the connection |
34 |
|
|
* @param param : extra customisable parameters for the creation of the socket (depends on the backend) |
35 |
|
|
* @return true if the socket has been created, false otherwise |
36 |
|
|
*/ |
37 |
|
2 |
bool PEmptyBackend::createClientSocket(PEmptyBackend::Socket & socket, const std::string & address, size_t port, const PEmptyParam & param){ |
38 |
|
2 |
return true; |
39 |
|
|
} |
40 |
|
|
|
41 |
|
|
///Create a Server socket |
42 |
|
|
/** @param[out] socket : socket to be created |
43 |
|
|
* @param address : address of the server, the client has to connect to |
44 |
|
|
* @param port : port to be used for the connection |
45 |
|
|
* @param param : extra customisable parameters for the creation of the socket (depends on the backend) |
46 |
|
|
* @return true if the socket has been created, false otherwise |
47 |
|
|
*/ |
48 |
|
2 |
bool PEmptyBackend::createServerSocket(PEmptyBackend::Socket & socket, const std::string & address, size_t port, const PEmptyParam & param){ |
49 |
|
2 |
return true; |
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
///Send message on the given socket |
53 |
|
|
/** @param socket : socket to be used |
54 |
|
|
* @param msg : message to be sent |
55 |
|
|
* @param flag : flags to be used to send the message (BLOCK, NON_BLOCK, etc) |
56 |
|
|
* @return true on success, false otherwise |
57 |
|
|
*/ |
58 |
|
20 |
bool PEmptyBackend::send(PEmptyBackend::Socket & socket, const PEmptyBackend::Message & msg, PSendFlag::PSendFlag flag){ |
59 |
|
20 |
return true; |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
///Recieve message from the given socket |
63 |
|
|
/** @param socket : socket to be used |
64 |
|
|
* @param msg : message to be recieved |
65 |
|
|
* @param flag : flags to be used to send the message (BLOCK, NON_BLOCK, etc) |
66 |
|
|
* @return true on success, false otherwise |
67 |
|
|
*/ |
68 |
|
✗ |
bool PEmptyBackend::recv(PEmptyBackend::Socket & socket, PEmptyBackend::Message & msg, PRecvFlag::PRecvFlag flag){ |
69 |
|
✗ |
return false; |
70 |
|
|
} |
71 |
|
|
|
72 |
|
|
///Resize a message |
73 |
|
|
/** @param[out] msg : message to be resized |
74 |
|
|
* @param sizeMsg : new size of the message |
75 |
|
|
*/ |
76 |
|
20 |
void PEmptyBackend::msgResize(PEmptyBackend::Message& msg, size_t sizeMsg){ |
77 |
|
20 |
msg.resize(sizeMsg); |
78 |
|
20 |
} |
79 |
|
|
|
80 |
|
|
///Get the size of a message |
81 |
|
|
/** @param msg : message to be used |
82 |
|
|
* @return size of the message in bytes |
83 |
|
|
*/ |
84 |
|
20 |
size_t PEmptyBackend::msgSize(const PEmptyBackend::Message& msg){ |
85 |
|
20 |
return msg.size(); |
86 |
|
|
} |
87 |
|
|
|
88 |
|
|
///Get the data of a message |
89 |
|
|
/** @param msg : message to be used |
90 |
|
|
* @return data of the message in bytes |
91 |
|
|
*/ |
92 |
|
10 |
const DataStreamIter PEmptyBackend::msgData(const PEmptyBackend::Message& msg){ |
93 |
|
10 |
return (const DataStreamIter)msg.data(); |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
///Get the data of a message |
97 |
|
|
/** @param msg : message to be used |
98 |
|
|
* @return data of the message in bytes |
99 |
|
|
*/ |
100 |
|
30 |
DataStreamIter PEmptyBackend::msgData(PEmptyBackend::Message& msg){ |
101 |
|
30 |
return msg.data(); |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
|
105 |
|
|
///Close the given socket |
106 |
|
|
/** @param[out] socket : socket to be closed |
107 |
|
|
*/ |
108 |
|
8 |
void PEmptyBackend::close(PEmptyBackend::Socket & socket){ |
109 |
|
|
|
110 |
|
8 |
} |
111 |
|
|
|
112 |
|
|
///Close the given socket |
113 |
|
|
/** @param socket : socket to be checked |
114 |
|
|
* @return true if the socket is connected, false otherwise |
115 |
|
|
*/ |
116 |
|
2 |
bool PEmptyBackend::isConnected(const PEmptyBackend::Socket & socket){ |
117 |
|
2 |
return true; |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
///Copy current backend message data into mock message |
121 |
|
|
/** @param[out] mockMsg : mock message |
122 |
|
|
* @param msg : message of the current backend to be converted |
123 |
|
|
*/ |
124 |
|
10 |
void PEmptyBackend::msgToMock(DataStreamMsg & mockMsg, const PEmptyBackend::Message & msg){ |
125 |
|
10 |
size_t dataSize(PEmptyBackend::msgSize(msg)); |
126 |
|
10 |
mockMsg.resize(dataSize); |
127 |
|
10 |
memcpy(mockMsg.data(), PEmptyBackend::msgData(msg), dataSize); |
128 |
|
10 |
} |
129 |
|
|
|
130 |
|
|
///Copy mock message data into current backend message |
131 |
|
|
/** @param[out] msg : message of the current backend to be converted |
132 |
|
|
* @param mockMsg : mock message |
133 |
|
|
*/ |
134 |
|
10 |
void PEmptyBackend::mockToMsg(PEmptyBackend::Message & msg, DataStreamMsg & mockMsg){ |
135 |
|
10 |
size_t dataSize(mockMsg.size()); |
136 |
|
10 |
PEmptyBackend::msgResize(msg, dataSize); |
137 |
|
10 |
memcpy(PEmptyBackend::msgData(msg), mockMsg.data(), dataSize); |
138 |
|
10 |
} |
139 |
|
|
|
140 |
|
|
|
141 |
|
|
|