xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
XrdClMessageUtils.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2011-2014 by European Organization for Nuclear Research (CERN)
3 // Author: Lukasz Janyst <ljanyst@cern.ch>
4 //------------------------------------------------------------------------------
5 // This file is part of the XRootD software suite.
6 //
7 // XRootD is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // XRootD is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with XRootD. If not, see <http://www.gnu.org/licenses/>.
19 //
20 // In applying this licence, CERN does not waive the privileges and immunities
21 // granted to it by virtue of its status as an Intergovernmental Organization
22 // or submit itself to any jurisdiction.
23 //------------------------------------------------------------------------------
24 
25 #ifndef __XRD_CL_MESSAGE_UTILS_HH__
26 #define __XRD_CL_MESSAGE_UTILS_HH__
27 
29 #include "XrdCl/XrdClURL.hh"
30 #include "XrdCl/XrdClMessage.hh"
31 #include "XrdCl/XrdClUglyHacks.hh"
32 
33 namespace XrdCl
34 {
35  class LocalFileHandler;
36 
37  //----------------------------------------------------------------------------
39  //----------------------------------------------------------------------------
41  {
42  public:
43  //------------------------------------------------------------------------
45  //------------------------------------------------------------------------
47  pStatus(0),
48  pResponse(0),
49  pCondVar(0) {}
50 
51  //------------------------------------------------------------------------
53  //------------------------------------------------------------------------
55  {
56  }
57 
58 
59  //------------------------------------------------------------------------
61  //------------------------------------------------------------------------
62  virtual void HandleResponse( XRootDStatus *status,
63  AnyObject *response )
64  {
65  XrdSysCondVarHelper scopedLock(pCondVar);
66  pStatus = status;
67  pResponse = response;
69  }
70 
71  //------------------------------------------------------------------------
73  //------------------------------------------------------------------------
75  {
76  return pStatus;
77  }
78 
79  //------------------------------------------------------------------------
81  //------------------------------------------------------------------------
83  {
84  return pResponse;
85  }
86 
87  //------------------------------------------------------------------------
89  //------------------------------------------------------------------------
91  {
92  XrdSysCondVarHelper scopedLock(pCondVar);
93  while (pStatus == 0) {
94  pCondVar.Wait();
95  }
96  }
97 
98  private:
101 
105  };
106 
107 
108  //----------------------------------------------------------------------------
109  // We're not interested in the response just commit suicide
110  //----------------------------------------------------------------------------
112  {
113  public:
114  //------------------------------------------------------------------------
115  // Handle the response
116  //------------------------------------------------------------------------
118  XrdCl::AnyObject *response,
119  XrdCl::HostList *hostList )
120  {
121  delete this;
122  }
123  };
124 
125  //----------------------------------------------------------------------------
126  // Sending parameters
127  //----------------------------------------------------------------------------
129  {
131  timeout(0), expires(0), followRedirects(true), stateful(true),
132  hostList(0), chunkList(0), redirectLimit(0) {}
133  uint16_t timeout;
134  time_t expires;
137  bool stateful;
140  uint16_t redirectLimit;
141  };
142 
144  {
145  public:
146  //------------------------------------------------------------------------
148  //------------------------------------------------------------------------
150  {
151  handler->WaitForResponse();
152  XRootDStatus *status = handler->GetStatus();
153  XRootDStatus ret( *status );
154  delete status;
155  return ret;
156  }
157 
158  //------------------------------------------------------------------------
160  //------------------------------------------------------------------------
161  template<class Type>
163  SyncResponseHandler *handler,
164  Type *&response )
165  {
166  handler->WaitForResponse();
167 
168  AnyObject *resp = handler->GetResponse();
169  XRootDStatus *status = handler->GetStatus();
170  XRootDStatus ret( *status );
171  delete status;
172 
173  if( ret.IsOK() )
174  {
175  if( !resp )
176  return XRootDStatus( stError, errInternal );
177  resp->Get( response );
178  resp->Set( (int *)0 );
179  delete resp;
180 
181  if( !response )
182  return XRootDStatus( stError, errInternal );
183  }
184 
185  return ret;
186  }
187 
188  //------------------------------------------------------------------------
190  //------------------------------------------------------------------------
191  template<class Request>
192  static void CreateRequest( Message *&msg,
193  Request *&req,
194  uint32_t payloadSize = 0 )
195  {
196  msg = new Message( sizeof(Request) + payloadSize );
197  req = (Request*)msg->GetBuffer();
198  msg->Zero();
199  }
200 
201  //------------------------------------------------------------------------
203  //------------------------------------------------------------------------
204  static Status SendMessage( const URL &url,
205  Message *msg,
206  ResponseHandler *handler,
207  const MessageSendParams &sendParams,
208  LocalFileHandler *lFileHandler );
209 
210  //------------------------------------------------------------------------
212  //------------------------------------------------------------------------
213  static Status RedirectMessage( const URL &url,
214  Message *msg,
215  ResponseHandler *handler,
216  MessageSendParams &sendParams,
217  LocalFileHandler *lFileHandler );
218 
219  //------------------------------------------------------------------------
221  //------------------------------------------------------------------------
222  static void ProcessSendParams( MessageSendParams &sendParams );
223 
224  //------------------------------------------------------------------------
234  //------------------------------------------------------------------------
235  static void RewriteCGIAndPath( Message *msg,
236  const URL::ParamsMap &newCgi,
237  bool replace,
238  const std::string &newPath );
239 
240  //------------------------------------------------------------------------
248  //------------------------------------------------------------------------
249  static void MergeCGI( URL::ParamsMap &cgi1,
250  const URL::ParamsMap &cgi2,
251  bool replace );
252  };
253 }
254 
255 #endif // __XRD_CL_MESSAGE_UTILS_HH__
Definition: XrdClMessageUtils.hh:111
Definition: XrdClAnyObject.hh:32
std::map< std::string, std::string > ParamsMap
Definition: XrdClURL.hh:33
Definition: XrdClMessageUtils.hh:128
uint16_t redirectLimit
Definition: XrdClMessageUtils.hh:140
std::vector< ChunkInfo > ChunkList
List of chunks.
Definition: XrdClXRootDResponses.hh:769
XRootDStatus * GetStatus()
Get the status.
Definition: XrdClMessageUtils.hh:74
void Get(Type &object)
Retrieve the object being held.
Definition: XrdClAnyObject.hh:78
The message representation used throughout the system.
Definition: XrdClMessage.hh:29
static XRootDStatus WaitForStatus(SyncResponseHandler *handler)
Wait and return the status of the query.
Definition: XrdClMessageUtils.hh:149
virtual void HandleResponseWithHosts(XrdCl::XRootDStatus *status, XrdCl::AnyObject *response, XrdCl::HostList *hostList)
Definition: XrdClMessageUtils.hh:117
bool followRedirects
Definition: XrdClMessageUtils.hh:136
uint16_t timeout
Definition: XrdClMessageUtils.hh:133
Synchronize the response.
Definition: XrdClMessageUtils.hh:40
SyncResponseHandler()
Constructor.
Definition: XrdClMessageUtils.hh:46
static XrdCl::XRootDStatus WaitForResponse(SyncResponseHandler *handler, Type *&response)
Wait for the response.
Definition: XrdClMessageUtils.hh:162
static void MergeCGI(URL::ParamsMap &cgi1, const URL::ParamsMap &cgi2, bool replace)
const char * GetBuffer(uint32_t offset=0) const
Get the message buffer.
Definition: XrdClBuffer.hh:72
Procedure execution status.
Definition: XrdClStatus.hh:109
SyncResponseHandler & operator=(const SyncResponseHandler &other)
Definition: XrdClMessageUtils.hh:143
virtual ~SyncResponseHandler()
Destructor.
Definition: XrdClMessageUtils.hh:54
AnyObject * GetResponse()
Get the response.
Definition: XrdClMessageUtils.hh:82
static void RewriteCGIAndPath(Message *msg, const URL::ParamsMap &newCgi, bool replace, const std::string &newPath)
Definition: XrdClXRootDResponses.hh:822
std::vector< HostInfo > HostList
Definition: XrdClXRootDResponses.hh:834
Definition: XrdSysPthread.hh:78
void Set(Type object, bool own=true)
Definition: XrdClAnyObject.hh:59
const uint16_t stError
An error occurred that could potentially be retried.
Definition: XrdClStatus.hh:32
Request status.
Definition: XrdClXRootDResponses.hh:212
ChunkList * chunkList
Definition: XrdClMessageUtils.hh:139
HostList * hostList
Definition: XrdClMessageUtils.hh:138
void WaitForResponse()
Wait for the arrival of the response.
Definition: XrdClMessageUtils.hh:90
HostInfo loadBalancer
Definition: XrdClMessageUtils.hh:135
void Broadcast()
Definition: XrdSysPthread.hh:89
Definition: XrdSysPthread.hh:129
MessageSendParams()
Definition: XrdClMessageUtils.hh:130
bool stateful
Definition: XrdClMessageUtils.hh:137
static Status SendMessage(const URL &url, Message *msg, ResponseHandler *handler, const MessageSendParams &sendParams, LocalFileHandler *lFileHandler)
Send message.
Handle an async response.
Definition: XrdClXRootDResponses.hh:839
Definition: XrdClLocalFileHandler.hh:32
URL representation.
Definition: XrdClURL.hh:30
time_t expires
Definition: XrdClMessageUtils.hh:134
const uint16_t errInternal
Internal error.
Definition: XrdClStatus.hh:55
AnyObject * pResponse
Definition: XrdClMessageUtils.hh:103
bool IsOK() const
We&#39;re fine.
Definition: XrdClStatus.hh:119
XrdSysCondVar pCondVar
Definition: XrdClMessageUtils.hh:104
XRootDStatus * pStatus
Definition: XrdClMessageUtils.hh:102
static void ProcessSendParams(MessageSendParams &sendParams)
Process sending params.
void Zero()
Zero.
Definition: XrdClBuffer.hh:124
static Status RedirectMessage(const URL &url, Message *msg, ResponseHandler *handler, MessageSendParams &sendParams, LocalFileHandler *lFileHandler)
Redirect message.
virtual void HandleResponse(XRootDStatus *status, AnyObject *response)
Handle the response.
Definition: XrdClMessageUtils.hh:62
static void CreateRequest(Message *&msg, Request *&req, uint32_t payloadSize=0)
Create a message.
Definition: XrdClMessageUtils.hh:192