xrootd
Main Page
Namespaces
Classes
Files
File List
File Members
src
XrdCl
XrdClMessageUtils.hh
Go to the documentation of this file.
1
//------------------------------------------------------------------------------
2
// Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
3
// Author: Lukasz Janyst <ljanyst@cern.ch>
4
//------------------------------------------------------------------------------
5
// XRootD is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU Lesser General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
9
//
10
// XRootD is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU General Public License for more details.
14
//
15
// You should have received a copy of the GNU Lesser General Public License
16
// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
17
//------------------------------------------------------------------------------
18
19
#ifndef __XRD_CL_MESSAGE_UTILS_HH__
20
#define __XRD_CL_MESSAGE_UTILS_HH__
21
22
#include "
XrdCl/XrdClXRootDResponses.hh
"
23
#include "
XrdCl/XrdClURL.hh
"
24
#include "
XrdCl/XrdClMessage.hh
"
25
#include "
XrdSys/XrdSysPthread.hh
"
26
#include <memory>
27
28
namespace
XrdCl
29
{
30
//----------------------------------------------------------------------------
32
//----------------------------------------------------------------------------
33
class
SyncResponseHandler
:
public
ResponseHandler
34
{
35
public
:
36
//------------------------------------------------------------------------
38
//------------------------------------------------------------------------
39
SyncResponseHandler
():
40
pStatus
(0),
41
pResponse
(0),
42
pSem
( new
XrdSysSemaphore
(0) ) {}
43
44
//------------------------------------------------------------------------
46
//------------------------------------------------------------------------
47
virtual
~SyncResponseHandler
()
48
{
49
delete
pSem
;
50
}
51
52
53
//------------------------------------------------------------------------
55
//------------------------------------------------------------------------
56
virtual
void
HandleResponse
(
XRootDStatus
*status,
57
AnyObject
*response )
58
{
59
pStatus
= status;
60
pResponse
= response;
61
pSem
->
Post
();
62
}
63
64
//------------------------------------------------------------------------
66
//------------------------------------------------------------------------
67
XRootDStatus
*
GetStatus
()
68
{
69
return
pStatus
;
70
}
71
72
//------------------------------------------------------------------------
74
//------------------------------------------------------------------------
75
AnyObject
*
GetResponse
()
76
{
77
return
pResponse
;
78
}
79
80
//------------------------------------------------------------------------
82
//------------------------------------------------------------------------
83
void
WaitForResponse
()
84
{
85
pSem
->
Wait
();
86
}
87
88
private
:
89
XRootDStatus
*
pStatus
;
90
AnyObject
*
pResponse
;
91
XrdSysSemaphore
*
pSem
;
92
};
93
94
//----------------------------------------------------------------------------
95
// Sending parameters
96
//----------------------------------------------------------------------------
97
struct
MessageSendParams
98
{
99
MessageSendParams
():
100
timeout
(0),
expires
(0),
followRedirects
(true),
stateful
(true),
101
hostList
(0),
chunkList
(0),
redirectLimit
(0) {}
102
uint16_t
timeout
;
103
time_t
expires
;
104
const
HostInfo
loadBalancer
;
105
bool
followRedirects
;
106
bool
stateful
;
107
HostList
*
hostList
;
108
ChunkList
*
chunkList
;
109
uint16_t
redirectLimit
;
110
};
111
112
class
MessageUtils
113
{
114
public
:
115
//------------------------------------------------------------------------
117
//------------------------------------------------------------------------
118
static
XRootDStatus
WaitForStatus
(
SyncResponseHandler
*handler )
119
{
120
handler->
WaitForResponse
();
121
XRootDStatus
*status = handler->
GetStatus
();
122
XRootDStatus
ret( *status );
123
delete
status;
124
return
ret;
125
}
126
127
//------------------------------------------------------------------------
129
//------------------------------------------------------------------------
130
template
<
class
Type>
131
static
XrdCl::XRootDStatus
WaitForResponse
(
132
SyncResponseHandler
*handler,
133
Type *&response )
134
{
135
handler->
WaitForResponse
();
136
137
std::auto_ptr<AnyObject> resp( handler->
GetResponse
() );
138
XRootDStatus
*status = handler->
GetStatus
();
139
XRootDStatus
ret( *status );
140
delete
status;
141
142
if
( ret.
IsOK
() )
143
{
144
if
( !resp.get() )
145
return
XRootDStatus
(
stError
,
errInternal
);
146
resp->Get( response );
147
resp->Set( (
int
*)0 );
148
if
( !response )
149
return
XRootDStatus
(
stError
,
errInternal
);
150
}
151
152
return
ret;
153
}
154
155
//------------------------------------------------------------------------
157
//------------------------------------------------------------------------
158
template
<
class
Type>
159
static
void
CreateRequest
(
Message
*&msg,
160
Type *&req,
161
uint32_t payloadSize = 0 )
162
{
163
msg =
new
Message
(
sizeof
(Type)+payloadSize );
164
req = (Type*)msg->
GetBuffer
();
165
msg->
Zero
();
166
}
167
168
//------------------------------------------------------------------------
170
//------------------------------------------------------------------------
171
static
Status
SendMessage
(
const
URL
&url,
172
Message
*msg,
173
ResponseHandler
*handler,
174
const
MessageSendParams
&sendParams );
175
176
//------------------------------------------------------------------------
178
//------------------------------------------------------------------------
179
static
void
ProcessSendParams
(
MessageSendParams
&sendParams );
180
181
//------------------------------------------------------------------------
189
//------------------------------------------------------------------------
190
static
void
AppendCGI
(
Message
*msg,
191
const
URL::ParamsMap
&newCgi,
192
bool
replace );
193
194
//------------------------------------------------------------------------
202
//------------------------------------------------------------------------
203
static
void
MergeCGI
(
URL::ParamsMap
&cgi1,
204
const
URL::ParamsMap
&cgi2,
205
bool
replace );
206
};
207
}
208
209
#endif // __XRD_CL_MESSAGE_UTILS_HH__
Generated by
1.8.3.1