XRootD
XrdEcUtilities.cc
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2011-2014 by European Organization for Nuclear Research (CERN)
3 // Author: Michal Simon <michal.simon@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 #include "XrdEc/XrdEcUtilities.hh"
26 #include "XrdCl/XrdClJobManager.hh"
27 #include "XrdCl/XrdClPostMaster.hh"
28 #include "XrdCl/XrdClDefaultEnv.hh"
29 
30 namespace XrdEc
31 {
32  //---------------------------------------------------------------------------
33  // A job for scheduling the user callback
34  //---------------------------------------------------------------------------
35  class ResponseJob : public XrdCl::Job
36  {
37  public:
38  //-----------------------------------------------------------------------
39  // Constructor
40  //-----------------------------------------------------------------------
42  XrdCl::XRootDStatus *status,
43  XrdCl::AnyObject *response ):
44  pHandler( handler ), pStatus( status ), pResponse( response )
45  {
46  }
47 
48  virtual void Run( void *arg )
49  {
50  pHandler->HandleResponse( pStatus, pResponse );
51  delete this;
52  }
53 
54  private:
55 
56  XrdCl::ResponseHandler *pHandler; //< user callback
57  XrdCl::XRootDStatus *pStatus; //< operation status
58  XrdCl::AnyObject *pResponse; //< user response
59  };
60 
61  //---------------------------------------------------------------------------
62  // A utility function for scheduling read operation handler
63  //---------------------------------------------------------------------------
64  void ScheduleHandler( uint64_t offset, uint32_t size, void *buffer, XrdCl::ResponseHandler *handler )
65  {
66  if( !handler ) return;
67 
68  XrdCl::ChunkInfo *chunk = new XrdCl::ChunkInfo();
69  chunk->offset = offset;
70  chunk->length = size;
71  chunk->buffer = buffer;
72 
73  XrdCl::AnyObject *resp = new XrdCl::AnyObject();
74  resp->Set( chunk );
75 
76  ResponseJob *job = new ResponseJob( handler, new XrdCl::XRootDStatus(), resp );
78  }
79 
80  //---------------------------------------------------------------------------
81  // A utility function for scheduling an operation handler
82  //---------------------------------------------------------------------------
84  {
85  if( !handler ) return;
86 
87  ResponseJob *job = new ResponseJob( handler, new XrdCl::XRootDStatus( st ), 0 );
89  }
90 
91 }
void Set(Type object, bool own=true)
static PostMaster * GetPostMaster()
Get default post master.
void QueueJob(Job *job, void *arg=0)
Add a job to be run.
Interface for a job to be run by the job manager.
JobManager * GetJobManager()
Get the job manager object user by the post master.
Handle an async response.
virtual void HandleResponse(XRootDStatus *status, AnyObject *response)
ResponseJob(XrdCl::ResponseHandler *handler, XrdCl::XRootDStatus *status, XrdCl::AnyObject *response)
virtual void Run(void *arg)
The job logic.
void ScheduleHandler(uint64_t offset, uint32_t size, void *buffer, XrdCl::ResponseHandler *handler)
Describe a data chunk for vector read.
void * buffer
length of the chunk
uint32_t length
offset in the file