//------------------------------------------------------------------------------ // Copyright (c) 2011-2017 by European Organization for Nuclear Research (CERN) // Author: Krzysztof Jamrog , // Michal Simon //------------------------------------------------------------------------------ // This file is part of the XRootD software suite. // // XRootD is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // XRootD is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with XRootD. If not, see . // // In applying this licence, CERN does not waive the privileges and immunities // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. //------------------------------------------------------------------------------ #ifndef __XRD_CL_FILE_OPERATIONS_HH__ #define __XRD_CL_FILE_OPERATIONS_HH__ #include "XrdCl/XrdClFile.hh" #include "XrdCl/XrdClOperations.hh" #include "XrdCl/XrdClOperationHandlers.hh" #include "XrdCl/XrdClCtx.hh" namespace XrdCl { //---------------------------------------------------------------------------- //! Base class for all file related operations //! //! @arg Derived : the class that derives from this template (CRTP) //! @arg HasHndl : true if operation has a handler, false otherwise //! @arg Args : operation arguments //---------------------------------------------------------------------------- template class Derived, bool HasHndl, typename Response, typename ... Arguments> class FileOperation: public ConcreteOperation { template class, bool, typename, typename ...> friend class FileOperation; public: //------------------------------------------------------------------------ //! Constructor //! //! @param f : file on which the operation will be performed //! @param args : file operation arguments //------------------------------------------------------------------------ FileOperation( Ctx f, Arguments... args): ConcreteOperation( std::move( args )... ), file( std::move( f ) ) { } //------------------------------------------------------------------------ //! Move constructor from other states //! //! @arg from : state from which the object is being converted //! //! @param op : the object that is being converted //------------------------------------------------------------------------ template FileOperation( FileOperation && op ) : ConcreteOperation( std::move( op ) ), file( op.file ) { } //------------------------------------------------------------------------ //! Destructor //------------------------------------------------------------------------ virtual ~FileOperation() { } protected: //------------------------------------------------------------------------ //! The file object itself //------------------------------------------------------------------------ Ctx file; }; //---------------------------------------------------------------------------- //! Open operation (@see FileOperation) //---------------------------------------------------------------------------- template class OpenImpl: public FileOperation, Arg, Arg, Arg> { //------------------------------------------------------------------------ //! Helper for extending the operator>> capabilities. //! //! In addition to standard overloads for std::function adds: //! - void( XRootDStatus&, StatInfo& ) //! - void( XRootDStatus&, StatInfo&, OperationContext& ) //------------------------------------------------------------------------ struct ExResp : public Resp { //-------------------------------------------------------------------- //! Constructor //! //! @param file : the underlying XrdCl::File object //-------------------------------------------------------------------- ExResp( const Ctx &file ): file( file ) { } //-------------------------------------------------------------------- //! A factory method //! //! @param func : the function/functor/lambda that should be wrapped //! @return : ResponseHandler instance //-------------------------------------------------------------------- inline ResponseHandler* Create( std::function func ) { return new ExOpenFuncWrapper( this->file, func ); } //-------------------------------------------------------------------- //! Make other overloads of Create visible //-------------------------------------------------------------------- using Resp::Create; //-------------------------------------------------------------------- //! The underlying XrdCl::File object //-------------------------------------------------------------------- Ctx file; }; public: //------------------------------------------------------------------------ //! Constructor (@see FileOperation) //------------------------------------------------------------------------ OpenImpl( Ctx f, Arg url, Arg flags, Arg mode = Access::None ) : FileOperation, Arg, Arg, Arg>( std::move( f ), std::move( url ), std::move( flags ), std::move( mode ) ) { } //------------------------------------------------------------------------ //! Move constructor from other states //! //! @arg from : state from which the object is being converted //! //! @param open : the object that is being converted //------------------------------------------------------------------------ template OpenImpl( OpenImpl && open ) : FileOperation, Arg, Arg, Arg>( std::move( open ) ) { } //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { UrlArg, FlagsArg, ModeArg }; //------------------------------------------------------------------------ //! Overload of operator>> defined in ConcreteOperation, we're adding //! additional capabilities by using ExResp factory (@see ExResp). //! //! @param hdlr : function/functor/lambda //------------------------------------------------------------------------ template OpenImpl operator>>( Hdlr &&hdlr ) { ExResp factory( *this->file ); return this->StreamImpl( factory.Create( hdlr ) ); } //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "Open"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param pipelineTimeout : pipeline timeout //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout ) { const std::string &url = std::get( this->args ); OpenFlags::Flags flags = std::get( this->args ); Access::Mode mode = std::get( this->args ); uint16_t timeout = pipelineTimeout < this->timeout ? pipelineTimeout : this->timeout; return this->file->Open( url, flags, mode, handler, timeout ); } }; //---------------------------------------------------------------------------- //! Factory for creating ReadImpl objects //---------------------------------------------------------------------------- inline OpenImpl Open( Ctx file, Arg url, Arg flags, Arg mode = Access::None, uint16_t timeout = 0 ) { return OpenImpl( std::move( file ), std::move( url ), std::move( flags ), std::move( mode ) ).Timeout( timeout ); } //---------------------------------------------------------------------------- //! Read operation (@see FileOperation) //---------------------------------------------------------------------------- template class ReadImpl: public FileOperation, Arg, Arg, Arg> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileOperation (@see FileOperation) //------------------------------------------------------------------------ using FileOperation, Arg, Arg, Arg>::FileOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { OffsetArg, SizeArg, BufferArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "Read"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout ) { uint64_t offset = std::get( this->args ).Get(); uint32_t size = std::get( this->args ).Get(); void *buffer = std::get( this->args ).Get(); uint16_t timeout = pipelineTimeout < this->timeout ? pipelineTimeout : this->timeout; return this->file->Read( offset, size, buffer, handler, timeout ); } }; //---------------------------------------------------------------------------- //! Factory for creating ReadImpl objects //---------------------------------------------------------------------------- inline ReadImpl Read( Ctx file, Arg offset, Arg size, Arg buffer, uint16_t timeout = 0 ) { return ReadImpl( std::move( file ), std::move( offset ), std::move( size ), std::move( buffer ) ).Timeout( timeout ); } //---------------------------------------------------------------------------- //! PgRead operation (@see FileOperation) //---------------------------------------------------------------------------- template class PgReadImpl: public FileOperation, Arg, Arg, Arg> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileOperation (@see FileOperation) //------------------------------------------------------------------------ using FileOperation, Arg, Arg, Arg>::FileOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { OffsetArg, SizeArg, BufferArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "PgRead"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout ) { uint64_t offset = std::get( this->args ).Get(); uint32_t size = std::get( this->args ).Get(); void *buffer = std::get( this->args ).Get(); uint16_t timeout = pipelineTimeout < this->timeout ? pipelineTimeout : this->timeout; return this->file->PgRead( offset, size, buffer, handler, timeout ); } }; //---------------------------------------------------------------------------- //! Factory for creating PgReadImpl objects //---------------------------------------------------------------------------- inline PgReadImpl PgRead( Ctx file, Arg offset, Arg size, Arg buffer, uint16_t timeout = 0 ) { return PgReadImpl( std::move( file ), std::move( offset ), std::move( size ), std::move( buffer ) ).Timeout( timeout ); } //---------------------------------------------------------------------------- //! RdWithRsp: factory for creating ReadImpl/PgReadImpl objects //---------------------------------------------------------------------------- template struct ReadTrait { }; template<> struct ReadTrait { using RET = ReadImpl; }; template<> struct ReadTrait { using RET = PgReadImpl; }; template inline typename ReadTrait::RET RdWithRsp( Ctx file, Arg offset, Arg size, Arg buffer, uint16_t timeout = 0 ); template<> inline ReadImpl RdWithRsp( Ctx file, Arg offset, Arg size, Arg buffer, uint16_t timeout ) { return Read( std::move( file ), std::move( offset ), std::move( size ), std::move( buffer ), timeout ); } template<> inline PgReadImpl RdWithRsp( Ctx file, Arg offset, Arg size, Arg buffer, uint16_t timeout ) { return PgRead( std::move( file ), std::move( offset ), std::move( size ), std::move( buffer ), timeout ); } //---------------------------------------------------------------------------- //! PgWrite operation (@see FileOperation) //---------------------------------------------------------------------------- template class PgWriteImpl: public FileOperation, Arg, Arg, Arg, Arg>> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileOperation (@see FileOperation) //------------------------------------------------------------------------ using FileOperation, Arg, Arg, Arg, Arg>>::FileOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { OffsetArg, SizeArg, BufferArg, CksumsArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "PgWrite"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout ) { uint64_t offset = std::get( this->args ).Get(); uint32_t size = std::get( this->args ).Get(); void *buffer = std::get( this->args ).Get(); std::vector cksums = std::get( this->args ).Get(); uint16_t timeout = pipelineTimeout < this->timeout ? pipelineTimeout : this->timeout; return this->file->PgWrite( offset, size, buffer, cksums, handler, timeout ); } }; //---------------------------------------------------------------------------- //! Factory for creating PgReadImpl objects //---------------------------------------------------------------------------- inline PgWriteImpl PgWrite( Ctx file, Arg offset, Arg size, Arg buffer, Arg> cksums, uint16_t timeout = 0 ) { return PgWriteImpl( std::move( file ), std::move( offset ), std::move( size ), std::move( buffer ), std::move( cksums ) ).Timeout( timeout ); } //---------------------------------------------------------------------------- //! Factory for creating PgReadImpl objects //---------------------------------------------------------------------------- inline PgWriteImpl PgWrite( Ctx file, Arg offset, Arg size, Arg buffer, uint16_t timeout = 0 ) { std::vector cksums; return PgWriteImpl( std::move( file ), std::move( offset ), std::move( size ), std::move( buffer ), std::move( cksums ) ).Timeout( timeout ); } //---------------------------------------------------------------------------- //! Close operation (@see FileOperation) //---------------------------------------------------------------------------- template class CloseImpl: public FileOperation> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileOperation (@see FileOperation) //------------------------------------------------------------------------ using FileOperation>::FileOperation; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "Close"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout ) { uint16_t timeout = pipelineTimeout < this->timeout ? pipelineTimeout : this->timeout; return this->file->Close( handler, timeout ); } }; //---------------------------------------------------------------------------- //! Factory for creating CloseImpl objects //---------------------------------------------------------------------------- inline CloseImpl Close( Ctx file, uint16_t timeout = 0 ) { return CloseImpl( std::move( file ) ).Timeout( timeout ); } //---------------------------------------------------------------------------- //! Stat operation (@see FileOperation) //---------------------------------------------------------------------------- template class StatImpl: public FileOperation, Arg> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileOperation (@see FileOperation) //------------------------------------------------------------------------ using FileOperation, Arg>::FileOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { ForceArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "Stat"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout ) { bool force = std::get( this->args ).Get(); uint16_t timeout = pipelineTimeout < this->timeout ? pipelineTimeout : this->timeout; return this->file->Stat( force, handler, timeout ); } }; //---------------------------------------------------------------------------- //! Factory for creating StatImpl objects (as there is another Stat in //! FileSystem there would be a clash of typenames). //---------------------------------------------------------------------------- inline StatImpl Stat( Ctx file, Arg force, uint16_t timeout = 0 ) { return StatImpl( std::move( file ), std::move( force ) ).Timeout( timeout ); } //---------------------------------------------------------------------------- //! Write operation (@see FileOperation) //---------------------------------------------------------------------------- template class WriteImpl: public FileOperation, Arg, Arg, Arg> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileOperation (@see FileOperation) //------------------------------------------------------------------------ using FileOperation, Arg, Arg, Arg>::FileOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { OffsetArg, SizeArg, BufferArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "Write"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout ) { uint64_t offset = std::get( this->args ).Get(); uint32_t size = std::get( this->args ).Get(); const void *buffer = std::get( this->args ).Get(); uint16_t timeout = pipelineTimeout < this->timeout ? pipelineTimeout : this->timeout; return this->file->Write( offset, size, buffer, handler, timeout ); } }; //---------------------------------------------------------------------------- //! Factory for creating WriteImpl objects //---------------------------------------------------------------------------- inline WriteImpl Write( Ctx file, Arg offset, Arg size, Arg buffer, uint16_t timeout = 0 ) { return WriteImpl( std::move( file ), std::move( offset ), std::move( size ), std::move( buffer ) ).Timeout( timeout ); } //---------------------------------------------------------------------------- //! Sync operation (@see FileOperation) //---------------------------------------------------------------------------- template class SyncImpl: public FileOperation> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileOperation (@see FileOperation) //------------------------------------------------------------------------ using FileOperation>::FileOperation; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "Sync"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout ) { uint16_t timeout = pipelineTimeout < this->timeout ? pipelineTimeout : this->timeout; return this->file->Sync( handler, timeout ); } }; //---------------------------------------------------------------------------- //! Factory for creating SyncImpl objects //---------------------------------------------------------------------------- inline SyncImpl Sync( Ctx file, uint16_t timeout = 0 ) { return SyncImpl( std::move( file ) ).Timeout( timeout ); } //---------------------------------------------------------------------------- //! Truncate operation (@see FileOperation) //---------------------------------------------------------------------------- template class TruncateImpl: public FileOperation, Arg> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileOperation (@see FileOperation) //------------------------------------------------------------------------ using FileOperation, Arg>::FileOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { SizeArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "Truncate"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout ) { uint64_t size = std::get( this->args ).Get(); uint16_t timeout = pipelineTimeout < this->timeout ? pipelineTimeout : this->timeout; return this->file->Truncate( size, handler, timeout ); } }; //---------------------------------------------------------------------------- //! Factory for creating TruncateImpl objects (as there is another Stat in //! FileSystem there would be a clash of typenames). //---------------------------------------------------------------------------- inline TruncateImpl Truncate( Ctx file, Arg size, uint16_t timeout ) { return TruncateImpl( std::move( file ), std::move( size ) ).Timeout( timeout ); } //---------------------------------------------------------------------------- //! VectorRead operation (@see FileOperation) //---------------------------------------------------------------------------- template class VectorReadImpl: public FileOperation, Arg, Arg> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileOperation (@see FileOperation) //------------------------------------------------------------------------ using FileOperation, Arg, Arg>::FileOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { ChunksArg, BufferArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "VectorRead"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout ) { ChunkList &chunks = std::get( this->args ).Get(); void *buffer = std::get( this->args ).Get(); uint16_t timeout = pipelineTimeout < this->timeout ? pipelineTimeout : this->timeout; return this->file->VectorRead( chunks, buffer, handler, timeout ); } }; //---------------------------------------------------------------------------- //! Factory for creating VectorReadImpl objects //---------------------------------------------------------------------------- inline VectorReadImpl VectorRead( Ctx file, Arg chunks, Arg buffer, uint16_t timeout = 0 ) { return VectorReadImpl( std::move( file ), std::move( chunks ), std::move( buffer ) ).Timeout( timeout ); } inline VectorReadImpl VectorRead( Ctx file, Arg chunks, uint16_t timeout = 0 ) { return VectorReadImpl( std::move( file ), std::move( chunks ), nullptr ).Timeout( timeout ); } //---------------------------------------------------------------------------- //! VectorWrite operation (@see FileOperation) //---------------------------------------------------------------------------- template class VectorWriteImpl: public FileOperation, Arg> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileOperation (@see FileOperation) //------------------------------------------------------------------------ using FileOperation, Arg>::FileOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { ChunksArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "VectorWrite"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout ) { const ChunkList &chunks = std::get( this->args ).Get(); uint16_t timeout = pipelineTimeout < this->timeout ? pipelineTimeout : this->timeout; return this->file->VectorWrite( chunks, handler, timeout ); } }; //---------------------------------------------------------------------------- //! Factory for creating VectorWriteImpl objects //---------------------------------------------------------------------------- inline VectorWriteImpl VectorWrite( Ctx file, Arg chunks, uint16_t timeout = 0 ) { return VectorWriteImpl( std::move( file ), std::move( chunks ) ).Timeout( timeout ); } //---------------------------------------------------------------------------- //! WriteV operation (@see FileOperation) //---------------------------------------------------------------------------- template class WriteVImpl: public FileOperation, Arg, Arg>> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileOperation (@see FileOperation) //------------------------------------------------------------------------ using FileOperation, Arg, Arg>>::FileOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { OffsetArg, IovArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "WriteV"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout ) { uint64_t offset = std::get( this->args ).Get(); std::vector &stdiov = std::get( this->args ).Get(); uint16_t timeout = pipelineTimeout < this->timeout ? pipelineTimeout : this->timeout; int iovcnt = stdiov.size(); iovec iov[iovcnt]; for( size_t i = 0; i < stdiov.size(); ++i ) { iov[i].iov_base = stdiov[i].iov_base; iov[i].iov_len = stdiov[i].iov_len; } return this->file->WriteV( offset, iov, iovcnt, handler, timeout ); } }; //---------------------------------------------------------------------------- //! Factory for creating WriteVImpl objects //---------------------------------------------------------------------------- inline WriteVImpl WriteV( Ctx file, Arg offset, Arg> iov, uint16_t timeout = 0 ) { return WriteVImpl( std::move( file ), std::move( offset ), std::move( iov ) ).Timeout( timeout ); } //---------------------------------------------------------------------------- //! Fcntl operation (@see FileOperation) //---------------------------------------------------------------------------- template class FcntlImpl: public FileOperation, Arg> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileOperation (@see FileOperation) //------------------------------------------------------------------------ using FileOperation, Arg>::FileOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { BufferArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "Fcntl"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout ) { Buffer &arg = std::get( this->args ).Get(); uint16_t timeout = pipelineTimeout < this->timeout ? pipelineTimeout : this->timeout; return this->file->Fcntl( arg, handler, timeout ); } }; typedef FcntlImpl Fcntl; //---------------------------------------------------------------------------- //! Visa operation (@see FileOperation) //---------------------------------------------------------------------------- template class VisaImpl: public FileOperation> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileOperation (@see FileOperation) //------------------------------------------------------------------------ using FileOperation>::FileOperation; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "Visa"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout ) { uint16_t timeout = pipelineTimeout < this->timeout ? pipelineTimeout : this->timeout; return this->file->Visa( handler, timeout ); } }; typedef VisaImpl Visa; //---------------------------------------------------------------------------- //! SetXAttr operation (@see FileOperation) //---------------------------------------------------------------------------- template class SetXAttrImpl: public FileOperation, Arg, Arg> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileOperation (@see FileOperation) //------------------------------------------------------------------------ using FileOperation, Arg, Arg>::FileOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { NameArg, ValueArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "SetXAttrImpl"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout ) { std::string &name = std::get( this->args ).Get(); std::string &value = std::get( this->args ).Get(); // wrap the arguments with a vector std::vector attrs; attrs.push_back( xattr_t( name, value ) ); // wrap the PipelineHandler so the response gets unpacked properly UnpackXAttrStatus *h = new UnpackXAttrStatus( handler ); uint16_t timeout = pipelineTimeout < this->timeout ? pipelineTimeout : this->timeout; XRootDStatus st = this->file->SetXAttr( attrs, h, timeout ); if( !st.IsOK() ) delete h; return st; } }; //---------------------------------------------------------------------------- //! Factory for creating SetXAttrImpl objects (as there is another SetXAttr in //! FileSystem there would be a clash of typenames). //---------------------------------------------------------------------------- inline SetXAttrImpl SetXAttr( Ctx file, Arg name, Arg value ) { return SetXAttrImpl( std::move( file ), std::move( name ), std::move( value ) ); } //---------------------------------------------------------------------------- //! SetXAttr bulk operation (@see FileOperation) //---------------------------------------------------------------------------- template class SetXAttrBulkImpl: public FileOperation>, Arg>> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileOperation (@see FileOperation) //------------------------------------------------------------------------ using FileOperation>, Arg>>::FileOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { AttrsArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "SetXAttrBulkImpl"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout ) { std::vector &attrs = std::get( this->args ).Get(); uint16_t timeout = pipelineTimeout < this->timeout ? pipelineTimeout : this->timeout; return this->file->SetXAttr( attrs, handler, timeout ); } }; //---------------------------------------------------------------------------- //! Factory for creating SetXAttrBulkImpl objects (as there is another SetXAttr //! in FileSystem there would be a clash of typenames). //---------------------------------------------------------------------------- inline SetXAttrBulkImpl SetXAttr( Ctx file, Arg> attrs ) { return SetXAttrBulkImpl( std::move( file ), std::move( attrs ) ); } //---------------------------------------------------------------------------- //! GetXAttr operation (@see FileOperation) //---------------------------------------------------------------------------- template class GetXAttrImpl: public FileOperation, Arg> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileOperation (@see FileOperation) //------------------------------------------------------------------------ using FileOperation, Arg>::FileOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { NameArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "GetXAttrImpl"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout ) { std::string &name = std::get( this->args ).Get(); // wrap the argument with a vector std::vector attrs; attrs.push_back( name ); // wrap the PipelineHandler so the response gets unpacked properly UnpackXAttr *h = new UnpackXAttr( handler ); uint16_t timeout = pipelineTimeout < this->timeout ? pipelineTimeout : this->timeout; XRootDStatus st = this->file->GetXAttr( attrs, h, timeout ); if( !st.IsOK() ) delete h; return st; } }; //---------------------------------------------------------------------------- //! Factory for creating GetXAttrImpl objects (as there is another GetXAttr in //! FileSystem there would be a clash of typenames). //---------------------------------------------------------------------------- inline GetXAttrImpl GetXAttr( Ctx file, Arg name ) { return GetXAttrImpl( std::move( file ), std::move( name ) ); } //---------------------------------------------------------------------------- //! GetXAttr bulk operation (@see FileOperation) //---------------------------------------------------------------------------- template class GetXAttrBulkImpl: public FileOperation>, Arg>> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileOperation (@see FileOperation) //------------------------------------------------------------------------ using FileOperation>, Arg>>::FileOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { NamesArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "GetXAttrBulkImpl"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout ) { std::vector &attrs = std::get( this->args ).Get(); uint16_t timeout = pipelineTimeout < this->timeout ? pipelineTimeout : this->timeout; return this->file->GetXAttr( attrs, handler, timeout ); } }; //---------------------------------------------------------------------------- //! Factory for creating GetXAttrBulkImpl objects (as there is another GetXAttr in //! FileSystem there would be a clash of typenames). //---------------------------------------------------------------------------- inline GetXAttrBulkImpl GetXAttr( Ctx file, Arg> attrs ) { return GetXAttrBulkImpl( std::move( file ), std::move( attrs ) ); } //---------------------------------------------------------------------------- //! DelXAttr operation (@see FileOperation) //---------------------------------------------------------------------------- template class DelXAttrImpl: public FileOperation, Arg> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileOperation (@see FileOperation) //------------------------------------------------------------------------ using FileOperation, Arg>::FileOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { NameArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "DelXAttrImpl"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout ) { std::string &name = std::get( this->args ).Get(); // wrap the argument with a vector std::vector attrs; attrs.push_back( name ); // wrap the PipelineHandler so the response gets unpacked properly UnpackXAttrStatus *h = new UnpackXAttrStatus( handler ); uint16_t timeout = pipelineTimeout < this->timeout ? pipelineTimeout : this->timeout; XRootDStatus st = this->file->DelXAttr( attrs, h, timeout ); if( !st.IsOK() ) delete h; return st; } }; //---------------------------------------------------------------------------- //! Factory for creating DelXAttrImpl objects (as there is another DelXAttr in //! FileSystem there would be a clash of typenames). //---------------------------------------------------------------------------- inline DelXAttrImpl DelXAttr( Ctx file, Arg name ) { return DelXAttrImpl( std::move( file ), std::move( name ) ); } //---------------------------------------------------------------------------- //! DelXAttr bulk operation (@see FileOperation) //---------------------------------------------------------------------------- template class DelXAttrBulkImpl: public FileOperation>, Arg>> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileOperation (@see FileOperation) //------------------------------------------------------------------------ using FileOperation>, Arg>>::FileOperation; //------------------------------------------------------------------------ //! Argument indexes in the args tuple //------------------------------------------------------------------------ enum { NamesArg }; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "DelXAttrBulkImpl"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout ) { std::vector &attrs = std::get( this->args ).Get(); uint16_t timeout = pipelineTimeout < this->timeout ? pipelineTimeout : this->timeout; return this->file->DelXAttr( attrs, handler, timeout ); } }; //---------------------------------------------------------------------------- //! Factory for creating DelXAttrBulkImpl objects (as there is another DelXAttr //! in FileSystem there would be a clash of typenames). //---------------------------------------------------------------------------- inline DelXAttrBulkImpl DelXAttr( Ctx file, Arg> attrs ) { return DelXAttrBulkImpl( std::move( file ), std::move( attrs ) ); } //---------------------------------------------------------------------------- //! ListXAttr bulk operation (@see FileOperation) //---------------------------------------------------------------------------- template class ListXAttrImpl: public FileOperation>> { public: //------------------------------------------------------------------------ //! Inherit constructors from FileOperation (@see FileOperation) //------------------------------------------------------------------------ using FileOperation>>::FileOperation; //------------------------------------------------------------------------ //! @return : name of the operation (@see Operation) //------------------------------------------------------------------------ std::string ToString() { return "ListXAttrImpl"; } protected: //------------------------------------------------------------------------ //! RunImpl operation (@see Operation) //! //! @param params : container with parameters forwarded from //! previous operation //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout ) { uint16_t timeout = pipelineTimeout < this->timeout ? pipelineTimeout : this->timeout; return this->file->ListXAttr( handler, timeout ); } }; //---------------------------------------------------------------------------- //! Factory for creating ListXAttrImpl objects (as there is another ListXAttr //! in FileSystem there would be a clash of typenames). //---------------------------------------------------------------------------- inline ListXAttrImpl ListXAttr( Ctx file ) { return ListXAttrImpl( std::move( file ) ); } } #endif // __XRD_CL_FILE_OPERATIONS_HH__