From 7f509fea01f6d69027fc3ddf74976e50fe39b413 Mon Sep 17 00:00:00 2001 From: Michal Simon Date: Wed, 12 Sep 2018 16:38:49 +0200 Subject: [PATCH] [XrdCl] pipelines : update comments. --- src/XrdCl/XrdClFileOperations.hh | 624 ++++++++++++++++-- src/XrdCl/XrdClFileSystemOperations.hh | 859 +++++++++++++++++++++++-- src/XrdCl/XrdClOperationArgs.hh | 347 +++++----- src/XrdCl/XrdClOperationHandlers.hh | 120 ++++ src/XrdCl/XrdClOperations.cc | 76 ++- src/XrdCl/XrdClOperations.hh | 512 +++++++++++---- src/XrdCl/XrdClParallelOperation.hh | 66 +- 7 files changed, 2187 insertions(+), 417 deletions(-) diff --git a/src/XrdCl/XrdClFileOperations.hh b/src/XrdCl/XrdClFileOperations.hh index 63a531b3398..354ee7f9af8 100644 --- a/src/XrdCl/XrdClFileOperations.hh +++ b/src/XrdCl/XrdClFileOperations.hh @@ -33,47 +33,80 @@ namespace XrdCl { + //---------------------------------------------------------------------------- + //! Base class for all file releated operations + //! + //! @arg Derived : the class that derives from this template (CRTP) + //! @arg state : describes current operation configuration state + //! @arg Args : operation arguments + //---------------------------------------------------------------------------- template class Derived, State state, typename ... Arguments> class FileOperation: public ConcreteOperation { template class, State, typename ...> friend class FileOperation; - public: - //------------------------------------------------------------------ + public: + //------------------------------------------------------------------------ //! Constructor //! - //! @param f file on which operation will be performed - //------------------------------------------------------------------ + //! @param f : file on which the operation will be performed + //------------------------------------------------------------------------ FileOperation(File *f): file(f) { static_assert(state == Bare, "Constructor is available only for type Operation"); } + //------------------------------------------------------------------------ + //! 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: + } + + protected: + //------------------------------------------------------------------------ + //! The file object itself + //------------------------------------------------------------------------ File *file; }; + //---------------------------------------------------------------------------- + //! Open operation (@see FileOperation) + //---------------------------------------------------------------------------- template class OpenImpl: public FileOperation, Arg, Arg> { public: + + //------------------------------------------------------------------------ + //! Constructor (@see FileOperation) + //------------------------------------------------------------------------ OpenImpl( File *f ) : FileOperation, Arg, Arg>( f ) { } + + //------------------------------------------------------------------------ + //! Constructor (@see FileOperation) + //------------------------------------------------------------------------ OpenImpl( File &f ) : FileOperation, Arg, Arg>( &f ) @@ -81,6 +114,13 @@ namespace XrdCl } + //------------------------------------------------------------------------ + //! Move constructor from other states + //! + //! @arg from : state from which the object is being converted + //! + //! @param op : the object that is being converted + //------------------------------------------------------------------------ template OpenImpl( OpenImpl && open ) : FileOperation, @@ -89,6 +129,9 @@ namespace XrdCl } + //------------------------------------------------------------------------ + //! URL Argument Descriptors + //------------------------------------------------------------------------ struct UrlArg { static const int index = 0; @@ -96,6 +139,9 @@ namespace XrdCl typedef std::string type; }; + //------------------------------------------------------------------------ + //! Flags Argument Descriptors + //------------------------------------------------------------------------ struct FlagsArg { static const int index = 1; @@ -103,6 +149,9 @@ namespace XrdCl typedef OpenFlags::Flags type; }; + //------------------------------------------------------------------------ + //! Mode Argument Descriptors + //------------------------------------------------------------------------ struct ModeArg { static const int index = 2; @@ -110,6 +159,9 @@ namespace XrdCl typedef Access::Mode type; }; + //------------------------------------------------------------------------ + //! Overloaded operator() (in order to provide default value for mode) + //------------------------------------------------------------------------ OpenImpl operator()( Arg url, Arg flags, Arg mode = Access::None ) { @@ -118,9 +170,17 @@ namespace XrdCl std::move( url ), std::move( flags ), std::move( mode ) ); } + //------------------------------------------------------------------------ + //! make visible the >> inherited from ConcreteOperation + //------------------------------------------------------------------------ using ConcreteOperation, Arg, Arg>::operator>>; + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ OpenImpl operator>>( std::function handleFunction ) { @@ -129,6 +189,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ OpenImpl operator>>( std::function handleFunction ) { @@ -137,6 +202,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ OpenImpl operator>>( std::function handleFunction ) { @@ -145,6 +215,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ OpenImpl operator>>( std::function handleFunction ) { @@ -153,12 +228,23 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! @return : name of the operation (@see Operation) + //------------------------------------------------------------------------ std::string ToString() { return "Open"; } protected: + + //------------------------------------------------------------------------ + //! Run operation (@see Operation) + //! + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation + //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr ¶ms, int bucket = 1 ) { try @@ -175,27 +261,44 @@ namespace XrdCl } }; typedef OpenImpl Open; - template const std::string OpenImpl::UrlArg::key = "url"; - template const std::string OpenImpl::FlagsArg::key = - "flags"; - template const std::string OpenImpl::ModeArg::key = "mode"; + template const std::string OpenImpl::UrlArg::key = "url"; + template const std::string OpenImpl::FlagsArg::key = "flags"; + template const std::string OpenImpl::ModeArg::key = "mode"; + //---------------------------------------------------------------------------- + //! Read operation (@see FileOperation) + //---------------------------------------------------------------------------- template class ReadImpl: public FileOperation, Arg, Arg> { public: + + //------------------------------------------------------------------------ + //! Constructor (@see FileOperation) + //------------------------------------------------------------------------ ReadImpl( File *f ) : FileOperation, Arg, Arg>( f ) { } + + //------------------------------------------------------------------------ + //! Constructor (@see FileOperation) + //------------------------------------------------------------------------ ReadImpl( File &f ) : FileOperation, Arg, Arg>( &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 ReadImpl( ReadImpl && read ) : FileOperation, Arg, @@ -224,9 +327,17 @@ namespace XrdCl typedef void* type; }; + //------------------------------------------------------------------------ + //! make visible the >> inherited from ConcreteOperation + //------------------------------------------------------------------------ using ConcreteOperation, Arg, Arg>::operator>>; + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ ReadImpl operator>>( std::function handleFunction ) { @@ -235,6 +346,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ ReadImpl operator>>( std::function handleFunction ) { @@ -243,6 +359,9 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! @return : name of the operation (@see Operation) + //------------------------------------------------------------------------ std::string ToString() { return "Read"; @@ -250,6 +369,13 @@ namespace XrdCl protected: + //------------------------------------------------------------------------ + //! Run operation (@see Operation) + //! + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation + //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr ¶ms, int bucket = 1 ) { try @@ -266,28 +392,43 @@ namespace XrdCl } }; typedef ReadImpl Read; - template const std::string ReadImpl::OffsetArg::key = - "offset"; - template const std::string ReadImpl::SizeArg::key = "size"; - template const std::string ReadImpl::BufferArg::key = - "buffer"; + template const std::string ReadImpl::OffsetArg::key = "offset"; + template const std::string ReadImpl::SizeArg::key = "size"; + template const std::string ReadImpl::BufferArg::key = "buffer"; + //---------------------------------------------------------------------------- + //! Close operation (@see FileOperation) + //---------------------------------------------------------------------------- template class CloseImpl: public FileOperation { public: + + //------------------------------------------------------------------------ + //! Constructor (@see FileOperation) + //------------------------------------------------------------------------ CloseImpl( File *f ) : FileOperation( f ) { } + //------------------------------------------------------------------------ + //! Constructor (@see FileOperation) + //------------------------------------------------------------------------ CloseImpl( File &f ) : FileOperation( &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 CloseImpl( CloseImpl && close ) : FileOperation( std::move( close ) ) @@ -295,8 +436,16 @@ namespace XrdCl } + //------------------------------------------------------------------------ + //! make visible the >> inherited from ConcreteOperation + //------------------------------------------------------------------------ using ConcreteOperation::operator>>; + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ CloseImpl operator>>( std::function handleFunction ) { @@ -305,6 +454,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ CloseImpl operator>>( std::function handleFunction ) { @@ -313,12 +467,23 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! @return : name of the operation (@see Operation) + //------------------------------------------------------------------------ std::string ToString() { return "Close"; } protected: + + //------------------------------------------------------------------------ + //! Run operation (@see Operation) + //! + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation + //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr ¶ms, int bucket = 1 ) { return this->file->Close( this->handler.get() ); @@ -326,19 +491,37 @@ namespace XrdCl }; typedef CloseImpl Close; + //---------------------------------------------------------------------------- + //! Stat operation (@see FileOperation) + //---------------------------------------------------------------------------- template class StatImpl: public FileOperation> { public: + + //------------------------------------------------------------------------ + //! Constructor (@see FileOperation) + //------------------------------------------------------------------------ StatImpl( File *f ) : FileOperation>( f ) { } + + //------------------------------------------------------------------------ + //! Constructor (@see FileOperation) + //------------------------------------------------------------------------ StatImpl( File &f ) : FileOperation>( &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 StatImpl( StatImpl && stat ) : FileOperation>( std::move( stat ) ) @@ -353,8 +536,16 @@ namespace XrdCl typedef bool type; }; + //------------------------------------------------------------------------ + //! make visible the >> inherited from ConcreteOperation + //------------------------------------------------------------------------ using ConcreteOperation>::operator>>; + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ StatImpl operator>>( std::function handleFunction ) { @@ -363,6 +554,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ StatImpl operator>>( std::function handleFunction ) { @@ -371,12 +567,23 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! @return : name of the operation (@see Operation) + //------------------------------------------------------------------------ std::string ToString() { return "Stat"; } protected: + + //------------------------------------------------------------------------ + //! Run operation (@see Operation) + //! + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation + //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr ¶ms, int bucket = 1 ) { try @@ -390,35 +597,60 @@ namespace XrdCl } } }; - template const std::string StatImpl::ForceArg::key = - "force"; + template const std::string StatImpl::ForceArg::key = "force"; + //---------------------------------------------------------------------------- + //! Factory for creating StatImpl objects (as there is another Stat in + //! FileSystem there would be a clash of typenames). + //---------------------------------------------------------------------------- StatImpl Stat( File *file ) { return StatImpl( file ); } + //---------------------------------------------------------------------------- + //! Factory for creating StatImpl objects (as there is another Stat in + //! FileSystem there would be a clash of typenames). + //---------------------------------------------------------------------------- StatImpl Stat( File &file ) { return StatImpl( file ); } + //---------------------------------------------------------------------------- + //! Write operation (@see FileOperation) + //---------------------------------------------------------------------------- template class WriteImpl: public FileOperation, Arg, Arg> { public: + + //------------------------------------------------------------------------ + //! Constructor (@see FileOperation) + //------------------------------------------------------------------------ WriteImpl( File *f ) : FileOperation, Arg, Arg>( f ) { } + + //------------------------------------------------------------------------ + //! Constructor (@see FileOperation) + //------------------------------------------------------------------------ WriteImpl( File &f ) : FileOperation, Arg, Arg>( &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 WriteImpl( WriteImpl && write ) : FileOperation, Arg, @@ -447,9 +679,17 @@ namespace XrdCl typedef void* type; }; + //------------------------------------------------------------------------ + //! make visible the >> inherited from ConcreteOperation + //------------------------------------------------------------------------ using ConcreteOperation, Arg, Arg>::operator>>; + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ WriteImpl operator>>( std::function handleFunction ) { @@ -458,6 +698,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ WriteImpl operator>>( std::function handleFunction ) { @@ -466,12 +711,23 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! @return : name of the operation (@see Operation) + //------------------------------------------------------------------------ std::string ToString() { return "Write"; } protected: + + //------------------------------------------------------------------------ + //! Run operation (@see Operation) + //! + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation + //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr ¶ms, int bucket = 1 ) { try @@ -488,34 +744,57 @@ namespace XrdCl } }; typedef WriteImpl Write; - template const std::string WriteImpl::OffsetArg::key = - "offset"; - template const std::string WriteImpl::SizeArg::key = - "size"; - template const std::string WriteImpl::BufferArg::key = - "buffer"; + template const std::string WriteImpl::OffsetArg::key = "offset"; + template const std::string WriteImpl::SizeArg::key = "size"; + template const std::string WriteImpl::BufferArg::key = "buffer"; + //---------------------------------------------------------------------------- + //! Sync operation (@see FileOperation) + //---------------------------------------------------------------------------- template class SyncImpl: public FileOperation { public: + + //------------------------------------------------------------------------ + //! Constructor (@see FileOperation) + //------------------------------------------------------------------------ SyncImpl( File *f ) : FileOperation( f ) { } + + //------------------------------------------------------------------------ + //! Constructor (@see FileOperation) + //------------------------------------------------------------------------ SyncImpl( File &f ) : FileOperation( &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 SyncImpl( SyncImpl && sync ) : FileOperation( std::move( sync ) ) { } + //------------------------------------------------------------------------ + //! make visible the >> inherited from ConcreteOperation + //------------------------------------------------------------------------ using ConcreteOperation::operator>>; + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ SyncImpl operator>>( std::function handleFunction ) { @@ -524,6 +803,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ SyncImpl operator>>( std::function handleFunction ) { @@ -532,12 +816,23 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! @return : name of the operation (@see Operation) + //------------------------------------------------------------------------ std::string ToString() { return "Sync"; } protected: + + //------------------------------------------------------------------------ + //! Run operation (@see Operation) + //! + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation + //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr ¶ms, int bucket = 1 ) { return this->file->Sync( this->handler.get() ); @@ -545,19 +840,37 @@ namespace XrdCl }; typedef SyncImpl Sync; + //---------------------------------------------------------------------------- + //! Truncate operation (@see FileOperation) + //---------------------------------------------------------------------------- template class TruncateImpl: public FileOperation> { public: + + //------------------------------------------------------------------------ + //! Constructor (@see FileOperation) + //------------------------------------------------------------------------ TruncateImpl( File *f ) : FileOperation>( f ) { } + + //------------------------------------------------------------------------ + //! Constructor (@see FileOperation) + //------------------------------------------------------------------------ TruncateImpl( File &f ) : FileOperation>( &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 TruncateImpl( TruncateImpl && trunc ) : FileOperation>( @@ -572,8 +885,16 @@ namespace XrdCl typedef uint64_t type; }; + //------------------------------------------------------------------------ + //! make visible the >> inherited from ConcreteOperation + //------------------------------------------------------------------------ using ConcreteOperation>::operator>>; + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ TruncateImpl operator>>( std::function handleFunction ) { @@ -582,6 +903,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ TruncateImpl operator>>( std::function handleFunction ) { @@ -590,12 +916,23 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! @return : name of the operation (@see Operation) + //------------------------------------------------------------------------ std::string ToString() { return "Truncate"; } protected: + + //------------------------------------------------------------------------ + //! Run operation (@see Operation) + //! + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation + //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr ¶ms, int bucket = 1 ) { try @@ -609,33 +946,58 @@ namespace XrdCl } } }; - template const std::string TruncateImpl::SizeArg::key = - "size"; + template const std::string TruncateImpl::SizeArg::key = "size"; + //---------------------------------------------------------------------------- + //! Factory for creating TruncateImpl objects (as there is another Stat in + //! FileSystem there would be a clash of typenames). + //---------------------------------------------------------------------------- TruncateImpl Truncate( File *file ) { return TruncateImpl( file ); } + //---------------------------------------------------------------------------- + //! Factory for creating TruncateImpl objects (as there is another Stat in + //! FileSystem there would be a clash of typenames). + //---------------------------------------------------------------------------- TruncateImpl Truncate( File &file ) { return TruncateImpl( file ); } + //---------------------------------------------------------------------------- + //! VectorRead operation (@see FileOperation) + //---------------------------------------------------------------------------- template class VectorReadImpl: public FileOperation, Arg> { public: + + //------------------------------------------------------------------------ + //! Constructor (@see FileOperation) + //------------------------------------------------------------------------ VectorReadImpl( File *f ) : FileOperation, Arg>( f ) { } + + //------------------------------------------------------------------------ + //! Constructor (@see FileOperation) + //------------------------------------------------------------------------ VectorReadImpl( File &f ) : FileOperation, Arg>( &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 VectorReadImpl( VectorReadImpl && vread ) : FileOperation, Arg>( @@ -657,8 +1019,16 @@ namespace XrdCl typedef char* type; }; + //------------------------------------------------------------------------ + //! make visible the >> inherited from ConcreteOperation + //------------------------------------------------------------------------ using ConcreteOperation, Arg>::operator>>; + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ VectorReadImpl operator>>( std::function handleFunction ) { @@ -667,6 +1037,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ VectorReadImpl operator>>( std::function handleFunction ) { @@ -675,12 +1050,23 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! @return : name of the operation (@see Operation) + //------------------------------------------------------------------------ std::string ToString() { return "VectorRead"; } protected: + + //------------------------------------------------------------------------ + //! Run operation (@see Operation) + //! + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation + //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr ¶ms, int bucket = 1 ) { try @@ -697,25 +1083,41 @@ namespace XrdCl } }; typedef VectorReadImpl VectorRead; - template const std::string VectorReadImpl::ChunksArg::key = - "chunks"; - template const std::string VectorReadImpl::BufferArg::key = - "buffer"; + template const std::string VectorReadImpl::ChunksArg::key = "chunks"; + template const std::string VectorReadImpl::BufferArg::key = "buffer"; + //---------------------------------------------------------------------------- + //! VectorWrite operation (@see FileOperation) + //---------------------------------------------------------------------------- template class VectorWriteImpl: public FileOperation> { public: + + //------------------------------------------------------------------------ + //! Constructor (@see FileOperation) + //------------------------------------------------------------------------ VectorWriteImpl( File *f ) : FileOperation>( f ) { } + + //------------------------------------------------------------------------ + //! Constructor (@see FileOperation) + //------------------------------------------------------------------------ VectorWriteImpl( File &f ) : FileOperation>( &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 VectorWriteImpl( VectorWriteImpl && vwrite ) : FileOperation>( @@ -730,8 +1132,16 @@ namespace XrdCl typedef ChunkList type; }; + //------------------------------------------------------------------------ + //! make visible the >> inherited from ConcreteOperation + //------------------------------------------------------------------------ using ConcreteOperation>::operator>>; + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ VectorWriteImpl operator>>( std::function handleFunction ) { @@ -740,6 +1150,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ VectorWriteImpl operator>>( std::function handleFunction ) { @@ -748,12 +1163,23 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! @return : name of the operation (@see Operation) + //------------------------------------------------------------------------ std::string ToString() { return "VectorWrite"; } protected: + + //------------------------------------------------------------------------ + //! Run operation (@see Operation) + //! + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation + //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr ¶ms, int bucket = 1 ) { try @@ -769,25 +1195,42 @@ namespace XrdCl } }; typedef VectorWriteImpl VectorWrite; - template const std::string VectorWriteImpl::ChunksArg::key = - "chunks"; + template const std::string VectorWriteImpl::ChunksArg::key = "chunks"; + //---------------------------------------------------------------------------- + //! WriteV operation (@see FileOperation) + //---------------------------------------------------------------------------- template class WriteVImpl: public FileOperation, Arg, Arg> { public: + + //------------------------------------------------------------------------ + //! Constructor (@see FileOperation) + //------------------------------------------------------------------------ WriteVImpl( File *f ) : FileOperation, Arg, Arg>( f ) { } + + //------------------------------------------------------------------------ + //! Constructor (@see FileOperation) + //------------------------------------------------------------------------ WriteVImpl( File &f ) : FileOperation, Arg, Arg>( &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 WriteVImpl( WriteVImpl && writev ) : FileOperation, Arg, @@ -816,9 +1259,17 @@ namespace XrdCl typedef int type; }; + //------------------------------------------------------------------------ + //! make visible the >> inherited from ConcreteOperation + //------------------------------------------------------------------------ using ConcreteOperation, Arg, Arg>::operator>>; + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ WriteVImpl operator>>( std::function handleFunction ) { @@ -827,6 +1278,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ WriteVImpl operator>>( std::function handleFunction ) { @@ -835,12 +1291,23 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! @return : name of the operation (@see Operation) + //------------------------------------------------------------------------ std::string ToString() { return "WriteV"; } protected: + + //------------------------------------------------------------------------ + //! Run operation (@see Operation) + //! + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation + //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr ¶ms, int bucket = 1 ) { try @@ -858,25 +1325,41 @@ namespace XrdCl } }; typedef WriteVImpl WriteV; - template const std::string WriteVImpl::OffsetArg::key = - "offset"; - template const std::string WriteVImpl::IovArg::key = "iov"; - template const std::string WriteVImpl::IovcntArg::key = - "iovcnt"; + template const std::string WriteVImpl::OffsetArg::key = "offset"; + template const std::string WriteVImpl::IovArg::key = "iov"; + template const std::string WriteVImpl::IovcntArg::key = "iovcnt"; + //---------------------------------------------------------------------------- + //! Fcntl operation (@see FileOperation) + //---------------------------------------------------------------------------- template class FcntlImpl: public FileOperation> { public: + + //------------------------------------------------------------------------ + //! Constructor (@see FileOperation) + //------------------------------------------------------------------------ FcntlImpl( File *f ) : FileOperation>( f ) { } + + //------------------------------------------------------------------------ + //! Constructor (@see FileOperation) + //------------------------------------------------------------------------ FcntlImpl( File &f ) : FileOperation>( &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 FcntlImpl( FcntlImpl && fcntl ) : FileOperation>( std::move( fcntl ) ) @@ -890,8 +1373,16 @@ namespace XrdCl typedef Buffer type; }; + //------------------------------------------------------------------------ + //! make visible the >> inherited from ConcreteOperation + //------------------------------------------------------------------------ using ConcreteOperation>::operator>>; + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ FcntlImpl operator>>( std::function handleFunction ) { @@ -900,6 +1391,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ FcntlImpl operator>>( std::function handleFunction ) { @@ -908,12 +1404,23 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! @return : name of the operation (@see Operation) + //------------------------------------------------------------------------ std::string ToString() { return "Fcntl"; } protected: + + //------------------------------------------------------------------------ + //! Run operation (@see Operation) + //! + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation + //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr ¶ms, int bucket = 1 ) { try @@ -928,30 +1435,55 @@ namespace XrdCl } }; typedef FcntlImpl Fcntl; - template const std::string FcntlImpl::BufferArg::key = - "arg"; + template const std::string FcntlImpl::BufferArg::key = "arg"; + //---------------------------------------------------------------------------- + //! Visa operation (@see FileOperation) + //---------------------------------------------------------------------------- template class VisaImpl: public FileOperation { public: + + //------------------------------------------------------------------------ + //! Constructor (@see FileOperation) + //------------------------------------------------------------------------ VisaImpl( File *f ) : FileOperation( f ) { } + + //------------------------------------------------------------------------ + //! Constructor (@see FileOperation) + //------------------------------------------------------------------------ VisaImpl( File &f ) : FileOperation( &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 VisaImpl( VisaImpl && visa ) : FileOperation( std::move( visa ) ) { } + //------------------------------------------------------------------------ + //! make visible the >> inherited from ConcreteOperation + //------------------------------------------------------------------------ using ConcreteOperation::operator>>; + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ VisaImpl operator>>( std::function handleFunction ) { @@ -960,6 +1492,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ VisaImpl operator>>( std::function handleFunction ) { @@ -968,12 +1505,23 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! @return : name of the operation (@see Operation) + //------------------------------------------------------------------------ std::string ToString() { return "Visa"; } protected: + + //------------------------------------------------------------------------ + //! Run operation (@see Operation) + //! + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation + //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr ¶ms, int bucket = 1 ) { return this->file->Visa( this->handler.get() ); diff --git a/src/XrdCl/XrdClFileSystemOperations.hh b/src/XrdCl/XrdClFileSystemOperations.hh index 1f1ee6f2fbd..a48cd1e9bc4 100644 --- a/src/XrdCl/XrdClFileSystemOperations.hh +++ b/src/XrdCl/XrdClFileSystemOperations.hh @@ -33,52 +33,93 @@ namespace XrdCl { + //---------------------------------------------------------------------------- + //! Base class for all file system releated operations + //! + //! @arg Derived : the class that derives from this template (CRTP) + //! @arg state : describes current operation configuration state + //! @arg Args : operation arguments + //---------------------------------------------------------------------------- template class Derived, State state, typename ... Args> class FileSystemOperation: public ConcreteOperation { template class, State, typename ...> friend class FileSystemOperation; - public: - //------------------------------------------------------------------ + public: + //------------------------------------------------------------------------ //! Constructor //! - //! @param fs filesystem object on which operation will be performed - //! @param h operation handler - //------------------------------------------------------------------ + //! @param fs : file system on which the operation will be performed + //------------------------------------------------------------------------ explicit FileSystemOperation(FileSystem *fs): filesystem(fs) { static_assert(state == Bare, "Constructor is available only for type Operation"); } + //------------------------------------------------------------------------ + //! Move constructor from other states + //! + //! @arg from : state from which the object is being converted + //! + //! @param op : the object that is being converted + //------------------------------------------------------------------------ template FileSystemOperation( FileSystemOperation && op ): ConcreteOperation( std::move( op ) ), filesystem( op.filesystem ) - {} + { + } + + //------------------------------------------------------------------------ + //! Destructor + //------------------------------------------------------------------------ virtual ~FileSystemOperation() - {} + { + + } - protected: + protected: + //------------------------------------------------------------------------ + //! The file system object itself. + //------------------------------------------------------------------------ FileSystem *filesystem; - }; + }; + //---------------------------------------------------------------------------- + //! Locate operation (@see FileSystemOperation) + //---------------------------------------------------------------------------- template class LocateImpl: public FileSystemOperation, Arg> { public: + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ LocateImpl( FileSystem *fs ) : FileSystemOperation, Arg>( fs ) { } + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ LocateImpl( FileSystem &fs ) : FileSystemOperation, Arg>( &fs ) { } + //------------------------------------------------------------------------ + //! Move constructor from other states + //! + //! @arg from : state from which the object is being converted + //! + //! @param op : the object that is being converted + //------------------------------------------------------------------------ template LocateImpl( LocateImpl && locate ) : FileSystemOperation, @@ -86,6 +127,9 @@ namespace XrdCl { } + //------------------------------------------------------------------------ + //! Path Argument Descriptors + //------------------------------------------------------------------------ struct PathArg { static const int index = 0; @@ -93,6 +137,9 @@ namespace XrdCl typedef std::string type; }; + //------------------------------------------------------------------------ + //! Flags Argument Descriptors + //------------------------------------------------------------------------ struct FlagsArg { static const int index = 1; @@ -100,9 +147,17 @@ namespace XrdCl typedef OpenFlags::Flags type; }; + //------------------------------------------------------------------------ + //! make visible the >> inherited from ConcreteOperation + //------------------------------------------------------------------------ using ConcreteOperation, Arg>::operator>>; + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ LocateImpl operator>>( std::function handleFunction ) { @@ -111,6 +166,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ LocateImpl operator>>( std::function handleFunction ) { @@ -119,12 +179,23 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! @return : name of the operation (@see Operation) + //------------------------------------------------------------------------ std::string ToString() { return "Locate"; } protected: + + //------------------------------------------------------------------------ + //! Run operation (@see Operation) + //! + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation + //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr ¶ms, int bucket = 1 ) { try @@ -140,27 +211,43 @@ namespace XrdCl } }; typedef LocateImpl Locate; - template const std::string LocateImpl::PathArg::key = - "path"; - template const std::string LocateImpl::FlagsArg::key = - "flags"; + template const std::string LocateImpl::PathArg::key = "path"; + template const std::string LocateImpl::FlagsArg::key = "flags"; + //---------------------------------------------------------------------------- + //! DeepLocate operation (@see FileSystemOperation) + //---------------------------------------------------------------------------- template class DeepLocateImpl: public FileSystemOperation, Arg> { public: + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ DeepLocateImpl( FileSystem *fs ) : FileSystemOperation, Arg>( fs ) { } + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ DeepLocateImpl( FileSystem &fs ) : FileSystemOperation, Arg>( &fs ) { } + //------------------------------------------------------------------------ + //! Move constructor from other states + //! + //! @arg from : state from which the object is being converted + //! + //! @param op : the object that is being converted + //------------------------------------------------------------------------ template DeepLocateImpl( DeepLocateImpl && locate ) : FileSystemOperation, @@ -168,6 +255,9 @@ namespace XrdCl { } + //------------------------------------------------------------------------ + //! Path Argument Descriptors + //------------------------------------------------------------------------ struct PathArg { static const int index = 0; @@ -175,6 +265,9 @@ namespace XrdCl typedef std::string type; }; + //------------------------------------------------------------------------ + //! Flags Argument Descriptors + //------------------------------------------------------------------------ struct FlagsArg { static const int index = 1; @@ -182,9 +275,17 @@ namespace XrdCl typedef OpenFlags::Flags type; }; + //------------------------------------------------------------------------ + //! make visible the >> inherited from ConcreteOperation + //------------------------------------------------------------------------ using ConcreteOperation, Arg>::operator>>; + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ DeepLocateImpl operator>>( std::function handleFunction ) { @@ -193,6 +294,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ DeepLocateImpl operator>>( std::function handleFunction ) { @@ -201,12 +307,23 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! @return : name of the operation (@see Operation) + //------------------------------------------------------------------------ std::string ToString() { return "DeepLocate"; } protected: + + //------------------------------------------------------------------------ + //! Run operation (@see Operation) + //! + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation + //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr ¶ms, int bucket = 1 ) { try @@ -223,27 +340,43 @@ namespace XrdCl } }; typedef DeepLocateImpl DeepLocate; - template const std::string DeepLocateImpl::PathArg::key = - "path"; - template const std::string DeepLocateImpl::FlagsArg::key = - "flags"; + template const std::string DeepLocateImpl::PathArg::key = "path"; + template const std::string DeepLocateImpl::FlagsArg::key = "flags"; + //---------------------------------------------------------------------------- + //! Mv operation (@see FileSystemOperation) + //---------------------------------------------------------------------------- template class MvImpl: public FileSystemOperation, Arg> { public: + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ MvImpl( FileSystem *fs ) : FileSystemOperation, Arg>( fs ) { } + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ MvImpl( FileSystem &fs ) : FileSystemOperation, Arg>( &fs ) { } + //------------------------------------------------------------------------ + //! Move constructor from other states + //! + //! @arg from : state from which the object is being converted + //! + //! @param op : the object that is being converted + //------------------------------------------------------------------------ template MvImpl( MvImpl && mv ) : FileSystemOperation, Arg>( @@ -251,6 +384,9 @@ namespace XrdCl { } + //------------------------------------------------------------------------ + //! Source Argument Descriptors + //------------------------------------------------------------------------ struct SourceArg { static const int index = 0; @@ -258,6 +394,9 @@ namespace XrdCl typedef std::string type; }; + //------------------------------------------------------------------------ + //! Dest Argument Descriptors + //------------------------------------------------------------------------ struct DestArg { static const int index = 1; @@ -265,8 +404,16 @@ namespace XrdCl typedef std::string type; }; + //------------------------------------------------------------------------ + //! make visible the >> inherited from ConcreteOperation + //------------------------------------------------------------------------ using ConcreteOperation, Arg>::operator>>; + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ MvImpl operator>>( std::function handleFunction ) { @@ -275,6 +422,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ MvImpl operator>>( std::function handleFunction ) { @@ -283,12 +435,23 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! @return : name of the operation (@see Operation) + //------------------------------------------------------------------------ std::string ToString() { return "Mv"; } protected: + + //------------------------------------------------------------------------ + //! Run operation (@see Operation) + //! + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation + //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr ¶ms, int bucket = 1 ) { try @@ -304,26 +467,43 @@ namespace XrdCl } }; typedef MvImpl Mv; - template const std::string MvImpl::SourceArg::key = - "source"; - template const std::string MvImpl::DestArg::key = "dest"; + template const std::string MvImpl::SourceArg::key = "source"; + template const std::string MvImpl::DestArg::key = "dest"; + //---------------------------------------------------------------------------- + //! Query operation (@see FileSystemOperation) + //---------------------------------------------------------------------------- template class QueryImpl: public FileSystemOperation, Arg> { public: + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ QueryImpl( FileSystem *fs ) : FileSystemOperation, Arg>( fs ) { } + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ QueryImpl( FileSystem &fs ) : FileSystemOperation, Arg>( &fs ) { } + //------------------------------------------------------------------------ + //! Move constructor from other states + //! + //! @arg from : state from which the object is being converted + //! + //! @param op : the object that is being converted + //------------------------------------------------------------------------ template QueryImpl( QueryImpl && query ) : FileSystemOperation, @@ -331,6 +511,9 @@ namespace XrdCl { } + //------------------------------------------------------------------------ + //! QueryCode Argument Descriptors + //------------------------------------------------------------------------ struct QueryCodeArg { static const int index = 0; @@ -338,6 +521,9 @@ namespace XrdCl typedef QueryCode::Code type; }; + //------------------------------------------------------------------------ + //! Buffer Argument Descriptors + //------------------------------------------------------------------------ struct BufferArg { static const int index = 1; @@ -345,9 +531,17 @@ namespace XrdCl typedef Buffer type; }; + //------------------------------------------------------------------------ + //! make visible the >> inherited from ConcreteOperation + //------------------------------------------------------------------------ using ConcreteOperation, Arg>::operator>>; + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ QueryImpl operator>>( std::function handleFunction ) { @@ -356,6 +550,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ QueryImpl operator>>( std::function handleFunction ) { @@ -364,12 +563,23 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! @return : name of the operation (@see Operation) + //------------------------------------------------------------------------ std::string ToString() { return "Query"; } protected: + + //------------------------------------------------------------------------ + //! Run operation (@see Operation) + //! + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation + //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr ¶ms, int bucket = 1 ) { try @@ -386,27 +596,43 @@ namespace XrdCl } }; typedef QueryImpl Query; - template const std::string QueryImpl::QueryCodeArg::key = - "queryCode"; - template const std::string QueryImpl::BufferArg::key = - "arg"; + template const std::string QueryImpl::QueryCodeArg::key = "queryCode"; + template const std::string QueryImpl::BufferArg::key = "arg"; + //---------------------------------------------------------------------------- + //! Truncate operation (@see FileSystemOperation) + //---------------------------------------------------------------------------- template class TruncateFsImpl: public FileSystemOperation, Arg> { public: + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ TruncateFsImpl( FileSystem *fs ) : FileSystemOperation, Arg>( fs ) { } + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ TruncateFsImpl( FileSystem &fs ) : FileSystemOperation, Arg>( &fs ) { } + //------------------------------------------------------------------------ + //! Move constructor from other states + //! + //! @arg from : state from which the object is being converted + //! + //! @param op : the object that is being converted + //------------------------------------------------------------------------ template TruncateFsImpl( TruncateFsImpl && trunc ) : FileSystemOperation, @@ -414,6 +640,9 @@ namespace XrdCl { } + //------------------------------------------------------------------------ + //! Path Argument Descriptors + //------------------------------------------------------------------------ struct PathArg { static const int index = 0; @@ -421,6 +650,9 @@ namespace XrdCl typedef std::string type; }; + //------------------------------------------------------------------------ + //! Size Argument Descriptors + //------------------------------------------------------------------------ struct SizeArg { static const int index = 1; @@ -428,9 +660,17 @@ namespace XrdCl typedef uint64_t type; }; + //------------------------------------------------------------------------ + //! make visible the >> inherited from ConcreteOperation + //------------------------------------------------------------------------ using ConcreteOperation, Arg>::operator>>; + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ TruncateFsImpl operator>>( std::function handleFunction ) { @@ -439,6 +679,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ TruncateFsImpl operator>>( std::function handleFunction ) { @@ -447,12 +692,23 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! @return : name of the operation (@see Operation) + //------------------------------------------------------------------------ std::string ToString() { return "Truncate"; } protected: + + //------------------------------------------------------------------------ + //! Run operation (@see Operation) + //! + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation + //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr ¶ms, int bucket = 1 ) { try @@ -467,10 +723,8 @@ namespace XrdCl } } }; - template const std::string TruncateFsImpl::PathArg::key = - "path"; - template const std::string TruncateFsImpl::SizeArg::key = - "size"; + template const std::string TruncateFsImpl::PathArg::key = "path"; + template const std::string TruncateFsImpl::SizeArg::key = "size"; TruncateFsImpl Truncate( FileSystem *fs ) { @@ -482,19 +736,37 @@ namespace XrdCl return TruncateFsImpl( fs ); } + //---------------------------------------------------------------------------- + //! Rm operation (@see FileSystemOperation) + //---------------------------------------------------------------------------- template class RmImpl: public FileSystemOperation> { public: + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ RmImpl( FileSystem *fs ) : FileSystemOperation>( fs ) { } + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ RmImpl( FileSystem &fs ) : FileSystemOperation>( &fs ) { } + //------------------------------------------------------------------------ + //! Move constructor from other states + //! + //! @arg from : state from which the object is being converted + //! + //! @param op : the object that is being converted + //------------------------------------------------------------------------ template RmImpl( RmImpl && rm ) : FileSystemOperation>( @@ -502,6 +774,9 @@ namespace XrdCl { } + //------------------------------------------------------------------------ + //! Path Argument Descriptors + //------------------------------------------------------------------------ struct PathArg { static const int index = 0; @@ -509,8 +784,16 @@ namespace XrdCl typedef std::string type; }; + //------------------------------------------------------------------------ + //! make visible the >> inherited from ConcreteOperation + //------------------------------------------------------------------------ using ConcreteOperation>::operator>>; + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ RmImpl operator>>( std::function handleFunction ) { @@ -519,6 +802,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ RmImpl operator>>( std::function handleFunction ) { @@ -527,12 +815,23 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! @return : name of the operation (@see Operation) + //------------------------------------------------------------------------ std::string ToString() { return "Rm"; } protected: + + //------------------------------------------------------------------------ + //! Run operation (@see Operation) + //! + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation + //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr ¶ms, int bucket = 1 ) { try @@ -549,22 +848,40 @@ namespace XrdCl typedef RmImpl Rm; template const std::string RmImpl::PathArg::key = "path"; + //---------------------------------------------------------------------------- + //! MkDir operation (@see FileSystemOperation) + //---------------------------------------------------------------------------- template class MkDirImpl: public FileSystemOperation, Arg, Arg> { public: + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ MkDirImpl( FileSystem *fs ) : FileSystemOperation, Arg, Arg>( fs ) { } + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ MkDirImpl( FileSystem &fs ) : FileSystemOperation, Arg, Arg>( &fs ) { } + //------------------------------------------------------------------------ + //! Move constructor from other states + //! + //! @arg from : state from which the object is being converted + //! + //! @param op : the object that is being converted + //------------------------------------------------------------------------ template MkDirImpl( MkDirImpl && mkdir ) : FileSystemOperation, @@ -572,6 +889,9 @@ namespace XrdCl { } + //------------------------------------------------------------------------ + //! Path Argument Descriptors + //------------------------------------------------------------------------ struct PathArg { static const int index = 0; @@ -579,6 +899,9 @@ namespace XrdCl typedef std::string type; }; + //------------------------------------------------------------------------ + //! Flags Argument Descriptors + //------------------------------------------------------------------------ struct FlagsArg { static const int index = 1; @@ -586,6 +909,9 @@ namespace XrdCl typedef MkDirFlags::Flags type; }; + //------------------------------------------------------------------------ + //! Mode Argument Descriptors + //------------------------------------------------------------------------ struct ModeArg { static const int index = 2; @@ -593,9 +919,17 @@ namespace XrdCl typedef Access::Mode type; }; + //------------------------------------------------------------------------ + //! make visible the >> inherited from ConcreteOperation + //------------------------------------------------------------------------ using ConcreteOperation, Arg, Arg>::operator>>; + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ MkDirImpl operator>>( std::function handleFunction ) { @@ -604,6 +938,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ MkDirImpl operator>>( std::function handleFunction ) { @@ -612,12 +951,23 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! @return : name of the operation (@see Operation) + //------------------------------------------------------------------------ std::string ToString() { return "MkDir"; } protected: + + //------------------------------------------------------------------------ + //! Run operation (@see Operation) + //! + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation + //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr ¶ms, int bucket = 1 ) { try @@ -636,26 +986,41 @@ namespace XrdCl } }; typedef MkDirImpl MkDir; - template const std::string MkDirImpl::PathArg::key = - "path"; - template const std::string MkDirImpl::FlagsArg::key = - "flags"; - template const std::string MkDirImpl::ModeArg::key = - "mode"; + template const std::string MkDirImpl::PathArg::key = "path"; + template const std::string MkDirImpl::FlagsArg::key = "flags"; + template const std::string MkDirImpl::ModeArg::key = "mode"; + //---------------------------------------------------------------------------- + //! RmDir operation (@see FileSystemOperation) + //---------------------------------------------------------------------------- template class RmDirImpl: public FileSystemOperation> { public: + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ RmDirImpl( FileSystem *fs ) : FileSystemOperation>( fs ) { } + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ RmDirImpl( FileSystem &fs ) : FileSystemOperation>( &fs ) { } + //------------------------------------------------------------------------ + //! Move constructor from other states + //! + //! @arg from : state from which the object is being converted + //! + //! @param op : the object that is being converted + //------------------------------------------------------------------------ template RmDirImpl( RmDirImpl && rmdir ) : FileSystemOperation>( @@ -663,6 +1028,9 @@ namespace XrdCl { } + //------------------------------------------------------------------------ + //! Path Argument Descriptors + //------------------------------------------------------------------------ struct PathArg { static const int index = 0; @@ -670,8 +1038,16 @@ namespace XrdCl typedef std::string type; }; + //------------------------------------------------------------------------ + //! make visible the >> inherited from ConcreteOperation + //------------------------------------------------------------------------ using ConcreteOperation>::operator>>; + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ RmDirImpl operator>>( std::function handleFunction ) { @@ -680,6 +1056,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ RmDirImpl operator>>( std::function handleFunction ) { @@ -688,12 +1069,23 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! @return : name of the operation (@see Operation) + //------------------------------------------------------------------------ std::string ToString() { return "RmDir"; } protected: + + //------------------------------------------------------------------------ + //! Run operation (@see Operation) + //! + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation + //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr ¶ms, int bucket = 1 ) { try @@ -708,25 +1100,42 @@ namespace XrdCl } }; typedef RmDirImpl RmDir; - template const std::string RmDirImpl::PathArg::key = - "path"; + template const std::string RmDirImpl::PathArg::key = "path"; + //---------------------------------------------------------------------------- + //! ChMod operation (@see FileSystemOperation) + //---------------------------------------------------------------------------- template class ChModImpl: public FileSystemOperation, Arg> { public: + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ ChModImpl( FileSystem *fs ) : FileSystemOperation, Arg>( fs ) { } + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ ChModImpl( FileSystem &fs ) : FileSystemOperation, Arg>( &fs ) { } + //------------------------------------------------------------------------ + //! Move constructor from other states + //! + //! @arg from : state from which the object is being converted + //! + //! @param op : the object that is being converted + //------------------------------------------------------------------------ template ChModImpl( ChModImpl && chmod ) : FileSystemOperation, @@ -734,6 +1143,9 @@ namespace XrdCl { } + //------------------------------------------------------------------------ + //! Path Argument Descriptors + //------------------------------------------------------------------------ struct PathArg { static const int index = 0; @@ -741,6 +1153,9 @@ namespace XrdCl typedef std::string type; }; + //------------------------------------------------------------------------ + //! Mode Argument Descriptors + //------------------------------------------------------------------------ struct ModeArg { static const int index = 1; @@ -748,9 +1163,17 @@ namespace XrdCl typedef Access::Mode type; }; + //------------------------------------------------------------------------ + //! make visible the >> inherited from ConcreteOperation + //------------------------------------------------------------------------ using ConcreteOperation, Arg>::operator>>; + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ ChModImpl operator>>( std::function handleFunction ) { @@ -759,6 +1182,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ ChModImpl operator>>( std::function handleFunction ) { @@ -767,12 +1195,23 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! @return : name of the operation (@see Operation) + //------------------------------------------------------------------------ std::string ToString() { return "ChMod"; } protected: + + //------------------------------------------------------------------------ + //! Run operation (@see Operation) + //! + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation + //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr ¶ms, int bucket = 1 ) { try @@ -788,32 +1227,56 @@ namespace XrdCl } }; typedef ChModImpl ChMod; - template const std::string ChModImpl::PathArg::key = - "path"; - template const std::string ChModImpl::ModeArg::key = - "mode"; + template const std::string ChModImpl::PathArg::key = "path"; + template const std::string ChModImpl::ModeArg::key = "mode"; + //---------------------------------------------------------------------------- + //! Ping operation (@see FileSystemOperation) + //---------------------------------------------------------------------------- template class PingImpl: public FileSystemOperation { public: + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ PingImpl( FileSystem *fs ) : FileSystemOperation( fs ) { } + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ PingImpl( FileSystem &fs ) : FileSystemOperation( &fs ) { } + //------------------------------------------------------------------------ + //! Move constructor from other states + //! + //! @arg from : state from which the object is being converted + //! + //! @param op : the object that is being converted + //------------------------------------------------------------------------ template PingImpl( PingImpl && ping ) : FileSystemOperation( std::move( ping ) ) { } + //------------------------------------------------------------------------ + //! make visible the >> inherited from ConcreteOperation + //------------------------------------------------------------------------ using ConcreteOperation::operator>>; + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ PingImpl operator>>( std::function handleFunction ) { @@ -822,6 +1285,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ PingImpl operator>>( std::function handleFunction ) { @@ -830,12 +1298,23 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! @return : name of the operation (@see Operation) + //------------------------------------------------------------------------ std::string ToString() { return "Ping"; } protected: + + //------------------------------------------------------------------------ + //! Run operation (@see Operation) + //! + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation + //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr ¶ms, int bucket = 1 ) { try @@ -850,20 +1329,38 @@ namespace XrdCl }; typedef PingImpl Ping; + //---------------------------------------------------------------------------- + //! Stat operation (@see FileSystemOperation) + //---------------------------------------------------------------------------- template class StatFsImpl: public FileSystemOperation> { public: + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ StatFsImpl( FileSystem *fs ) : FileSystemOperation>( fs ) { } + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ StatFsImpl( FileSystem &fs ) : FileSystemOperation>( &fs ) { } + //------------------------------------------------------------------------ + //! Move constructor from other states + //! + //! @arg from : state from which the object is being converted + //! + //! @param op : the object that is being converted + //------------------------------------------------------------------------ template StatFsImpl( StatFsImpl && statfs ) : FileSystemOperation>( @@ -871,6 +1368,9 @@ namespace XrdCl { } + //------------------------------------------------------------------------ + //! Path Argument Descriptors + //------------------------------------------------------------------------ struct PathArg { static const int index = 0; @@ -878,8 +1378,16 @@ namespace XrdCl typedef std::string type; }; + //------------------------------------------------------------------------ + //! make visible the >> inherited from ConcreteOperation + //------------------------------------------------------------------------ using ConcreteOperation>::operator>>; + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ StatFsImpl operator>>( std::function handleFunction ) { @@ -888,6 +1396,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ StatFsImpl operator>>( std::function handleFunction ) { @@ -896,12 +1409,23 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! @return : name of the operation (@see Operation) + //------------------------------------------------------------------------ std::string ToString() { return "Stat"; } protected: + + //------------------------------------------------------------------------ + //! Run operation (@see Operation) + //! + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation + //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr ¶ms, int bucket = 1 ) { try @@ -915,8 +1439,7 @@ namespace XrdCl } } }; - template const std::string StatFsImpl::PathArg::key = - "path"; + template const std::string StatFsImpl::PathArg::key = "path"; StatFsImpl Stat( FileSystem *fs ) { @@ -928,20 +1451,38 @@ namespace XrdCl return StatFsImpl( fs ); } + //---------------------------------------------------------------------------- + //! StatVS operation (@see FileSystemOperation) + //---------------------------------------------------------------------------- template class StatVFSImpl: public FileSystemOperation> { public: + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ StatVFSImpl( FileSystem *fs ) : FileSystemOperation>( fs ) { } + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ StatVFSImpl( FileSystem &fs ) : FileSystemOperation>( &fs ) { } + //------------------------------------------------------------------------ + //! Move constructor from other states + //! + //! @arg from : state from which the object is being converted + //! + //! @param op : the object that is being converted + //------------------------------------------------------------------------ template StatVFSImpl( StatVFSImpl && statvfs ) : FileSystemOperation>( @@ -949,6 +1490,9 @@ namespace XrdCl { } + //------------------------------------------------------------------------ + //! Path Argument Descriptors + //------------------------------------------------------------------------ struct PathArg { static const int index = 0; @@ -956,8 +1500,16 @@ namespace XrdCl typedef std::string type; }; + //------------------------------------------------------------------------ + //! make visible the >> inherited from ConcreteOperation + //------------------------------------------------------------------------ using ConcreteOperation>::operator>>; + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ StatVFSImpl operator>>( std::function handleFunction ) { @@ -966,6 +1518,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ StatVFSImpl operator>>( std::function handleFunction ) { @@ -974,12 +1531,23 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! @return : name of the operation (@see Operation) + //------------------------------------------------------------------------ std::string ToString() { return "StatVFS"; } protected: + + //------------------------------------------------------------------------ + //! Run operation (@see Operation) + //! + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation + //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr ¶ms, int bucket = 1 ) { try @@ -994,30 +1562,55 @@ namespace XrdCl } }; typedef StatVFSImpl StatVFS; - template const std::string StatVFSImpl::PathArg::key = - "path"; + template const std::string StatVFSImpl::PathArg::key = "path"; + //---------------------------------------------------------------------------- + //! Protocol operation (@see FileSystemOperation) + //---------------------------------------------------------------------------- template class ProtocolImpl: public FileSystemOperation { public: + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ ProtocolImpl( FileSystem *fs ) : FileSystemOperation( fs ) { } + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ ProtocolImpl( FileSystem &fs ) : FileSystemOperation( &fs ) { } + //------------------------------------------------------------------------ + //! Move constructor from other states + //! + //! @arg from : state from which the object is being converted + //! + //! @param op : the object that is being converted + //------------------------------------------------------------------------ template ProtocolImpl( ProtocolImpl && prot ) : FileSystemOperation( std::move( prot ) ) { } + //------------------------------------------------------------------------ + //! make visible the >> inherited from ConcreteOperation + //------------------------------------------------------------------------ using ConcreteOperation::operator>>; + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ ProtocolImpl operator>>( std::function handleFunction ) { @@ -1026,6 +1619,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ ProtocolImpl operator>>( std::function handleFunction ) { @@ -1034,12 +1632,23 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! @return : name of the operation (@see Operation) + //------------------------------------------------------------------------ std::string ToString() { return "Protocol"; } protected: + + //------------------------------------------------------------------------ + //! Run operation (@see Operation) + //! + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation + //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr ¶ms, int bucket = 1 ) { try @@ -1054,22 +1663,40 @@ namespace XrdCl }; typedef ProtocolImpl Protocol; + //---------------------------------------------------------------------------- + //! DirList operation (@see FileSystemOperation) + //---------------------------------------------------------------------------- template class DirListImpl: public FileSystemOperation, Arg> { public: + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ DirListImpl( FileSystem *fs ) : FileSystemOperation, Arg>( fs ) { } + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ DirListImpl( FileSystem &fs ) : FileSystemOperation, Arg>( &fs ) { } + //------------------------------------------------------------------------ + //! Move constructor from other states + //! + //! @arg from : state from which the object is being converted + //! + //! @param op : the object that is being converted + //------------------------------------------------------------------------ template DirListImpl( DirListImpl && dirls ) : FileSystemOperation, @@ -1077,6 +1704,9 @@ namespace XrdCl { } + //------------------------------------------------------------------------ + //! Path Argument Descriptors + //------------------------------------------------------------------------ struct PathArg { static const int index = 0; @@ -1084,6 +1714,9 @@ namespace XrdCl typedef std::string type; }; + //------------------------------------------------------------------------ + //! Flags Argument Descriptors + //------------------------------------------------------------------------ struct FlagsArg { static const int index = 1; @@ -1091,9 +1724,17 @@ namespace XrdCl typedef DirListFlags::Flags type; }; + //------------------------------------------------------------------------ + //! make visible the >> inherited from ConcreteOperation + //------------------------------------------------------------------------ using ConcreteOperation, Arg>::operator>>; + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ DirListImpl operator>>( std::function handleFunction ) { @@ -1102,6 +1743,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ DirListImpl operator>>( std::function handleFunction ) { @@ -1110,12 +1756,23 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! @return : name of the operation (@see Operation) + //------------------------------------------------------------------------ std::string ToString() { return "DirList"; } protected: + + //------------------------------------------------------------------------ + //! Run operation (@see Operation) + //! + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation + //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr ¶ms, int bucket = 1 ) { try @@ -1132,25 +1789,41 @@ namespace XrdCl } }; typedef DirListImpl DirList; - template const std::string DirListImpl::PathArg::key = - "path"; - template const std::string DirListImpl::FlagsArg::key = - "flags"; + template const std::string DirListImpl::PathArg::key = "path"; + template const std::string DirListImpl::FlagsArg::key = "flags"; + //---------------------------------------------------------------------------- + //! SendInfo operation (@see FileSystemOperation) + //---------------------------------------------------------------------------- template class SendInfoImpl: public FileSystemOperation> { public: + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ SendInfoImpl( FileSystem *fs ) : FileSystemOperation>( fs ) { } + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ SendInfoImpl( FileSystem &fs ) : FileSystemOperation>( &fs ) { } + //------------------------------------------------------------------------ + //! Move constructor from other states + //! + //! @arg from : state from which the object is being converted + //! + //! @param op : the object that is being converted + //------------------------------------------------------------------------ template SendInfoImpl( SendInfoImpl && sendinfo ) : FileSystemOperation>( @@ -1158,6 +1831,9 @@ namespace XrdCl { } + //------------------------------------------------------------------------ + //! Info Argument Descriptors + //------------------------------------------------------------------------ struct InfoArg { static const int index = 0; @@ -1165,8 +1841,16 @@ namespace XrdCl typedef std::string type; }; + //------------------------------------------------------------------------ + //! make visible the >> inherited from ConcreteOperation + //------------------------------------------------------------------------ using ConcreteOperation>::operator>>; + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ SendInfoImpl operator>>( std::function handleFunction ) { @@ -1175,6 +1859,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ SendInfoImpl operator>>( std::function handleFunction ) { @@ -1183,12 +1872,23 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! @return : name of the operation (@see Operation) + //------------------------------------------------------------------------ std::string ToString() { return "SendInfo"; } protected: + + //------------------------------------------------------------------------ + //! Run operation (@see Operation) + //! + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation + //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr ¶ms, int bucket = 1 ) { try @@ -1203,25 +1903,42 @@ namespace XrdCl } }; typedef SendInfoImpl SendInfo; - template const std::string SendInfoImpl::InfoArg::key = - "info"; + template const std::string SendInfoImpl::InfoArg::key = "info"; + //---------------------------------------------------------------------------- + //! Prepare operation (@see FileSystemOperation) + //---------------------------------------------------------------------------- template class PrepareImpl: public FileSystemOperation>, Arg, Arg> { public: + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ PrepareImpl( FileSystem *fs ) : FileSystemOperation>, Arg, Arg>( fs ) { } + + //------------------------------------------------------------------------ + //! Constructor (@see FileSystemOperation) + //------------------------------------------------------------------------ PrepareImpl( FileSystem &fs ) : FileSystemOperation>, Arg, Arg>( &fs ) { } + //------------------------------------------------------------------------ + //! Move constructor from other states + //! + //! @arg from : state from which the object is being converted + //! + //! @param op : the object that is being converted + //------------------------------------------------------------------------ template PrepareImpl( PrepareImpl && prep ) : FileSystemOperation>, @@ -1229,6 +1946,9 @@ namespace XrdCl { } + //------------------------------------------------------------------------ + //! FileList Argument Descriptors + //------------------------------------------------------------------------ struct FileListArg { static const int index = 0; @@ -1236,6 +1956,9 @@ namespace XrdCl typedef std::vector type; }; + //------------------------------------------------------------------------ + //! Flags Argument Descriptors + //------------------------------------------------------------------------ struct FlagsArg { static const int index = 1; @@ -1243,6 +1966,9 @@ namespace XrdCl typedef PrepareFlags::Flags type; }; + //------------------------------------------------------------------------ + //! Priority Argument Descriptors + //------------------------------------------------------------------------ struct PriorityArg { static const int index = 2; @@ -1250,9 +1976,17 @@ namespace XrdCl typedef uint8_t type; }; + //------------------------------------------------------------------------ + //! make visible the >> inherited from ConcreteOperation + //------------------------------------------------------------------------ using ConcreteOperation>, Arg, Arg>::operator>>; + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ PrepareImpl operator>>( std::function handleFunction ) { @@ -1261,6 +1995,11 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ PrepareImpl operator>>( std::function handleFunction ) { @@ -1269,12 +2008,23 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } + //------------------------------------------------------------------------ + //! @return : name of the operation (@see Operation) + //------------------------------------------------------------------------ std::string ToString() { return "Prepare"; } protected: + + //------------------------------------------------------------------------ + //! Run operation (@see Operation) + //! + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation + //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr ¶ms, int bucket = 1 ) { try @@ -1294,12 +2044,9 @@ namespace XrdCl } }; typedef PrepareImpl Prepare; - template const std::string PrepareImpl::FileListArg::key = - "fileList"; - template const std::string PrepareImpl::FlagsArg::key = - "flags"; - template const std::string PrepareImpl::PriorityArg::key = - "priority"; + template const std::string PrepareImpl::FileListArg::key = "fileList"; + template const std::string PrepareImpl::FlagsArg::key = "flags"; + template const std::string PrepareImpl::PriorityArg::key = "priority"; } diff --git a/src/XrdCl/XrdClOperationArgs.hh b/src/XrdCl/XrdClOperationArgs.hh index 9f989b3b64a..3005c6db961 100644 --- a/src/XrdCl/XrdClOperationArgs.hh +++ b/src/XrdCl/XrdClOperationArgs.hh @@ -33,35 +33,55 @@ namespace XrdCl { - class NotDefParam + //---------------------------------------------------------------------------- + //! A argument that has not been defined + //---------------------------------------------------------------------------- + class NotDefArg { - } notdef; + } notdef; //> a global for specifying not defined arguments - //-------------------------------------------------------------------- - //! Single value container representing optional value. + //---------------------------------------------------------------------------- + //! Operation argument. + //! The argument is optional, user may initialize it with 'notdef' //! - //! @tparam T type of the value stored - //-------------------------------------------------------------------- + //! @arg T : real type of the argument + //---------------------------------------------------------------------------- template class Arg { public: + + //------------------------------------------------------------------------ + //! Constructor. + //! + //! @param val : value of the argument + //------------------------------------------------------------------------ Arg( T val ) : empty( false ) { value = val; } - Arg() : - empty( true ) + //------------------------------------------------------------------------ + //! Constructor. + //------------------------------------------------------------------------ + Arg() : empty( true ) { } - Arg( NotDefParam notdef ) : + //------------------------------------------------------------------------ + //! Constructor. + //! + //! @param notdef : place holder meaning the argument is not defined yet + //------------------------------------------------------------------------ + Arg( NotDefArg notdef ) : empty( true ) { } + //------------------------------------------------------------------------ + //! Move Constructor. + //------------------------------------------------------------------------ Arg( Arg && opt ) : value( std::move( opt.value ) ) { @@ -69,6 +89,9 @@ namespace XrdCl opt.empty = true; } + //------------------------------------------------------------------------ + //! Move-Assignment. + //------------------------------------------------------------------------ Arg& operator=( Arg &&arg ) { value = std::move( arg.value ); @@ -77,11 +100,18 @@ namespace XrdCl return *this; } + //------------------------------------------------------------------------ + //! @return : true if the argument has not been defined yet, + //! false otherwise + //------------------------------------------------------------------------ bool IsEmpty() { return empty; } + //------------------------------------------------------------------------ + //! @return : value of the argument + //------------------------------------------------------------------------ T& GetValue() { if( IsEmpty() ) @@ -93,41 +123,72 @@ namespace XrdCl } private: + + //------------------------------------------------------------------------ + //! value of the argument + //------------------------------------------------------------------------ T value; + + //------------------------------------------------------------------------ + //! true if the argument has not been defined yet, false otherwise + //------------------------------------------------------------------------ bool empty; }; - //------------------------------------------------------------------ - //! Single value container specialization for std::string type - //! Besides base functionality it contains conversion from - //! const char* type - //------------------------------------------------------------------ + //---------------------------------------------------------------------------- + //! Operation argument. + //! Specialized for 'std::string', migh be constructed in addition from c-like + //! string (const char*) + //! + //! @arg T : real type of the argument + //---------------------------------------------------------------------------- template<> class Arg { public: + + //------------------------------------------------------------------------ + //! Constructor. + //! + //! @param val : value of the argument + //------------------------------------------------------------------------ Arg( const std::string& str ) : empty( false ) { value = str; } + //------------------------------------------------------------------------ + //! Constructor. + //! + //! @param val : value of the argument + //------------------------------------------------------------------------ Arg( const char *val ) : empty( false ) { value = std::string( val ); } - Arg() : - empty( true ) + //------------------------------------------------------------------------ + //! Constructor. + //------------------------------------------------------------------------ + Arg() : empty( true ) { } - Arg( NotDefParam notdef ) : + //------------------------------------------------------------------------ + //! Constructor. + //! + //! @param notdef : place holder meaning the argument is not defined yet + //------------------------------------------------------------------------ + Arg( NotDefArg notdef ) : empty( true ) { } + //------------------------------------------------------------------------ + //! Move Constructor. + //----------------------------------------------------------------------- Arg( Arg &&arg ) : value( std::move( arg.value ) ) { @@ -135,6 +196,9 @@ namespace XrdCl arg.empty = true; } + //------------------------------------------------------------------------ + //! Move-Assignment. + //------------------------------------------------------------------------ Arg& operator=( Arg &&opt ) { value = std::move( opt.value ); @@ -143,11 +207,18 @@ namespace XrdCl return *this; } + //------------------------------------------------------------------------ + //! @return : true if the argument has not been defined yet, + //! false otherwise + //------------------------------------------------------------------------ bool IsEmpty() { return empty; } + //------------------------------------------------------------------------ + //! @return : value of the argument + //------------------------------------------------------------------------ std::string& GetValue() { if( IsEmpty() ) @@ -159,185 +230,82 @@ namespace XrdCl } private: - std::string value; - bool empty; - }; - template<> - class Arg - { - public: - - Arg( Buffer &buf ) : - empty( false ) - { - value = std::move( buf ); - } - - Arg() : - empty( true ) - { - } - - Arg( NotDefParam notdef ) : - empty( true ) - { - } - - Arg( Arg && arg ) : - value( std::move( arg.value ) ) - { - empty = arg.empty; - arg.empty = true; - } - - Arg& operator=( Arg &&opt ) - { - value = std::move( opt.value ); - empty = opt.empty; - opt.empty = true; - return *this; - } - - bool IsEmpty() - { - return empty; - } - - Buffer& GetValue() - { - if( IsEmpty() ) - { - throw std::logic_error( - "Cannot get parameter: value has not been specified" ); - } - return value; - } + //------------------------------------------------------------------------ + //! value of the argument + //------------------------------------------------------------------------ + std::string value; - private: - Buffer value; + //------------------------------------------------------------------------ + //! true if the argument has not been defined yet, false otherwise + //------------------------------------------------------------------------ bool empty; }; - //-------------------------------------------------------------------- - //! Container to store file operation parameters - //! Parameters are stored as key-value pairs and grouped in buckets - //! Normally only bucket 1 is used, more buckets are used only in - //! multiworklfow operations - //-------------------------------------------------------------------- + //---------------------------------------------------------------------------- + //! Container with argument for forwarding + //---------------------------------------------------------------------------- class ArgsContainer { public: - //------------------------------------------------------------ - //! Get value from container + + //------------------------------------------------------------------------ + //! Get an argument from container //! - //! @param key key under which the value is stored - //! @return value - //------------------------------------------------------------ - template - typename T::type& GetArg( int bucket = 1 ) + //! @arg ArgDesc : descryptor of the argument type + //! + //! @param bucket : bucket number of the desired argument + //------------------------------------------------------------------------ + template + typename ArgDesc::type& GetArg( int bucket = 1 ) { - if( !Exists( T::key, bucket ) ) + if( !Exists( ArgDesc::key, bucket ) ) { std::ostringstream oss; - oss << "Parameter " << T::key << " has not been specified in bucket " + oss << "Parameter " << ArgDesc::key << " has not been specified in bucket " << bucket; throw std::logic_error( oss.str() ); } - AnyObject *obj = paramsMap[bucket][T::key]; - typename T::type *valuePtr = nullptr; + AnyObject *obj = paramsMap[bucket][ArgDesc::key]; + typename ArgDesc::type *valuePtr = nullptr; obj->Get( valuePtr ); return *valuePtr; } - //------------------------------------------------------------ - //! Save value in container + //------------------------------------------------------------------------ + //! Set an argument in container //! - //! @param key key under which the value will be saved - //! @param value value to save - //! @param bucket bucket in which key will be added - //------------------------------------------------------------ - template - void SetArg( typename T::type value, int bucket = 1 ) - { - if( !BucketExists( bucket ) ) - { - paramsMap[bucket]; - } - if( paramsMap[bucket].find( T::key ) != paramsMap[bucket].end() ) - { - std::ostringstream oss; - oss << "Parameter " << T::key << " has already been set in bucket " - << bucket; - throw std::logic_error( oss.str() ); - } - typename T::type *valuePtr = new typename T::type( value ); - AnyObject *obj = new AnyObject(); - obj->Set( valuePtr, true ); - paramsMap[bucket][T::key] = obj; - } - - //------------------------------------------------------------ - //! Save pointer in container + //! @arg ArgDesc : descryptor of the argument type //! - //! @param key key under which the pointer will be saved - //! @param value pointer to save - //! @param passOwnership flag indicating whether memory - //! should be released automatically - //! when destroying container - //! @param bucket bucket to which key will be saved - //------------------------------------------------------------ - template - void SetPtrArg( typename T::type value, bool passOwnership, - int bucket = 1 ) + //! @param bucket : bucket number of the desired argument + //------------------------------------------------------------------------ + template + void SetArg( typename ArgDesc::type value, int bucket = 1 ) { if( !BucketExists( bucket ) ) { paramsMap[bucket]; } - if( paramsMap[bucket].find( T::key ) != paramsMap[bucket].end() ) + if( paramsMap[bucket].find( ArgDesc::key ) != paramsMap[bucket].end() ) { std::ostringstream oss; - oss << "Parameter " << T::key << " has already been set in bucket " + oss << "Parameter " << ArgDesc::key << " has already been set in bucket " << bucket; throw std::logic_error( oss.str() ); } + typename ArgDesc::type *valuePtr = new typename ArgDesc::type( value ); AnyObject *obj = new AnyObject(); - obj->Set( value, passOwnership ); - paramsMap[bucket][T::key] = obj; - } - - //------------------------------------------------------------ - //! Check whether given key exists in the container under - //! given bucket - //! - //! @param key key to check - //! @param bucket bucket which will be checked - //! @return true if exists, false if not - //------------------------------------------------------------ - bool Exists( const std::string &key, int bucket = 1 ) - { - return paramsMap.find( bucket ) != paramsMap.end() - && paramsMap[bucket].find( key ) != paramsMap[bucket].end(); - } - - //------------------------------------------------------------------ - //! Check whether given bucket exist in the container - //! - //! @param bucket bucket to check - //! @return true if exists, false if not - //------------------------------------------------------------------ - bool BucketExists( int bucket ) - { - return paramsMap.find( bucket ) != paramsMap.end(); + obj->Set( valuePtr, true ); + paramsMap[bucket][ArgDesc::key] = obj; } + //------------------------------------------------------------------------ + //! Destructor + //------------------------------------------------------------------------ ~ArgsContainer() { auto buckets = paramsMap.begin(); - //---------------------------------------------------------------- // Destroy dynamically allocated objects stored in map - //---------------------------------------------------------------- while( buckets != paramsMap.end() ) { auto& objectsMap = buckets->second; @@ -353,29 +321,78 @@ namespace XrdCl } private: + + //------------------------------------------------------------------------ + //! Check if given key exists in given bucket + //! + //! @param key : key of the argument + //! @param bucket : the bucket we want to check + //! + //! @return : true if the argument exists, false otherwise + //------------------------------------------------------------------------ + bool Exists( const std::string &key, int bucket = 1 ) + { + return paramsMap.find( bucket ) != paramsMap.end() + && paramsMap[bucket].find( key ) != paramsMap[bucket].end(); + } + + //------------------------------------------------------------------------ + //! Check if given bucket exist + //! + //! @param bucket : bucket number + //! + //! @return : true if the bucket exists, false otherwise + //------------------------------------------------------------------------ + bool BucketExists( int bucket ) + { + return paramsMap.find( bucket ) != paramsMap.end(); + } + + //------------------------------------------------------------------------ + //! map of buckets with arguments + //------------------------------------------------------------------------ std::unordered_map> paramsMap; }; - //-------------------------------------------------------------------- - //! Operation context for a lambda function. - //-------------------------------------------------------------------- + //---------------------------------------------------------------------------- + //! Operation Context. + //! + //! Acts as an additional parameter to a lambda so it can forward arguments. + //---------------------------------------------------------------------------- class OperationContext { public: + + //------------------------------------------------------------------------ + //! Constructor + //! + //! @param paramsContainer : container with argument + //------------------------------------------------------------------------ OperationContext( std::shared_ptr paramsContainer ) : container( paramsContainer ) { } - template - void FwdArg( typename T::type value, int bucket = 1 ) + //------------------------------------------------------------------------ + //! Forward argument to next operation in pipeline + //! + //! @arg ArgDesc : descryptor of the argument type + //! + //! @param value : value of the argument + //! @param bucket : the bucket where the argument should be stored + //------------------------------------------------------------------------ + template + void FwdArg( typename ArgDesc::type value, int bucket = 1 ) { - container->SetArg < T > ( value, bucket ); + container->SetArg ( value, bucket ); } private: - std::shared_ptr container; + //------------------------------------------------------------------------ + //! Container with arguments for forwarding + //------------------------------------------------------------------------ + std::shared_ptr container; }; } diff --git a/src/XrdCl/XrdClOperationHandlers.hh b/src/XrdCl/XrdClOperationHandlers.hh index 1e9b58165a9..2eb1897c2b4 100644 --- a/src/XrdCl/XrdClOperationHandlers.hh +++ b/src/XrdCl/XrdClOperationHandlers.hh @@ -31,15 +31,27 @@ namespace XrdCl { + //---------------------------------------------------------------------------- + //! Lambda wrapper + //---------------------------------------------------------------------------- class SimpleFunctionWrapper: public ForwardingHandler { public: + + //------------------------------------------------------------------------ + //! Constructor. + // + //! @param func : function, functor or lambda + //------------------------------------------------------------------------ SimpleFunctionWrapper( std::function handleFunction ) : fun( handleFunction ) { } + //------------------------------------------------------------------------ + //! Callback method. + //------------------------------------------------------------------------ void HandleResponse( XrdCl::XRootDStatus *status, XrdCl::AnyObject *response ) { @@ -50,18 +62,33 @@ namespace XrdCl } private: + //------------------------------------------------------------------------ + //! user defined function, functor or lambda + //------------------------------------------------------------------------ std::function fun; }; + //---------------------------------------------------------------------------- + //! Lambda wrapper + //---------------------------------------------------------------------------- class SimpleForwardingFunctionWrapper: public ForwardingHandler { public: + + //------------------------------------------------------------------------ + //! Constructor. + // + //! @param func : function, functor or lambda + //------------------------------------------------------------------------ SimpleForwardingFunctionWrapper( std::function handleFunction ) : fun( handleFunction ) { } + //------------------------------------------------------------------------ + //! Callback method. + //------------------------------------------------------------------------ void HandleResponse( XrdCl::XRootDStatus *status, XrdCl::AnyObject *response ) { @@ -73,19 +100,36 @@ namespace XrdCl } private: + //------------------------------------------------------------------------ + //! user defined function, functor or lambda + //------------------------------------------------------------------------ std::function fun; }; + //---------------------------------------------------------------------------- + //! Lambda wrapper + //! + //! @arg ResponseType : type of response returned by the server + //---------------------------------------------------------------------------- template class FunctionWrapper: public ForwardingHandler { public: + + //------------------------------------------------------------------------ + //! Constructor. + // + //! @param func : function, functor or lambda + //------------------------------------------------------------------------ FunctionWrapper( std::function handleFunction ) : fun( handleFunction ) { } + //------------------------------------------------------------------------ + //! Callback method. + //------------------------------------------------------------------------ void HandleResponse( XrdCl::XRootDStatus *status, XrdCl::AnyObject *response ) { @@ -101,17 +145,36 @@ namespace XrdCl } private: + //------------------------------------------------------------------------ + //! user defined function, functor or lambda + //------------------------------------------------------------------------ std::function fun; + + //------------------------------------------------------------------------ + //! Null reference to the response (not really but acts as one) + //------------------------------------------------------------------------ static ResponseType nullref; }; + //---------------------------------------------------------------------------- + // Initialize the 'null-reference' + //---------------------------------------------------------------------------- template ResponseType FunctionWrapper::nullref; + //---------------------------------------------------------------------------- + //! Lambda wrapper + //---------------------------------------------------------------------------- template class ForwardingFunctionWrapper: public ForwardingHandler { public: + + //------------------------------------------------------------------------ + //! Constructor. + // + //! @param func : function, functor or lambda + //------------------------------------------------------------------------ ForwardingFunctionWrapper( std::function< void( XrdCl::XRootDStatus&, ResponseType&, OperationContext& )> handleFunction ) : @@ -119,6 +182,9 @@ namespace XrdCl { } + //------------------------------------------------------------------------ + //! Callback method. + //------------------------------------------------------------------------ void HandleResponse( XrdCl::XRootDStatus *status, XrdCl::AnyObject *response ) { @@ -135,23 +201,45 @@ namespace XrdCl } private: + //------------------------------------------------------------------------ + //! user defined function, functor or lambda + //------------------------------------------------------------------------ std::function< void( XrdCl::XRootDStatus&, ResponseType&, OperationContext &wrapper )> fun; + + //------------------------------------------------------------------------ + //! Null reference to the response (not really but acts as one) + //------------------------------------------------------------------------ static ResponseType nullref; }; + //---------------------------------------------------------------------------- + // Initialize the 'null-reference' + //---------------------------------------------------------------------------- template ResponseType ForwardingFunctionWrapper::nullref; + //---------------------------------------------------------------------------- + //! Lambda wrapper + //---------------------------------------------------------------------------- class ExOpenFuncWrapper: public ForwardingHandler { public: + + //------------------------------------------------------------------------ + //! Constructor. + // + //! @param func : function, functor or lambda + //------------------------------------------------------------------------ ExOpenFuncWrapper( File &f, std::function handleFunction ) : f( f ), fun( handleFunction ) { } + //------------------------------------------------------------------------ + //! Callback method. + //------------------------------------------------------------------------ void HandleResponse( XrdCl::XRootDStatus *status, XrdCl::AnyObject *response ) { @@ -169,15 +257,34 @@ namespace XrdCl private: File &f; + //------------------------------------------------------------------------ + //! user defined function, functor or lambda + //------------------------------------------------------------------------ std::function fun; + + //------------------------------------------------------------------------ + //! Null reference to the response (not really but acts as one) + //------------------------------------------------------------------------ static StatInfo nullref; }; + //---------------------------------------------------------------------------- + // Initialize the 'null-reference' + //---------------------------------------------------------------------------- StatInfo ExOpenFuncWrapper::nullref; + //---------------------------------------------------------------------------- + //! Lambda wrapper + //---------------------------------------------------------------------------- class ForwardingExOpenFuncWrapper: public ForwardingHandler { public: + + //------------------------------------------------------------------------ + //! Constructor. + // + //! @param func : function, functor or lambda + //------------------------------------------------------------------------ ForwardingExOpenFuncWrapper( File &f, std::function< void( XrdCl::XRootDStatus&, StatInfo&, OperationContext& )> handleFunction ) : @@ -185,6 +292,9 @@ namespace XrdCl { } + //------------------------------------------------------------------------ + //! Callback method. + //------------------------------------------------------------------------ void HandleResponse( XrdCl::XRootDStatus *status, XrdCl::AnyObject *response ) { @@ -203,10 +313,20 @@ namespace XrdCl private: File &f; + //------------------------------------------------------------------------ + //! user defined function, functor or lambda + //------------------------------------------------------------------------ std::function fun; + + //------------------------------------------------------------------------ + //! Null reference to the response (not really but acts as one) + //------------------------------------------------------------------------ static StatInfo nullref; }; + //---------------------------------------------------------------------------- + // Initialize the 'null-reference' + //---------------------------------------------------------------------------- StatInfo ForwardingExOpenFuncWrapper::nullref; } diff --git a/src/XrdCl/XrdClOperations.cc b/src/XrdCl/XrdClOperations.cc index f171f7a6509..c506dafac1e 100644 --- a/src/XrdCl/XrdClOperations.cc +++ b/src/XrdCl/XrdClOperations.cc @@ -34,16 +34,17 @@ namespace XrdCl { //---------------------------------------------------------------------------- - // OperationHandler + // OperationHandler Constructor. //---------------------------------------------------------------------------- - OperationHandler::OperationHandler( ForwardingHandler *handler, bool own ) : - responseHandler( handler ), ownHandler( own ), nextOperation( nullptr ), workflow( - nullptr ) + responseHandler( handler ), ownHandler( own ), workflow( nullptr ) { params = handler->GetArgContainer(); } + //---------------------------------------------------------------------------- + // OperationHandler::AddOperation + //---------------------------------------------------------------------------- void OperationHandler::AddOperation( Operation *operation ) { if( nextOperation ) @@ -52,10 +53,13 @@ namespace XrdCl } else { - nextOperation = operation; + nextOperation.reset( operation ); } } + //---------------------------------------------------------------------------- + // OperationHandler::HandleResponseImpl + //---------------------------------------------------------------------------- void OperationHandler::HandleResponseImpl( XRootDStatus *status, AnyObject *response, HostList *hostList ) { @@ -72,29 +76,43 @@ namespace XrdCl workflow->EndWorkflowExecution( statusCopy ); } + //---------------------------------------------------------------------------- + // OperationHandler::HandleResponseWithHosts + //---------------------------------------------------------------------------- void OperationHandler::HandleResponseWithHosts( XRootDStatus *status, AnyObject *response, HostList *hostList ) { HandleResponseImpl( status, response, hostList ); } + //---------------------------------------------------------------------------- + // OperationHandler::HandleResponse + //---------------------------------------------------------------------------- void OperationHandler::HandleResponse( XRootDStatus *status, AnyObject *response ) { HandleResponseImpl( status, response ); } + //---------------------------------------------------------------------------- + // OperationHandler::RunNextOperation + //---------------------------------------------------------------------------- XRootDStatus OperationHandler::RunNextOperation() { return nextOperation->Run( params ); } + //---------------------------------------------------------------------------- + // OperationHandler Destructor + //---------------------------------------------------------------------------- OperationHandler::~OperationHandler() { - delete nextOperation; if( ownHandler ) delete responseHandler; } + //---------------------------------------------------------------------------- + // OperationHandler::AssignToWorkflow + //---------------------------------------------------------------------------- void OperationHandler::AssignToWorkflow( Workflow *wf ) { if( workflow ) @@ -108,28 +126,37 @@ namespace XrdCl } } + //---------------------------------------------------------------------------- - // Workflow + // Workflow Constructor. //---------------------------------------------------------------------------- - Workflow::Workflow( Operation &op, bool enableLogging ) : firstOperation( op.Move() ), status( nullptr ), logging( enableLogging ) { firstOperation->AssignToWorkflow( this ); } + //---------------------------------------------------------------------------- + // Workflow Constructor. + //---------------------------------------------------------------------------- Workflow::Workflow( Operation &&op, bool enableLogging ) : firstOperation( op.Move() ), status( nullptr ), logging( enableLogging ) { firstOperation->AssignToWorkflow( this ); } + //---------------------------------------------------------------------------- + // Workflow Constructor. + //---------------------------------------------------------------------------- Workflow::Workflow( Operation *op, bool enableLogging ) : firstOperation( op->Move() ), status( nullptr ), logging( enableLogging ) { firstOperation->AssignToWorkflow( this ); } + //---------------------------------------------------------------------------- + // Workflow Constructor. + //---------------------------------------------------------------------------- Workflow::Workflow( Operation &op, bool enableLogging ) : status( nullptr ), logging( enableLogging ) { @@ -137,6 +164,9 @@ namespace XrdCl firstOperation->AssignToWorkflow( this ); } + //---------------------------------------------------------------------------- + // Workflow Constructor. + //---------------------------------------------------------------------------- Workflow::Workflow( Operation &&op, bool enableLogging ) : status( nullptr ), logging( enableLogging ) { @@ -144,6 +174,9 @@ namespace XrdCl firstOperation->AssignToWorkflow( this ); } + //---------------------------------------------------------------------------- + // Workflow Constructor. + //---------------------------------------------------------------------------- Workflow::Workflow( Operation *op, bool enableLogging ) : status( nullptr ), logging( enableLogging ) { @@ -151,6 +184,9 @@ namespace XrdCl firstOperation->AssignToWorkflow( this ); } + //---------------------------------------------------------------------------- + // Workflow Constructor. + //---------------------------------------------------------------------------- Workflow::Workflow( Pipeline &&pipeline, bool enableLogging ) : status( nullptr ), logging( enableLogging ) { @@ -159,12 +195,18 @@ namespace XrdCl firstOperation = pipeline.operation.release(); } + //---------------------------------------------------------------------------- + // Workflow Destructor. + //---------------------------------------------------------------------------- Workflow::~Workflow() { delete firstOperation; delete status; } + //---------------------------------------------------------------------------- + // Workflow::Run + //---------------------------------------------------------------------------- XRootDStatus Workflow::Run( std::shared_ptr params, int bucket ) { @@ -184,6 +226,9 @@ namespace XrdCl return firstOperation->Run( firstOperationParams ); } + //---------------------------------------------------------------------------- + // Workflow::EndWorkflowExecution + //---------------------------------------------------------------------------- void Workflow::EndWorkflowExecution( const XRootDStatus &lastOperationStatus ) { if( semaphore ) @@ -193,11 +238,17 @@ namespace XrdCl } } + //---------------------------------------------------------------------------- + // Workflow::GetStatus + //---------------------------------------------------------------------------- XRootDStatus Workflow::GetStatus() { return status ? *status : XRootDStatus(); } + //---------------------------------------------------------------------------- + // Workflow::Wait + //---------------------------------------------------------------------------- void Workflow::Wait() { if( semaphore ) @@ -206,11 +257,17 @@ namespace XrdCl } } + //---------------------------------------------------------------------------- + // Workflow::AddOperationInfo + //---------------------------------------------------------------------------- void Workflow::AddOperationInfo( std::string description ) { operationDescriptions.push_back( description ); } + //---------------------------------------------------------------------------- + // Workflow::ToString + //---------------------------------------------------------------------------- std::string Workflow::ToString() { std::ostringstream oss; @@ -227,6 +284,9 @@ namespace XrdCl return oss.str(); } + //---------------------------------------------------------------------------- + // Workflow::Print + //---------------------------------------------------------------------------- void Workflow::Print() { std::ostringstream oss; diff --git a/src/XrdCl/XrdClOperations.hh b/src/XrdCl/XrdClOperations.hh index e1be41f7ce3..9f00dc98bb6 100644 --- a/src/XrdCl/XrdClOperations.hh +++ b/src/XrdCl/XrdClOperations.hh @@ -30,8 +30,9 @@ #include #include #include -#include "XrdCl/XrdClFile.hh" +#include "XrdCl/XrdClXRootDResponses.hh" #include "XrdCl/XrdClOperationArgs.hh" +#include "XrdSys/XrdSysPthread.hh" namespace XrdCl { @@ -45,19 +46,26 @@ namespace XrdCl class Pipeline; - //--------------------------------------------------------------------------- - //! Handler allowing forwarding parameters to the next operation in workflow - //--------------------------------------------------------------------------- + //---------------------------------------------------------------------------- + //! Handler allowing forwarding parameters to the next operation in pipeline + //---------------------------------------------------------------------------- class ForwardingHandler: public ResponseHandler { friend class OperationHandler; public: + + //------------------------------------------------------------------------ + //! Constructor. + //------------------------------------------------------------------------ ForwardingHandler() : - container( new ArgsContainer() ), responseHandler( nullptr ) + container( new ArgsContainer() ) { } + //------------------------------------------------------------------------ + //! Callback function. + //------------------------------------------------------------------------ virtual void HandleResponseWithHosts( XRootDStatus *status, AnyObject *response, HostList *hostList ) { @@ -65,6 +73,9 @@ namespace XrdCl HandleResponse( status, response ); } + //------------------------------------------------------------------------ + //! Callback function. + //------------------------------------------------------------------------ virtual void HandleResponse( XRootDStatus *status, AnyObject *response ) { delete status; @@ -72,14 +83,14 @@ namespace XrdCl delete this; } - //------------------------------------------------------------------ - //! Saves value in param container so that in can be used in - //! next operation + //------------------------------------------------------------------------ + //! Forward an argument to next operation in pipeline + //! + //! @arg T : type of the value which will be saved //! - //! @tparam T type of the value which will be saved - //! @param value value to save - //! @param bucket bucket in which value will be saved - //------------------------------------------------------------------ + //! @param value : value to save + //! @param bucket : bucket in which value will be saved + //------------------------------------------------------------------------ template void FwdArg( typename T::type value, int bucket = 1 ) { @@ -87,35 +98,56 @@ namespace XrdCl } private: + + //------------------------------------------------------------------------ + //! @return : container with arguments for forwarding + //------------------------------------------------------------------------ std::shared_ptr& GetArgContainer() { return container; } + //------------------------------------------------------------------------ + //! container with arguments for forwarding + //------------------------------------------------------------------------ std::shared_ptr container; protected: + + //------------------------------------------------------------------------ + //! @return : operation context + //------------------------------------------------------------------------ std::unique_ptr GetOperationContext() { return std::unique_ptr( new OperationContext( container ) ); } - - ResponseHandler* responseHandler; }; + //---------------------------------------------------------------------------- + //! Handler allowing wrapping a normal ResponseHandler into + //! a ForwaridngHandler. + //---------------------------------------------------------------------------- class WrappingHandler: public ForwardingHandler { friend class OperationHandler; public: + //------------------------------------------------------------------------ + //! Constructor. + //! + //! @param handler : the handler to be wrapped up + //------------------------------------------------------------------------ WrappingHandler( ResponseHandler *handler ) : handler( handler ) { } + //------------------------------------------------------------------------ + //! Callback function. + //------------------------------------------------------------------------ void HandleResponseWithHosts( XRootDStatus *status, AnyObject *response, HostList *hostList ) { @@ -123,6 +155,9 @@ namespace XrdCl delete this; } + //------------------------------------------------------------------------ + //! Callback function. + //------------------------------------------------------------------------ void HandleResponse( XRootDStatus *status, AnyObject *response ) { handler->HandleResponse( status, response ); @@ -131,12 +166,15 @@ namespace XrdCl private: + //------------------------------------------------------------------------ + //! The wrapped handler + //------------------------------------------------------------------------ ResponseHandler *handler; }; - //--------------------------------------------------------------------------- - //! File operations workflow - //--------------------------------------------------------------------------- + //---------------------------------------------------------------------------- + //! An operations workflow + //---------------------------------------------------------------------------- class Workflow { friend class OperationHandler; @@ -145,35 +183,45 @@ namespace XrdCl //------------------------------------------------------------------------ //! Constructor //! - //! @param op first operation of the sequence + //! @param op : first operation of the sequence + //! @param enableLogging : true if logging should be enabled, + //! false otherwise //------------------------------------------------------------------------ explicit Workflow( Operation& op, bool enableLogging = true ); //------------------------------------------------------------------------ //! Constructor //! - //! @param op first operation of the sequence + //! @param op : first operation of the sequence + //! @param enableLogging : true if logging should be enabled, + //! false otherwise //------------------------------------------------------------------------ explicit Workflow( Operation && op, bool enableLogging = true ); //------------------------------------------------------------------------ //! Constructor //! - //! @param op first operation of the sequence + //! @param op : first operation of the sequence + //! @param enableLogging : true if logging should be enabled, + //! false otherwise //------------------------------------------------------------------------ explicit Workflow( Operation* op, bool enableLogging = true ); //------------------------------------------------------------------------ //! Constructor //! - //! @param op first operation of the sequence + //! @param op : first operation of the sequence + //! @param enableLogging : true if logging should be enabled, + //! false otherwise //------------------------------------------------------------------------ explicit Workflow( Operation& op, bool enableLogging = true ); //------------------------------------------------------------------------ //! Constructor //! - //! @param op first operation of the sequence + //! @param op : first operation of the sequence + //! @param enableLogging : true if logging should be enabled, + //! false otherwise //------------------------------------------------------------------------ explicit Workflow( Operation && op, bool enableLogging = true ); @@ -181,95 +229,140 @@ namespace XrdCl //------------------------------------------------------------------------ //! Constructor //! - //! @param op first operation of the sequence + //! @param op : first operation of the sequence + //! @param enableLogging : true if logging should be enabled, + //! false otherwise //------------------------------------------------------------------------ explicit Workflow( Operation* op, bool enableLogging = true ); //------------------------------------------------------------------------ //! Constructor //! - //! @param a pipeline object + //! @param pipeline : a pipeline object + //! @param enableLogging : true if logging should be enabled, + //! false otherwise //------------------------------------------------------------------------ Workflow( Pipeline &&pipeline, bool enableLogging = true ); + //------------------------------------------------------------------------ + //! Destructor + //------------------------------------------------------------------------ ~Workflow(); //------------------------------------------------------------------------ - //! Run first workflow operation + //! Start the pipeline + //! + //! @return : status of the operation //! - //! @return original workflow object //! @throws logic_error if the workflow is already running //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr params = nullptr, int bucket = 1 ); //------------------------------------------------------------------------ - //! Wait for workflow execution end - //! - //! @return original workflow object + //! Wait for the pipeline execution to end //------------------------------------------------------------------------ void Wait(); //------------------------------------------------------------------------ //! Get workflow execution status //! - //! @return workflow execution status if available, otherwise default - //! XRootDStatus object + //! @return : workflow execution status //------------------------------------------------------------------------ XRootDStatus GetStatus(); - //------------------------------------------------------------------ + //----------------------------------------------------------------------- //! Get workflow description //! - //! @return description of the workflow - //------------------------------------------------------------------ + //! @return : description of the workflow + //----------------------------------------------------------------------- std::string ToString(); - //------------------------------------------------------------------ + //----------------------------------------------------------------------- //! Add operation description to the descriptions list //! - //! @param description description of assigned operation - //------------------------------------------------------------------ + //! @param description : description of assigned operation + //----------------------------------------------------------------------- void AddOperationInfo( std::string description ); - //------------------------------------------------------------------ + //----------------------------------------------------------------------- //! Log operation descriptions - //------------------------------------------------------------------ + //----------------------------------------------------------------------- void Print(); private: //------------------------------------------------------------------------ //! Release the semaphore and save status //! - //! @param lastOperationStatus status of last executed operation. - //! It is set as status of workflow execution. + //! @param lastOperationStatus : status of last executed operation, + //! it is set as status of workflow execution //------------------------------------------------------------------------ void EndWorkflowExecution( const XRootDStatus &lastOperationStatus ); + //------------------------------------------------------------------------ + //! first operation in the pipeline + //------------------------------------------------------------------------ Operation *firstOperation; + + //------------------------------------------------------------------------ + //! Synchronization semaphore, will be released once the pipeline + //! execution came to an end + //------------------------------------------------------------------------ std::unique_ptr semaphore; + + //------------------------------------------------------------------------ + //! Status of the workflow + //------------------------------------------------------------------------ XRootDStatus *status; + + //------------------------------------------------------------------------ + //! Description of the workflow + //------------------------------------------------------------------------ std::list operationDescriptions; + + //------------------------------------------------------------------------ + //! true if logging is enabled, false otherwise + //------------------------------------------------------------------------ bool logging; }; - //--------------------------------------------------------------------------- + //---------------------------------------------------------------------------- //! Wrapper for ForwardingHandler, used only internally to run next operation //! after previous one is finished - //--------------------------------------------------------------------------- + //---------------------------------------------------------------------------- class OperationHandler: public ResponseHandler { public: + + //------------------------------------------------------------------------ + //! Constructor. + //! + //! @param handler : the forwarding handler of our operation + //! @param own : if true we have the ownership of handler (it's + //! memory), and it is our responsibility to deallocate it + //------------------------------------------------------------------------ OperationHandler( ForwardingHandler *handler, bool own ); + + //------------------------------------------------------------------------ + //! Callback function. + //------------------------------------------------------------------------ void HandleResponseWithHosts( XRootDStatus *status, AnyObject *response, HostList *hostList ); + + //------------------------------------------------------------------------ + //! Callback function. + //------------------------------------------------------------------------ void HandleResponse( XRootDStatus *status, AnyObject *response ); + + //------------------------------------------------------------------------ + //! Destructor. + //------------------------------------------------------------------------ ~OperationHandler(); //------------------------------------------------------------------------ - //! Add new operation to the sequence + //! Add new operation to the pipeline //! - //! @param operation operation to add + //! @param operation : operation to add //------------------------------------------------------------------------ void AddOperation( Operation *operation ); @@ -290,21 +383,48 @@ namespace XrdCl private: + //------------------------------------------------------------------------ + //! Callback function implementation; + //------------------------------------------------------------------------ void HandleResponseImpl( XRootDStatus *status, AnyObject *response, HostList *hostList = nullptr ); + //------------------------------------------------------------------------ + //! The forwarding handler of our operation + //------------------------------------------------------------------------ ForwardingHandler *responseHandler; + + //------------------------------------------------------------------------ + //! true, if we own the handler + //------------------------------------------------------------------------ bool ownHandler; - Operation *nextOperation; + + //------------------------------------------------------------------------ + //! Next operation in the pipeline + //------------------------------------------------------------------------ + std::unique_ptr> nextOperation; + + //------------------------------------------------------------------------ + //! Workflow object. + //------------------------------------------------------------------------ Workflow *workflow; + + //------------------------------------------------------------------------ + //! Arguments for forwarding + //------------------------------------------------------------------------ std::shared_ptr params; }; - //---------------------------------------------------------------------- - //! Operation template + //---------------------------------------------------------------------------- + //! Operation template. An Operation is a once-use-only object - once executed + //! by a Workflow engine it is invalidated. Also if used as an argument for + //! >> or | the original object gets invalidated. //! - //! @tparam state describes current operation configuration state - //---------------------------------------------------------------------- + //! @arg state : describes current operation state: + //! - Bare : a bare operation + //! - Configured : operation with its arguments + //! - Handled : operation with its arguments and handler + //---------------------------------------------------------------------------- template class Operation { @@ -315,15 +435,18 @@ namespace XrdCl friend class OperationHandler; public: - //------------------------------------------------------------------ + + //------------------------------------------------------------------------ //! Constructor - //------------------------------------------------------------------ - Operation() : - handler( nullptr ) + //------------------------------------------------------------------------ + Operation() { } + //------------------------------------------------------------------------ + //! Move constructor between template instances. + //------------------------------------------------------------------------ template Operation( Operation && op ) : handler( std::move( op.handler ) ) @@ -331,23 +454,40 @@ namespace XrdCl } + //------------------------------------------------------------------------ + //! Destructor + //------------------------------------------------------------------------ virtual ~Operation() { } + //------------------------------------------------------------------------ + //! Move current object into newly allocated instance + //! + //! @return : the new instance + //------------------------------------------------------------------------ virtual Operation* Move() = 0; + //------------------------------------------------------------------------ + //! Move current object into newly allocated instance, and convert + //! it into 'Handled' state. + //! + //! @return : the new instance + //------------------------------------------------------------------------ virtual Operation* ToHandled() = 0; + //------------------------------------------------------------------------ + //! Name of the operation. + //------------------------------------------------------------------------ virtual std::string ToString() = 0; protected: - //------------------------------------------------------------------ - //! Set workflow pointer in the handler + //------------------------------------------------------------------------ + //! Assign workflow to OperationHandler //! - //! @param wf workflow to set - //------------------------------------------------------------------ + //! @param wf : the workflow + //------------------------------------------------------------------------ void AssignToWorkflow( Workflow *wf ) { static_assert(state == Handled, "Only Operation can be assigned to workflow"); @@ -355,23 +495,24 @@ namespace XrdCl handler->AssignToWorkflow( wf ); } - //------------------------------------------------------------------ + //------------------------------------------------------------------------ //! Run operation //! - //! @param params container with parameters forwarded from - //! previous operation - //! @return status of the operation - //------------------------------------------------------------------ + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation + //------------------------------------------------------------------------ virtual XRootDStatus Run( std::shared_ptr ¶ms, int bucket = 1 ) = 0; - //------------------------------------------------------------------ + //------------------------------------------------------------------------ //! Handle error caused by missing parameter //! - //! @param err error object - //! @return default operation status (actual status containg - //! error information is passed to the handler) - //------------------------------------------------------------------ + //! @param err : error object + //! + //! @return : default operation status (actual status containg + //! error information is passed to the handler) + //------------------------------------------------------------------------ virtual XRootDStatus HandleError( const std::logic_error& err ) { XRootDStatus *st = new XRootDStatus( stError, err.what() ); @@ -379,11 +520,11 @@ namespace XrdCl return XRootDStatus(); } - //------------------------------------------------------------------ - //! Add next operation to the handler + //------------------------------------------------------------------------ + //! Add next operation in the pipeline //! - //! @param op operation to add - //------------------------------------------------------------------ + //! @param op : operation to add + //------------------------------------------------------------------------ void AddOperation( Operation *op ) { if( handler ) @@ -392,30 +533,46 @@ namespace XrdCl } } + //------------------------------------------------------------------------ + //! Operation handler + //------------------------------------------------------------------------ std::unique_ptr handler; }; - //---------------------------------------------------------------------- - //! A wrapper around operation pipeline - //---------------------------------------------------------------------- + //---------------------------------------------------------------------------- + //! A wrapper around operation pipeline. A Pipeline is a once-use-only + //! object - once executed by a Workflow engine it is invalidated. + //! + //! Takes ownership of given operation pipeline (which is in most would + //! be a temporary object) + //---------------------------------------------------------------------------- class Pipeline { friend class Workflow; public: + //------------------------------------------------------------------------ + //! Constructor + //------------------------------------------------------------------------ Pipeline( Operation *op ) : operation( op->Move() ) { } + //------------------------------------------------------------------------ + //! Constructor + //------------------------------------------------------------------------ Pipeline( Operation &op ) : operation( op.Move() ) { } + //------------------------------------------------------------------------ + //! Constructor + //------------------------------------------------------------------------ Pipeline( Operation &&op ) : operation( op.Move() ) { @@ -428,12 +585,18 @@ namespace XrdCl } + //------------------------------------------------------------------------ + //! Constructor + //------------------------------------------------------------------------ Pipeline( Operation &op ) : operation( op.ToHandled() ) { } + //------------------------------------------------------------------------ + //! Constructor + //------------------------------------------------------------------------ Pipeline( Operation &&op ) : operation( op.ToHandled() ) { @@ -446,12 +609,18 @@ namespace XrdCl } + //------------------------------------------------------------------------ + //! Constructor + //------------------------------------------------------------------------ Pipeline& operator=( Pipeline &&pipe ) { operation = std::move( pipe.operation ); return *this; } + //------------------------------------------------------------------------ + //! Conversion to Operation + //------------------------------------------------------------------------ operator Operation&() { return *operation.get(); @@ -459,43 +628,65 @@ namespace XrdCl private: + //------------------------------------------------------------------------ + //! First iteam in the pipeline + //------------------------------------------------------------------------ std::unique_ptr> operation; }; - //---------------------------------------------------------------------- - //! ArgsOperation template + //---------------------------------------------------------------------------- + //! Concrete Operation template + //! Defines | and >> operator as well as operation arguments. //! - //! @param Derived the class that derives from this template - //! @param state describes current operation configuration state - //! @param Args operation arguments - //---------------------------------------------------------------------- + //! @arg Derived : the class that derives from this template (CRTP) + //! @arg state : describes current operation configuration state + //! @arg Args : operation arguments + //---------------------------------------------------------------------------- template class Derived, State state, typename ... Args> class ConcreteOperation: public Operation { template class, State, typename ...> friend class ConcreteOperation; - public: + public: + //------------------------------------------------------------------------ + //! Constructor + //------------------------------------------------------------------------ ConcreteOperation() - {} + { + } + + //------------------------------------------------------------------------ + //! Move constructor from other states + //! + //! @arg from : state from which the object is being converted + //! + //! @param op : the object that is being converted + //------------------------------------------------------------------------ template - ConcreteOperation( ConcreteOperation && op ) : Operation( std::move( op ) ), args( std::move( op.args ) ) + ConcreteOperation( ConcreteOperation && op ) : + Operation( std::move( op ) ), args( std::move( op.args ) ) { } + //------------------------------------------------------------------------ + //! Move current object into newly allocated instance + //! + //! @return : the new instance + //------------------------------------------------------------------------ Operation* Move() { Derived *me = static_cast*>( this ); return new Derived( std::move( *me ) ); } - //------------------------------------------------------------------ + //------------------------------------------------------------------------ //! Transform operation to handled //! //! @return Operation& - //------------------------------------------------------------------ + //------------------------------------------------------------------------ Operation* ToHandled() { this->handler.reset( new OperationHandler( new ForwardingHandler(), true ) ); @@ -503,6 +694,11 @@ namespace XrdCl return new Derived( std::move( *me ) ); } + //------------------------------------------------------------------------ + //! Transform into a new instance with desired state + //! + //! @return : new instance in the desired state + //------------------------------------------------------------------------ template Derived Transform() { @@ -510,96 +706,122 @@ namespace XrdCl return Derived( std::move( *me ) ); } + //------------------------------------------------------------------------ + //! Generic function call operator. Sets the arguments for the + //! given operation. + //! + //! @param args : parameter pack with operation arguments + //! + //! @return : move-copy of myself in 'Configured' state + //------------------------------------------------------------------------ Derived operator()( Args... args ) { static_assert(state == Bare, "Operator () is available only for type Operation"); - this->TakeArgs( std::move( args )... ); + this->args = std::tuple( std::move( args )... ); return Transform(); } - //------------------------------------------------------------------ - //! Add handler which will be executed after operation ends + //------------------------------------------------------------------------ + //! Adds handler to the operation //! - //! @param h handler to add - //------------------------------------------------------------------ + //! @param h : handler to add + //------------------------------------------------------------------------ Derived operator>>(ForwardingHandler *h) { return StreamImpl( h, false ); } - //------------------------------------------------------------------ - //! Add handler which will be executed after operation ends + //------------------------------------------------------------------------ + //! Adds handler for the operation //! - //! @param h handler to add - //------------------------------------------------------------------ + //! @param h : handler to add + //------------------------------------------------------------------------ Derived operator>>(ForwardingHandler &h) { return StreamImpl( &h, false ); } - //------------------------------------------------------------------ - //! Add handler which will be executed after operation ends + //------------------------------------------------------------------------ + //! Adds handler for the operation //! - //! @param h handler to add - //------------------------------------------------------------------ + //! @param h : handler to add + //------------------------------------------------------------------------ Derived operator>>(ResponseHandler *h) { return StreamImpl( new WrappingHandler( h ) ); } - //------------------------------------------------------------------ - //! Add handler which will be executed after operation ends + //------------------------------------------------------------------------ + //! Adds handler for the operation //! - //! @param h handler to add - //------------------------------------------------------------------ + //! @param h : handler to add + //------------------------------------------------------------------------ Derived operator>>(ResponseHandler &h) { return StreamImpl( new WrappingHandler( &h ) ); } - //------------------------------------------------------------------ - //! Add operation to handler + //------------------------------------------------------------------------ + //! Creates a pipeline of 2 or more operations //! - //! @param op operation to add - //! @return handled operation - //------------------------------------------------------------------ + //! @param op : operation to add + //! + //! @return : handled operation + //------------------------------------------------------------------------ Derived operator|( Operation &op ) { static_assert(state != Bare, "Operator | is available only for Operations that have been at least configured."); return PipeImpl( *this, op ); } + //------------------------------------------------------------------------ + //! Creates a pipeline of 2 or more operations + //! + //! @param op : operation to add + //! + //! @return : handled operation + //------------------------------------------------------------------------ Derived operator|( Operation &&op ) { static_assert(state != Bare, "Operator | is available only for Operations that have been at least configured."); return PipeImpl( *this, op ); } + //------------------------------------------------------------------------ + //! Creates a pipeline of 2 or more operations + //! + //! @param op operation to add + //! + //! @return handled operation + //------------------------------------------------------------------------ Derived operator|( Operation &op ) { static_assert(state != Bare, "Operator | is available only for Operations that have been at least configured."); return PipeImpl( *this, op ); } + //------------------------------------------------------------------------ + //! Creates a pipeline of 2 or more operations + //! + //! @param op : operation to add + //! + //! @return : handled operation + //------------------------------------------------------------------------ Derived operator|( Operation &&op ) { static_assert(state != Bare, "Operator | is available only for Operations that have been at least configured."); return PipeImpl( *this, op ); } - protected: + protected: - inline void TakeArgs( Args&&... args ) - { - this->args = std::tuple( std::move( args )... ); - } - - //------------------------------------------------------------------ - //! implements operator>> functionality + //------------------------------------------------------------------------ + //! Implements operator>> functionality //! - //! @param h handler to be added - //! @return return an instance of Derived - //------------------------------------------------------------------ + //! @param h : handler to be added + //! @ + //! @return : return an instance of Derived + //------------------------------------------------------------------------ inline Derived StreamImpl( ForwardingHandler *handler, bool own = true ) { static_assert(state == Configured, "Operator >> is available only for type Operation"); @@ -607,6 +829,14 @@ namespace XrdCl return Transform(); } + //------------------------------------------------------------------------ + //! Implements operator| functionality + //! + //! @param me : reference to myself (*this) + //! @param op : reference to the other operation + //! + //! @return : move-copy of myself + //------------------------------------------------------------------------ inline static Derived PipeImpl( ConcreteOperation &me, Operation &op ) { @@ -614,6 +844,14 @@ namespace XrdCl return me.Transform(); } + //------------------------------------------------------------------------ + //! Implements operator| functionality + //! + //! @param me : reference to myself (*this) + //! @param op : reference to the other operation + //! + //! @return : move-copy of myself + //------------------------------------------------------------------------ inline static Derived PipeImpl( ConcreteOperation &me, Operation &op ) { @@ -629,6 +867,14 @@ namespace XrdCl return me.Transform(); } + //------------------------------------------------------------------------ + //! Implements operator| functionality + //! + //! @param me : reference to myself (*this) + //! @param op : reference to the other operation + //! + //! @return : move-copy of myself + //------------------------------------------------------------------------ inline static Derived PipeImpl( ConcreteOperation &me, Operation &op ) { @@ -637,16 +883,30 @@ namespace XrdCl return me.Transform(); } + //------------------------------------------------------------------------ + //! Operation arguments + //------------------------------------------------------------------------ std::tuple args; }; - //---------------------------------------------------------------------- - //! Get helper function for ArgsOperation template - //! - //! @param args tuple with operation arguments - //! @param params params forwarded by previous operation - //! @param bucket bucket assigned to this operation - //---------------------------------------------------------------------- + //---------------------------------------------------------------------------- + //! Helper function for extracting arguments from a argument tuple and + //! argument container. Priority goes to arguments specified in the + //! tuple, only if not defined there an arguments is being looked up + //! in the argument container. + //! + //! @arg ArgDesc : descryptor of the argument type + //! @arg Args : types of operation arguments + //! + //! @param args : tuple with operation arguments + //! @param params : container with forwarded arguments + //! @param bucket : bucket number in the container + //! + //! @return : requested argument + //! + //! @throws : logic_error if the argument has not been specified + //! neither in the tuple nor in the container + //---------------------------------------------------------------------------- template inline typename ArgDesc::type& Get( std::tuple &args, std::shared_ptr ¶ms, int bucket ) diff --git a/src/XrdCl/XrdClParallelOperation.hh b/src/XrdCl/XrdClParallelOperation.hh index 74a03643073..4c4a640294f 100644 --- a/src/XrdCl/XrdClParallelOperation.hh +++ b/src/XrdCl/XrdClParallelOperation.hh @@ -31,11 +31,13 @@ namespace XrdCl { - //----------------------------------------------------------------------- - //! Parallel operations + //---------------------------------------------------------------------------- + //! Parallel operations, allows to execute two or more pipelines in + //! parallel. //! - //! @tparam state describes current operation configuration state - //----------------------------------------------------------------------- + //! @arg state : describes current operation configuration state + //! (@see Operation) + //---------------------------------------------------------------------------- template class ParallelOperation: public ConcreteOperation { @@ -43,6 +45,9 @@ namespace XrdCl public: + //------------------------------------------------------------------------ + //! Constructor: copy-move a ParallelOperation in different state + //------------------------------------------------------------------------ template ParallelOperation( ParallelOperation &&obj ) : ConcreteOperation( std::move( obj ) ), workflows( @@ -50,6 +55,13 @@ namespace XrdCl { } + //------------------------------------------------------------------------ + //! Constructor + //! + //! @arg Container : iterable container type + //! + //! @param container : iterable container with pipelines + //------------------------------------------------------------------------ template ParallelOperation( Container &container ) { @@ -62,8 +74,16 @@ namespace XrdCl } } + //------------------------------------------------------------------------ + //! make visible the >> inherited from ConcreteOperation + //------------------------------------------------------------------------ using ConcreteOperation::operator>>; + //------------------------------------------------------------------------ + //! Adds handler for the operation + //! + //! @param handleFunction : callback (function, functor or lambda) + //------------------------------------------------------------------------ ParallelOperation operator>>( std::function handleFunction ) { @@ -72,11 +92,9 @@ namespace XrdCl return this->StreamImpl( forwardingHandler ); } - //------------------------------------------------------------------ - //! Get description of parallel operations flow - //! - //! @return std::string description - //------------------------------------------------------------------ + //------------------------------------------------------------------------ + //! @return : operation name + //------------------------------------------------------------------------ std::string ToString() { std::ostringstream oss; @@ -94,13 +112,13 @@ namespace XrdCl } private: + //------------------------------------------------------------------------ - //! Run operations + //! Run operation //! - //! @param params parameters container - //! @param bucketDefault bucket in parameters container - //! (not used here, provided only for compatibility with the interface ) - //! @return XRootDStatus status of the operations + //! @param params : container with parameters forwarded from + //! previous operation + //! @return : status of the operation //------------------------------------------------------------------------ XRootDStatus Run( std::shared_ptr ¶ms, int bucketDefault = 0 ) @@ -136,27 +154,27 @@ namespace XrdCl std::vector> workflows; }; - //----------------------------------------------------------------------- + //---------------------------------------------------------------------------- //! Factory function for creating parallel operation from a vector - //----------------------------------------------------------------------- + //---------------------------------------------------------------------------- template ParallelOperation Parallel( Container &container ) { return ParallelOperation( container ); } - //----------------------------------------------------------------------- + //---------------------------------------------------------------------------- //! Helper function for converting parameter pack into a vector - //----------------------------------------------------------------------- + //---------------------------------------------------------------------------- void PipesToVec( std::vector& ) { // base case } - //----------------------------------------------------------------------- + //---------------------------------------------------------------------------- // Declare PipesToVec (we need to do declare those functions ahead of // definitions, as they may call each other. - //----------------------------------------------------------------------- + //---------------------------------------------------------------------------- template void PipesToVec( std::vector &v, Operation &operation, Others&... others ); @@ -169,9 +187,9 @@ namespace XrdCl void PipesToVec( std::vector &v, Pipeline &pipeline, Others&... others ); - //----------------------------------------------------------------------- + //---------------------------------------------------------------------------- // Define PipesToVec - //----------------------------------------------------------------------- + //---------------------------------------------------------------------------- template void PipesToVec( std::vector &v, Operation &operation, Others&... others ) @@ -196,12 +214,12 @@ namespace XrdCl PipesToVec( v, others... ); } - //----------------------------------------------------------------------- + //---------------------------------------------------------------------------- //! Factory function for creating parallel operation from //! a given number of operations //! (we use && reference since due to reference colapsing this will fit //! both r- and l-value references) - //----------------------------------------------------------------------- + //---------------------------------------------------------------------------- template ParallelOperation Parallel( Operations&& ... operations ) {