diff --git a/src/XrdCl/XrdClFileOperations.hh b/src/XrdCl/XrdClFileOperations.hh index d9c0e6af867..d17269a98cb 100644 --- a/src/XrdCl/XrdClFileOperations.hh +++ b/src/XrdCl/XrdClFileOperations.hh @@ -34,7 +34,7 @@ namespace XrdCl { template class Derived, State state, typename ... Arguments> - class FileOperation: public OperationBase + class FileOperation: public ConcreteOperation { template class, State, typename ...> friend class FileOperation; @@ -51,7 +51,7 @@ namespace XrdCl } template - FileOperation( FileOperation && op ) : OperationBase( std::move( op ) ), file( op.file ) + FileOperation( FileOperation && op ) : ConcreteOperation( std::move( op ) ), file( op.file ) { } @@ -113,12 +113,12 @@ namespace XrdCl OpenImpl operator()( Arg url, Arg flags, Arg mode = Access::None ) { - return this->OperationBase, + return this->ConcreteOperation, Arg, Arg>::operator ()( std::move( url ), std::move( flags ), std::move( mode ) ); } - using OperationBase, + using ConcreteOperation, Arg, Arg>::operator>>; OpenImpl operator>>( @@ -223,7 +223,7 @@ namespace XrdCl typedef void* type; }; - using OperationBase, Arg, + using ConcreteOperation, Arg, Arg>::operator>>; ReadImpl operator>>( @@ -293,7 +293,7 @@ namespace XrdCl } - using OperationBase::operator>>; + using ConcreteOperation::operator>>; CloseImpl operator>>( std::function handleFunction ) @@ -351,7 +351,7 @@ namespace XrdCl typedef bool type; }; - using OperationBase>::operator>>; + using ConcreteOperation>::operator>>; StatImpl operator>>( std::function handleFunction ) @@ -439,7 +439,7 @@ namespace XrdCl typedef void* type; }; - using OperationBase, Arg, + using ConcreteOperation, Arg, Arg>::operator>>; WriteImpl operator>>( @@ -505,7 +505,7 @@ namespace XrdCl { } - using OperationBase::operator>>; + using ConcreteOperation::operator>>; SyncImpl operator>>( std::function handleFunction ) @@ -563,7 +563,7 @@ namespace XrdCl typedef uint64_t type; }; - using OperationBase>::operator>>; + using ConcreteOperation>::operator>>; TruncateImpl operator>>( std::function handleFunction ) @@ -642,7 +642,7 @@ namespace XrdCl typedef char* type; }; - using OperationBase, Arg>::operator>>; + using ConcreteOperation, Arg>::operator>>; VectorReadImpl operator>>( std::function handleFunction ) @@ -714,7 +714,7 @@ namespace XrdCl typedef ChunkList type; }; - using OperationBase>::operator>>; + using ConcreteOperation>::operator>>; VectorWriteImpl operator>>( std::function handleFunction ) @@ -799,7 +799,7 @@ namespace XrdCl typedef int type; }; - using OperationBase, Arg, + using ConcreteOperation, Arg, Arg>::operator>>; WriteVImpl operator>>( @@ -872,7 +872,7 @@ namespace XrdCl typedef Buffer type; }; - using OperationBase>::operator>>; + using ConcreteOperation>::operator>>; FcntlImpl operator>>( std::function handleFunction ) @@ -931,7 +931,7 @@ namespace XrdCl { } - using OperationBase::operator>>; + using ConcreteOperation::operator>>; VisaImpl operator>>( std::function handleFunction ) diff --git a/src/XrdCl/XrdClFileSystemOperations.hh b/src/XrdCl/XrdClFileSystemOperations.hh index 37290ff6236..87bdf001369 100644 --- a/src/XrdCl/XrdClFileSystemOperations.hh +++ b/src/XrdCl/XrdClFileSystemOperations.hh @@ -34,7 +34,7 @@ namespace XrdCl { template class Derived, State state, typename ... Args> - class FileSystemOperation: public OperationBase + class FileSystemOperation: public ConcreteOperation { template class, State, typename ...> friend class FileSystemOperation; @@ -52,7 +52,7 @@ namespace XrdCl } template - FileSystemOperation( FileSystemOperation && op ): OperationBase( std::move( op ) ), filesystem( op.filesystem ) + FileSystemOperation( FileSystemOperation && op ): ConcreteOperation( std::move( op ) ), filesystem( op.filesystem ) {} virtual ~FileSystemOperation() @@ -100,7 +100,7 @@ namespace XrdCl typedef OpenFlags::Flags type; }; - using OperationBase, + using ConcreteOperation, Arg>::operator>>; LocateImpl operator>>( @@ -181,7 +181,7 @@ namespace XrdCl typedef OpenFlags::Flags type; }; - using OperationBase, + using ConcreteOperation, Arg>::operator>>; DeepLocateImpl operator>>( @@ -263,7 +263,7 @@ namespace XrdCl typedef std::string type; }; - using OperationBase, Arg>::operator>>; + using ConcreteOperation, Arg>::operator>>; MvImpl operator>>( std::function handleFunction ) @@ -342,7 +342,7 @@ namespace XrdCl typedef Buffer type; }; - using OperationBase, Arg>::operator>>; + using ConcreteOperation, Arg>::operator>>; QueryImpl operator>>( std::function handleFunction ) @@ -423,7 +423,7 @@ namespace XrdCl typedef uint64_t type; }; - using OperationBase, Arg>::operator>>; + using ConcreteOperation, Arg>::operator>>; TruncateFsImpl operator>>( std::function handleFunction ) @@ -497,7 +497,7 @@ namespace XrdCl typedef std::string type; }; - using OperationBase>::operator>>; + using ConcreteOperation>::operator>>; RmImpl operator>>( std::function handleFunction ) @@ -580,7 +580,7 @@ namespace XrdCl typedef Access::Mode type; }; - using OperationBase, + using ConcreteOperation, Arg, Arg>::operator>>; MkDirImpl operator>>( @@ -656,7 +656,7 @@ namespace XrdCl typedef std::string type; }; - using OperationBase>::operator>>; + using ConcreteOperation>::operator>>; RmDirImpl operator>>( std::function handleFunction ) @@ -733,7 +733,7 @@ namespace XrdCl typedef Access::Mode type; }; - using OperationBase, Arg>::operator>>; + using ConcreteOperation, Arg>::operator>>; ChModImpl operator>>( std::function handleFunction ) @@ -795,7 +795,7 @@ namespace XrdCl { } - using OperationBase::operator>>; + using ConcreteOperation::operator>>; PingImpl operator>>( std::function handleFunction ) @@ -860,7 +860,7 @@ namespace XrdCl typedef std::string type; }; - using OperationBase>::operator>>; + using ConcreteOperation>::operator>>; StatFsImpl operator>>( std::function handleFunction ) @@ -932,7 +932,7 @@ namespace XrdCl typedef std::string type; }; - using OperationBase>::operator>>; + using ConcreteOperation>::operator>>; StatVFSImpl operator>>( std::function handleFunction ) @@ -991,7 +991,7 @@ namespace XrdCl { } - using OperationBase::operator>>; + using ConcreteOperation::operator>>; ProtocolImpl operator>>( std::function handleFunction ) @@ -1065,7 +1065,7 @@ namespace XrdCl typedef DirListFlags::Flags type; }; - using OperationBase, + using ConcreteOperation, Arg>::operator>>; DirListImpl operator>>( @@ -1138,7 +1138,7 @@ namespace XrdCl typedef std::string type; }; - using OperationBase>::operator>>; + using ConcreteOperation>::operator>>; SendInfoImpl operator>>( std::function handleFunction ) @@ -1222,7 +1222,7 @@ namespace XrdCl typedef uint8_t type; }; - using OperationBase>, + using ConcreteOperation>, Arg, Arg>::operator>>; PrepareImpl operator>>( diff --git a/src/XrdCl/XrdClOperations.cc b/src/XrdCl/XrdClOperations.cc index 9b48379ea68..4af4825e0b6 100644 --- a/src/XrdCl/XrdClOperations.cc +++ b/src/XrdCl/XrdClOperations.cc @@ -156,6 +156,14 @@ namespace XrdCl firstOperation->AssignToWorkflow( this ); } + Workflow::Workflow( Pipeline &&pipeline, bool enableLogging ) : + status( NULL ), logging( enableLogging ) + { + if( !pipeline.operation ) + throw std::invalid_argument( "Pipeline already has been executed." ); + firstOperation = pipeline.operation.release(); + } + Workflow::~Workflow() { delete firstOperation; diff --git a/src/XrdCl/XrdClOperations.hh b/src/XrdCl/XrdClOperations.hh index b6e82d9b901..2f491a45f9f 100644 --- a/src/XrdCl/XrdClOperations.hh +++ b/src/XrdCl/XrdClOperations.hh @@ -41,8 +41,11 @@ namespace XrdCl { Bare, Configured, Handled }; + template class Operation; + class Pipeline; + //--------------------------------------------------------------------------- //! Handler allowing forwarding parameters to the next operation in workflow //--------------------------------------------------------------------------- @@ -175,6 +178,13 @@ namespace XrdCl //------------------------------------------------------------------------ explicit Workflow( Operation* op, bool enableLogging = true ); + //------------------------------------------------------------------------ + //! Constructor + //! + //! @param a pipeline object + //------------------------------------------------------------------------ + Workflow( Pipeline &&pipeline, bool enableLogging = true ); + ~Workflow(); //------------------------------------------------------------------------ @@ -373,6 +383,67 @@ namespace XrdCl std::unique_ptr handler; }; + + //---------------------------------------------------------------------- + //! A wrapper around operation pipeline + //---------------------------------------------------------------------- + class Pipeline + { + friend class Workflow; + + public: + + Pipeline( Operation *op ) : operation( op->Move() ) + { + + } + + Pipeline( Operation &op ) : operation( op.Move() ) + { + + } + + Pipeline( Operation &&op ) : operation( op.Move() ) + { + + } + + Pipeline( Operation *op ) : operation( op->ToHandled() ) + { + + } + + Pipeline( Operation &op ) : operation( op.ToHandled() ) + { + + } + + Pipeline( Operation &&op ) : operation( op.ToHandled() ) + { + + } + + Pipeline( Pipeline &&pipe ) : operation( std::move( pipe.operation ) ) + { + + } + + Pipeline& operator=( Pipeline &&pipe ) + { + operation = std::move( pipe.operation ); + return *this; + } + + operator Operation&() + { + return *operation.get(); + } + + private: + + std::unique_ptr> operation; + }; + //---------------------------------------------------------------------- //! ArgsOperation template //! @@ -381,17 +452,17 @@ namespace XrdCl //! @param Args operation arguments //---------------------------------------------------------------------- template class Derived, State state, typename ... Args> - class OperationBase: public Operation + class ConcreteOperation: public Operation { - template class, State, typename ...> friend class OperationBase; + template class, State, typename ...> friend class ConcreteOperation; public: - OperationBase() + ConcreteOperation() {} template - OperationBase( OperationBase && op ) : Operation( std::move( op ) ), args( std::move( op.args ) ) + ConcreteOperation( ConcreteOperation && op ) : Operation( std::move( op ) ), args( std::move( op.args ) ) { } @@ -500,21 +571,21 @@ namespace XrdCl } inline static - Derived PipeImpl( OperationBase &me, Operation &op ) + Derived PipeImpl( ConcreteOperation &me, Operation &op ) { me.AddOperation( op.Move() ); return me.Transform(); } inline static - Derived PipeImpl( OperationBase &me, Operation &op ) + Derived PipeImpl( ConcreteOperation &me, Operation &op ) { me.AddOperation( op.ToHandled() ); return me.Transform(); } inline static - Derived PipeImpl( OperationBase &me, Operation &op ) + Derived PipeImpl( ConcreteOperation &me, Operation &op ) { me.handler.reset( new OperationHandler( new ForwardingHandler(), true ) ); me.AddOperation( op.Move() ); @@ -522,7 +593,7 @@ namespace XrdCl } inline static - Derived PipeImpl( OperationBase &me, Operation &op ) + Derived PipeImpl( ConcreteOperation &me, Operation &op ) { me.handler.reset( new OperationHandler( new ForwardingHandler(), true ) ); me.AddOperation( op.ToHandled() ); @@ -553,7 +624,7 @@ namespace XrdCl //! @tparam state describes current operation configuration state //----------------------------------------------------------------------- template - class ParallelOperation: public OperationBase + class ParallelOperation: public ConcreteOperation { template friend class ParallelOperation; @@ -578,22 +649,20 @@ namespace XrdCl template ParallelOperation( ParallelOperation &&obj ) : - OperationBase( std::move( obj ) ), workflows( + ConcreteOperation( std::move( obj ) ), workflows( std::move( obj.workflows ) ) { } - template + template ParallelOperation( Container &container ) { static_assert(state == Configured, "Constructor is available only for type ParallelOperations"); - static_assert(std::is_same*>::value, "Invalid type in container"); - typename Container::iterator it = container.begin(); - while( it != container.end() ) + auto itr = container.begin(); + for( ; itr != container.end(); ++itr ) { - std::unique_ptr w( new Workflow( *it, false ) ); + std::unique_ptr w( new Workflow( *itr, false ) ); workflows.push_back( std::move( w ) ); - ++it; } }