XRootD
XrdClFileOperations.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2011-2017 by European Organization for Nuclear Research (CERN)
3 // Author: Krzysztof Jamrog <krzysztof.piotr.jamrog@cern.ch>,
4 // Michal Simon <michal.simon@cern.ch>
5 //------------------------------------------------------------------------------
6 // This file is part of the XRootD software suite.
7 //
8 // XRootD is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Lesser General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or
11 // (at your option) any later version.
12 //
13 // XRootD is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public License
19 // along with XRootD. If not, see <http://www.gnu.org/licenses/>.
20 //
21 // In applying this licence, CERN does not waive the privileges and immunities
22 // granted to it by virtue of its status as an Intergovernmental Organization
23 // or submit itself to any jurisdiction.
24 //------------------------------------------------------------------------------
25 
26 #ifndef __XRD_CL_FILE_OPERATIONS_HH__
27 #define __XRD_CL_FILE_OPERATIONS_HH__
28 
29 #include "XrdCl/XrdClFile.hh"
30 #include "XrdCl/XrdClOperations.hh"
32 #include "XrdCl/XrdClCtx.hh"
33 
34 namespace XrdCl
35 {
36 
37  //----------------------------------------------------------------------------
43  //----------------------------------------------------------------------------
44  template<template<bool> class Derived, bool HasHndl, typename Response, typename ... Arguments>
45  class FileOperation: public ConcreteOperation<Derived, HasHndl, Response, Arguments...>
46  {
47 
48  template<template<bool> class, bool, typename, typename ...> friend class FileOperation;
49 
50  public:
51  //------------------------------------------------------------------------
56  //------------------------------------------------------------------------
57  FileOperation( Ctx<File> f, Arguments... args): ConcreteOperation<Derived, false, Response, Arguments...>( std::move( args )... ), file( std::move( f ) )
58  {
59  }
60 
61  //------------------------------------------------------------------------
67  //------------------------------------------------------------------------
68  template<bool from>
70  ConcreteOperation<Derived, HasHndl, Response, Arguments...>( std::move( op ) ), file( op.file )
71  {
72 
73  }
74 
75  //------------------------------------------------------------------------
77  //------------------------------------------------------------------------
78  virtual ~FileOperation()
79  {
80 
81  }
82 
83  protected:
84 
85  //------------------------------------------------------------------------
87  //------------------------------------------------------------------------
89  };
90 
91  //----------------------------------------------------------------------------
93  //----------------------------------------------------------------------------
94  template<bool HasHndl>
97  {
98  //------------------------------------------------------------------------
104  //------------------------------------------------------------------------
105  struct ExResp : public Resp<void>
106  {
107  //--------------------------------------------------------------------
111  //--------------------------------------------------------------------
112  ExResp( const Ctx<File> &file ): file( file )
113  {
114  }
115 
116  //--------------------------------------------------------------------
121  //--------------------------------------------------------------------
122  inline ResponseHandler* Create( std::function<void( XRootDStatus&,
123  StatInfo& )> func )
124  {
125  return new ExOpenFuncWrapper( this->file, func );
126  }
127 
128  //--------------------------------------------------------------------
130  //--------------------------------------------------------------------
131  using Resp<void>::Create;
132 
133  //--------------------------------------------------------------------
135  //--------------------------------------------------------------------
136  Ctx<File> file;
137  };
138 
139  public:
140 
141  //------------------------------------------------------------------------
143  //------------------------------------------------------------------------
146  FileOperation<OpenImpl, HasHndl, Resp<void>, Arg<std::string>, Arg<OpenFlags::Flags>,
147  Arg<Access::Mode>>( std::move( f ), std::move( url ), std::move( flags ),
148  std::move( mode ) )
149  {
150  }
151 
152  //------------------------------------------------------------------------
158  //------------------------------------------------------------------------
159  template<bool from>
161  FileOperation<OpenImpl, HasHndl, Resp<void>, Arg<std::string>, Arg<OpenFlags::Flags>,
162  Arg<Access::Mode>>( std::move( open ) )
163  {
164  }
165 
166 
167  //------------------------------------------------------------------------
169  //------------------------------------------------------------------------
170  enum { UrlArg, FlagsArg, ModeArg };
171 
172  //------------------------------------------------------------------------
177  //------------------------------------------------------------------------
178  template<typename Hdlr>
179  OpenImpl<true> operator>>( Hdlr &&hdlr )
180  {
181  ExResp factory( *this->file );
182  return this->StreamImpl( factory.Create( hdlr ) );
183  }
184 
185  //------------------------------------------------------------------------
187  //------------------------------------------------------------------------
188  std::string ToString()
189  {
190  return "Open";
191  }
192 
193  protected:
194 
195  //------------------------------------------------------------------------
200  //------------------------------------------------------------------------
201  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
202  {
203  const std::string &url = std::get<UrlArg>( this->args );
204  OpenFlags::Flags flags = std::get<FlagsArg>( this->args );
205  Access::Mode mode = std::get<ModeArg>( this->args );
206  uint16_t timeout = pipelineTimeout < this->timeout ?
207  pipelineTimeout : this->timeout;
208  return this->file->Open( url, flags, mode, handler, timeout );
209  }
210  };
211 
212  //----------------------------------------------------------------------------
214  //----------------------------------------------------------------------------
216  Arg<Access::Mode> mode = Access::None, uint16_t timeout = 0 )
217  {
218  return OpenImpl<false>( std::move( file ), std::move( url ), std::move( flags ),
219  std::move( mode ) ).Timeout( timeout );
220  }
221 
222  //----------------------------------------------------------------------------
224  //----------------------------------------------------------------------------
225  template<bool HasHndl>
226  class ReadImpl: public FileOperation<ReadImpl, HasHndl, Resp<ChunkInfo>,
227  Arg<uint64_t>, Arg<uint32_t>, Arg<void*>>
228  {
229  public:
230 
231  //------------------------------------------------------------------------
233  //------------------------------------------------------------------------
236 
237  //------------------------------------------------------------------------
239  //------------------------------------------------------------------------
241 
242  //------------------------------------------------------------------------
244  //------------------------------------------------------------------------
245  std::string ToString()
246  {
247  return "Read";
248  }
249 
250  protected:
251 
252  //------------------------------------------------------------------------
258  //------------------------------------------------------------------------
259  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
260  {
261  uint64_t offset = std::get<OffsetArg>( this->args ).Get();
262  uint32_t size = std::get<SizeArg>( this->args ).Get();
263  void *buffer = std::get<BufferArg>( this->args ).Get();
264  uint16_t timeout = pipelineTimeout < this->timeout ?
265  pipelineTimeout : this->timeout;
266  return this->file->Read( offset, size, buffer, handler, timeout );
267  }
268  };
269 
270  //----------------------------------------------------------------------------
272  //----------------------------------------------------------------------------
274  Arg<void*> buffer, uint16_t timeout = 0 )
275  {
276  return ReadImpl<false>( std::move( file ), std::move( offset ), std::move( size ),
277  std::move( buffer ) ).Timeout( timeout );
278  }
279 
280  //----------------------------------------------------------------------------
282  //----------------------------------------------------------------------------
283  template<bool HasHndl>
284  class PgReadImpl: public FileOperation<PgReadImpl, HasHndl, Resp<PageInfo>,
285  Arg<uint64_t>, Arg<uint32_t>, Arg<void*>>
286  {
287  public:
288 
289  //------------------------------------------------------------------------
291  //------------------------------------------------------------------------
294 
295  //------------------------------------------------------------------------
297  //------------------------------------------------------------------------
299 
300  //------------------------------------------------------------------------
302  //------------------------------------------------------------------------
303  std::string ToString()
304  {
305  return "PgRead";
306  }
307 
308  protected:
309 
310  //------------------------------------------------------------------------
316  //------------------------------------------------------------------------
317  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
318  {
319  uint64_t offset = std::get<OffsetArg>( this->args ).Get();
320  uint32_t size = std::get<SizeArg>( this->args ).Get();
321  void *buffer = std::get<BufferArg>( this->args ).Get();
322  uint16_t timeout = pipelineTimeout < this->timeout ?
323  pipelineTimeout : this->timeout;
324  return this->file->PgRead( offset, size, buffer, handler, timeout );
325  }
326  };
327 
328  //----------------------------------------------------------------------------
330  //----------------------------------------------------------------------------
332  Arg<uint32_t> size, Arg<void*> buffer,
333  uint16_t timeout = 0 )
334  {
335  return PgReadImpl<false>( std::move( file ), std::move( offset ), std::move( size ),
336  std::move( buffer ) ).Timeout( timeout );
337  }
338 
339  //----------------------------------------------------------------------------
341  //----------------------------------------------------------------------------
342  template<typename RSP> struct ReadTrait { };
343 
344  template<> struct ReadTrait<ChunkInfo> { using RET = ReadImpl<false>; };
345 
346  template<> struct ReadTrait<PageInfo> { using RET = PgReadImpl<false>; };
347 
348  template<typename RSP> inline typename ReadTrait<RSP>::RET
350  Arg<void*> buffer, uint16_t timeout = 0 );
351 
352  template<> inline ReadImpl<false>
354  Arg<void*> buffer, uint16_t timeout )
355  {
356  return Read( std::move( file ), std::move( offset ), std::move( size ),
357  std::move( buffer ), timeout );
358  }
359 
360  template<> inline PgReadImpl<false>
361  RdWithRsp<PageInfo>( Ctx<File> file, Arg<uint64_t> offset, Arg<uint32_t> size,
362  Arg<void*> buffer, uint16_t timeout )
363  {
364  return PgRead( std::move( file ), std::move( offset ), std::move( size ),
365  std::move( buffer ), timeout );
366  }
367 
368  //----------------------------------------------------------------------------
370  //----------------------------------------------------------------------------
371  template<bool HasHndl>
372  class PgWriteImpl: public FileOperation<PgWriteImpl, HasHndl, Resp<void>,
373  Arg<uint64_t>, Arg<uint32_t>, Arg<void*>, Arg<std::vector<uint32_t>>>
374  {
375  public:
376 
377  //------------------------------------------------------------------------
379  //------------------------------------------------------------------------
382 
383  //------------------------------------------------------------------------
385  //------------------------------------------------------------------------
387 
388  //------------------------------------------------------------------------
390  //------------------------------------------------------------------------
391  std::string ToString()
392  {
393  return "PgWrite";
394  }
395 
396  protected:
397 
398  //------------------------------------------------------------------------
404  //------------------------------------------------------------------------
405  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
406  {
407  uint64_t offset = std::get<OffsetArg>( this->args ).Get();
408  uint32_t size = std::get<SizeArg>( this->args ).Get();
409  void *buffer = std::get<BufferArg>( this->args ).Get();
410  std::vector<uint32_t> cksums = std::get<CksumsArg>( this->args ).Get();
411  uint16_t timeout = pipelineTimeout < this->timeout ?
412  pipelineTimeout : this->timeout;
413  return this->file->PgWrite( offset, size, buffer, cksums, handler, timeout );
414  }
415  };
416 
417  //----------------------------------------------------------------------------
419  //----------------------------------------------------------------------------
421  Arg<uint32_t> size, Arg<void*> buffer,
422  Arg<std::vector<uint32_t>> cksums,
423  uint16_t timeout = 0 )
424  {
425  return PgWriteImpl<false>( std::move( file ), std::move( offset ), std::move( size ),
426  std::move( buffer ), std::move( cksums ) ).Timeout( timeout );
427  }
428 
429  //----------------------------------------------------------------------------
431  //----------------------------------------------------------------------------
433  Arg<uint32_t> size, Arg<void*> buffer,
434  uint16_t timeout = 0 )
435  {
436  std::vector<uint32_t> cksums;
437  return PgWriteImpl<false>( std::move( file ), std::move( offset ), std::move( size ),
438  std::move( buffer ), std::move( cksums ) ).Timeout( timeout );
439  }
440 
441  //----------------------------------------------------------------------------
443  //----------------------------------------------------------------------------
444  template<bool HasHndl>
445  class CloseImpl: public FileOperation<CloseImpl, HasHndl, Resp<void>>
446  {
447  public:
448 
449  //------------------------------------------------------------------------
451  //------------------------------------------------------------------------
453 
454  //------------------------------------------------------------------------
456  //------------------------------------------------------------------------
457  std::string ToString()
458  {
459  return "Close";
460  }
461 
462  protected:
463 
464  //------------------------------------------------------------------------
470  //------------------------------------------------------------------------
471  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
472  {
473  uint16_t timeout = pipelineTimeout < this->timeout ?
474  pipelineTimeout : this->timeout;
475  return this->file->Close( handler, timeout );
476  }
477  };
478 
479  //----------------------------------------------------------------------------
481  //----------------------------------------------------------------------------
482  inline CloseImpl<false> Close( Ctx<File> file, uint16_t timeout = 0 )
483  {
484  return CloseImpl<false>( std::move( file ) ).Timeout( timeout );
485  }
486 
487  //----------------------------------------------------------------------------
489  //----------------------------------------------------------------------------
490  template<bool HasHndl>
491  class StatImpl: public FileOperation<StatImpl, HasHndl, Resp<StatInfo>, Arg<bool>>
492  {
493  public:
494 
495  //------------------------------------------------------------------------
497  //------------------------------------------------------------------------
499 
500  //------------------------------------------------------------------------
502  //------------------------------------------------------------------------
503  enum { ForceArg };
504 
505  //------------------------------------------------------------------------
507  //------------------------------------------------------------------------
508  std::string ToString()
509  {
510  return "Stat";
511  }
512 
513  protected:
514 
515  //------------------------------------------------------------------------
521  //------------------------------------------------------------------------
522  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
523  {
524  bool force = std::get<ForceArg>( this->args ).Get();
525  uint16_t timeout = pipelineTimeout < this->timeout ?
526  pipelineTimeout : this->timeout;
527  return this->file->Stat( force, handler, timeout );
528  }
529  };
530 
531  //----------------------------------------------------------------------------
534  //----------------------------------------------------------------------------
535  inline StatImpl<false> Stat( Ctx<File> file, Arg<bool> force, uint16_t timeout = 0 )
536  {
537  return StatImpl<false>( std::move( file ), std::move( force ) ).Timeout( timeout );
538  }
539 
540  //----------------------------------------------------------------------------
542  //----------------------------------------------------------------------------
543  template<bool HasHndl>
544  class WriteImpl: public FileOperation<WriteImpl, HasHndl, Resp<void>, Arg<uint64_t>,
545  Arg<uint32_t>, Arg<const void*>>
546  {
547  public:
548 
549  //------------------------------------------------------------------------
551  //------------------------------------------------------------------------
554 
555  //------------------------------------------------------------------------
557  //------------------------------------------------------------------------
559 
560  //------------------------------------------------------------------------
562  //------------------------------------------------------------------------
563  std::string ToString()
564  {
565  return "Write";
566  }
567 
568  protected:
569 
570  //------------------------------------------------------------------------
576  //------------------------------------------------------------------------
577  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
578  {
579  uint64_t offset = std::get<OffsetArg>( this->args ).Get();
580  uint32_t size = std::get<SizeArg>( this->args ).Get();
581  const void *buffer = std::get<BufferArg>( this->args ).Get();
582  uint16_t timeout = pipelineTimeout < this->timeout ?
583  pipelineTimeout : this->timeout;
584  return this->file->Write( offset, size, buffer, handler, timeout );
585  }
586  };
587 
588  //----------------------------------------------------------------------------
590  //----------------------------------------------------------------------------
592  Arg<const void*> buffer, uint16_t timeout = 0 )
593  {
594  return WriteImpl<false>( std::move( file ), std::move( offset ), std::move( size ),
595  std::move( buffer ) ).Timeout( timeout );
596  }
597 
598  //----------------------------------------------------------------------------
600  //----------------------------------------------------------------------------
601  template<bool HasHndl>
602  class SyncImpl: public FileOperation<SyncImpl, HasHndl, Resp<void>>
603  {
604  public:
605 
606  //------------------------------------------------------------------------
608  //------------------------------------------------------------------------
610 
611  //------------------------------------------------------------------------
613  //------------------------------------------------------------------------
614  std::string ToString()
615  {
616  return "Sync";
617  }
618 
619  protected:
620 
621  //------------------------------------------------------------------------
627  //------------------------------------------------------------------------
628  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
629  {
630  uint16_t timeout = pipelineTimeout < this->timeout ?
631  pipelineTimeout : this->timeout;
632  return this->file->Sync( handler, timeout );
633  }
634  };
635 
636  //----------------------------------------------------------------------------
638  //----------------------------------------------------------------------------
639  inline SyncImpl<false> Sync( Ctx<File> file, uint16_t timeout = 0 )
640  {
641  return SyncImpl<false>( std::move( file ) ).Timeout( timeout );
642  }
643 
644  //----------------------------------------------------------------------------
646  //----------------------------------------------------------------------------
647  template<bool HasHndl>
648  class TruncateImpl: public FileOperation<TruncateImpl, HasHndl, Resp<void>, Arg<uint64_t>>
649  {
650  public:
651 
652  //------------------------------------------------------------------------
654  //------------------------------------------------------------------------
656 
657  //------------------------------------------------------------------------
659  //------------------------------------------------------------------------
660  enum { SizeArg };
661 
662  //------------------------------------------------------------------------
664  //------------------------------------------------------------------------
665  std::string ToString()
666  {
667  return "Truncate";
668  }
669 
670  protected:
671 
672  //------------------------------------------------------------------------
678  //------------------------------------------------------------------------
679  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
680  {
681  uint64_t size = std::get<SizeArg>( this->args ).Get();
682  uint16_t timeout = pipelineTimeout < this->timeout ?
683  pipelineTimeout : this->timeout;
684  return this->file->Truncate( size, handler, timeout );
685  }
686  };
687 
688  //----------------------------------------------------------------------------
691  //----------------------------------------------------------------------------
692  inline TruncateImpl<false> Truncate( Ctx<File> file, Arg<uint64_t> size, uint16_t timeout )
693  {
694  return TruncateImpl<false>( std::move( file ), std::move( size ) ).Timeout( timeout );
695  }
696 
697  //----------------------------------------------------------------------------
699  //----------------------------------------------------------------------------
700  template<bool HasHndl>
701  class VectorReadImpl: public FileOperation<VectorReadImpl, HasHndl,
702  Resp<VectorReadInfo>, Arg<ChunkList>, Arg<void*>>
703  {
704  public:
705 
706  //------------------------------------------------------------------------
708  //------------------------------------------------------------------------
711 
712  //------------------------------------------------------------------------
714  //------------------------------------------------------------------------
715  enum { ChunksArg, BufferArg };
716 
717  //------------------------------------------------------------------------
719  //------------------------------------------------------------------------
720  std::string ToString()
721  {
722  return "VectorRead";
723  }
724 
725  protected:
726 
727  //------------------------------------------------------------------------
733  //------------------------------------------------------------------------
734  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
735  {
736  ChunkList &chunks = std::get<ChunksArg>( this->args ).Get();
737  void *buffer = std::get<BufferArg>( this->args ).Get();
738  uint16_t timeout = pipelineTimeout < this->timeout ?
739  pipelineTimeout : this->timeout;
740  return this->file->VectorRead( chunks, buffer, handler, timeout );
741  }
742  };
743 
744  //----------------------------------------------------------------------------
746  //----------------------------------------------------------------------------
748  Arg<void*> buffer, uint16_t timeout = 0 )
749  {
750  return VectorReadImpl<false>( std::move( file ), std::move( chunks ), std::move( buffer ) ).Timeout( timeout );
751  }
752 
754  uint16_t timeout = 0 )
755  {
756  return VectorReadImpl<false>( std::move( file ), std::move( chunks ), nullptr ).Timeout( timeout );
757  }
758 
759  //----------------------------------------------------------------------------
761  //----------------------------------------------------------------------------
762  template<bool HasHndl>
763  class VectorWriteImpl: public FileOperation<VectorWriteImpl, HasHndl, Resp<void>,
764  Arg<ChunkList>>
765  {
766  public:
767 
768  //------------------------------------------------------------------------
770  //------------------------------------------------------------------------
772 
773  //------------------------------------------------------------------------
775  //------------------------------------------------------------------------
776  enum { ChunksArg };
777 
778  //------------------------------------------------------------------------
780  //------------------------------------------------------------------------
781  std::string ToString()
782  {
783  return "VectorWrite";
784  }
785 
786  protected:
787 
788  //------------------------------------------------------------------------
794  //------------------------------------------------------------------------
795  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
796  {
797  const ChunkList &chunks = std::get<ChunksArg>( this->args ).Get();
798  uint16_t timeout = pipelineTimeout < this->timeout ?
799  pipelineTimeout : this->timeout;
800  return this->file->VectorWrite( chunks, handler, timeout );
801  }
802  };
803 
804  //----------------------------------------------------------------------------
806  //----------------------------------------------------------------------------
808  uint16_t timeout = 0 )
809  {
810  return VectorWriteImpl<false>( std::move( file ), std::move( chunks ) ).Timeout( timeout );
811  }
812 
813  //----------------------------------------------------------------------------
815  //----------------------------------------------------------------------------
816  template<bool HasHndl>
817  class WriteVImpl: public FileOperation<WriteVImpl, HasHndl, Resp<void>, Arg<uint64_t>,
818  Arg<std::vector<iovec>>>
819  {
820  public:
821 
822  //------------------------------------------------------------------------
824  //------------------------------------------------------------------------
827 
828  //------------------------------------------------------------------------
830  //------------------------------------------------------------------------
831  enum { OffsetArg, IovArg };
832 
833  //------------------------------------------------------------------------
835  //------------------------------------------------------------------------
836  std::string ToString()
837  {
838  return "WriteV";
839  }
840 
841  protected:
842 
843  //------------------------------------------------------------------------
849  //------------------------------------------------------------------------
850  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
851  {
852  uint64_t offset = std::get<OffsetArg>( this->args ).Get();
853  std::vector<iovec> &stdiov = std::get<IovArg>( this->args ).Get();
854  uint16_t timeout = pipelineTimeout < this->timeout ?
855  pipelineTimeout : this->timeout;
856 
857  int iovcnt = stdiov.size();
858  iovec iov[iovcnt];
859  for( size_t i = 0; i < stdiov.size(); ++i )
860  {
861  iov[i].iov_base = stdiov[i].iov_base;
862  iov[i].iov_len = stdiov[i].iov_len;
863  }
864 
865  return this->file->WriteV( offset, iov, iovcnt, handler, timeout );
866  }
867  };
868 
869  //----------------------------------------------------------------------------
871  //----------------------------------------------------------------------------
873  Arg<std::vector<iovec>> iov, uint16_t timeout = 0 )
874  {
875  return WriteVImpl<false>( std::move( file ), std::move( offset ),
876  std::move( iov ) ).Timeout( timeout );
877  }
878 
879  //----------------------------------------------------------------------------
881  //----------------------------------------------------------------------------
882  template<bool HasHndl>
883  class FcntlImpl: public FileOperation<FcntlImpl, HasHndl, Resp<Buffer>, Arg<Buffer>>
884  {
885  public:
886 
887  //------------------------------------------------------------------------
889  //------------------------------------------------------------------------
891 
892  //------------------------------------------------------------------------
894  //------------------------------------------------------------------------
895  enum { BufferArg };
896 
897  //------------------------------------------------------------------------
899  //------------------------------------------------------------------------
900  std::string ToString()
901  {
902  return "Fcntl";
903  }
904 
905  protected:
906 
907  //------------------------------------------------------------------------
913  //------------------------------------------------------------------------
914  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
915  {
916  Buffer &arg = std::get<BufferArg>( this->args ).Get();
917  uint16_t timeout = pipelineTimeout < this->timeout ?
918  pipelineTimeout : this->timeout;
919  return this->file->Fcntl( arg, handler, timeout );
920  }
921  };
923 
924  //----------------------------------------------------------------------------
926  //----------------------------------------------------------------------------
927  template<bool HasHndl>
928  class VisaImpl: public FileOperation<VisaImpl, HasHndl, Resp<Buffer>>
929  {
930  public:
931 
932  //------------------------------------------------------------------------
934  //------------------------------------------------------------------------
936 
937  //------------------------------------------------------------------------
939  //------------------------------------------------------------------------
940  std::string ToString()
941  {
942  return "Visa";
943  }
944 
945  protected:
946 
947  //------------------------------------------------------------------------
953  //------------------------------------------------------------------------
954  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
955  {
956  uint16_t timeout = pipelineTimeout < this->timeout ?
957  pipelineTimeout : this->timeout;
958  return this->file->Visa( handler, timeout );
959  }
960  };
962 
963  //----------------------------------------------------------------------------
965  //----------------------------------------------------------------------------
966  template<bool HasHndl>
967  class SetXAttrImpl: public FileOperation<SetXAttrImpl, HasHndl, Resp<void>,
968  Arg<std::string>, Arg<std::string>>
969  {
970  public:
971 
972  //------------------------------------------------------------------------
974  //------------------------------------------------------------------------
977 
978  //------------------------------------------------------------------------
980  //------------------------------------------------------------------------
981  enum { NameArg, ValueArg };
982 
983  //------------------------------------------------------------------------
985  //------------------------------------------------------------------------
986  std::string ToString()
987  {
988  return "SetXAttrImpl";
989  }
990 
991  protected:
992 
993  //------------------------------------------------------------------------
999  //------------------------------------------------------------------------
1000  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
1001  {
1002  std::string &name = std::get<NameArg>( this->args ).Get();
1003  std::string &value = std::get<ValueArg>( this->args ).Get();
1004  // wrap the arguments with a vector
1005  std::vector<xattr_t> attrs;
1006  attrs.push_back( xattr_t( name, value ) );
1007  // wrap the PipelineHandler so the response gets unpacked properly
1009  uint16_t timeout = pipelineTimeout < this->timeout ?
1010  pipelineTimeout : this->timeout;
1011  XRootDStatus st = this->file->SetXAttr( attrs, h, timeout );
1012  if( !st.IsOK() ) delete h;
1013  return st;
1014  }
1015  };
1016 
1017  //----------------------------------------------------------------------------
1020  //----------------------------------------------------------------------------
1022  {
1023  return SetXAttrImpl<false>( std::move( file ), std::move( name ), std::move( value ) );
1024  }
1025 
1026  //----------------------------------------------------------------------------
1028  //----------------------------------------------------------------------------
1029  template<bool HasHndl>
1030  class SetXAttrBulkImpl: public FileOperation<SetXAttrBulkImpl, HasHndl,
1031  Resp<std::vector<XAttrStatus>>, Arg<std::vector<xattr_t>>>
1032  {
1033  public:
1034 
1035  //------------------------------------------------------------------------
1037  //------------------------------------------------------------------------
1040 
1041  //------------------------------------------------------------------------
1043  //------------------------------------------------------------------------
1044  enum { AttrsArg };
1045 
1046  //------------------------------------------------------------------------
1048  //------------------------------------------------------------------------
1049  std::string ToString()
1050  {
1051  return "SetXAttrBulkImpl";
1052  }
1053 
1054 
1055  protected:
1056 
1057  //------------------------------------------------------------------------
1063  //------------------------------------------------------------------------
1064  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
1065  {
1066  std::vector<xattr_t> &attrs = std::get<AttrsArg>( this->args ).Get();
1067  uint16_t timeout = pipelineTimeout < this->timeout ?
1068  pipelineTimeout : this->timeout;
1069  return this->file->SetXAttr( attrs, handler, timeout );
1070  }
1071  };
1072 
1073  //----------------------------------------------------------------------------
1076  //----------------------------------------------------------------------------
1077  inline SetXAttrBulkImpl<false> SetXAttr( Ctx<File> file, Arg<std::vector<xattr_t>> attrs )
1078  {
1079  return SetXAttrBulkImpl<false>( std::move( file ), std::move( attrs ) );
1080  }
1081 
1082  //----------------------------------------------------------------------------
1084  //----------------------------------------------------------------------------
1085  template<bool HasHndl>
1086  class GetXAttrImpl: public FileOperation<GetXAttrImpl, HasHndl, Resp<std::string>,
1087  Arg<std::string>>
1088  {
1089  public:
1090 
1091  //------------------------------------------------------------------------
1093  //------------------------------------------------------------------------
1096 
1097  //------------------------------------------------------------------------
1099  //------------------------------------------------------------------------
1100  enum { NameArg };
1101 
1102  //------------------------------------------------------------------------
1104  //------------------------------------------------------------------------
1105  std::string ToString()
1106  {
1107  return "GetXAttrImpl";
1108  }
1109 
1110  protected:
1111 
1112  //------------------------------------------------------------------------
1118  //------------------------------------------------------------------------
1119  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
1120  {
1121  std::string &name = std::get<NameArg>( this->args ).Get();
1122  // wrap the argument with a vector
1123  std::vector<std::string> attrs;
1124  attrs.push_back( name );
1125  // wrap the PipelineHandler so the response gets unpacked properly
1126  UnpackXAttr *h = new UnpackXAttr( handler );
1127  uint16_t timeout = pipelineTimeout < this->timeout ?
1128  pipelineTimeout : this->timeout;
1129  XRootDStatus st = this->file->GetXAttr( attrs, h, timeout );
1130  if( !st.IsOK() ) delete h;
1131  return st;
1132  }
1133  };
1134 
1135  //----------------------------------------------------------------------------
1138  //----------------------------------------------------------------------------
1140  {
1141  return GetXAttrImpl<false>( std::move( file ), std::move( name ) );
1142  }
1143 
1144  //----------------------------------------------------------------------------
1146  //----------------------------------------------------------------------------
1147  template<bool HasHndl>
1148  class GetXAttrBulkImpl: public FileOperation<GetXAttrBulkImpl, HasHndl, Resp<std::vector<XAttr>>,
1149  Arg<std::vector<std::string>>>
1150  {
1151  public:
1152 
1153  //------------------------------------------------------------------------
1155  //------------------------------------------------------------------------
1158 
1159  //------------------------------------------------------------------------
1161  //------------------------------------------------------------------------
1162  enum { NamesArg };
1163 
1164  //------------------------------------------------------------------------
1166  //------------------------------------------------------------------------
1167  std::string ToString()
1168  {
1169  return "GetXAttrBulkImpl";
1170  }
1171 
1172 
1173  protected:
1174 
1175  //------------------------------------------------------------------------
1181  //------------------------------------------------------------------------
1182  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
1183  {
1184  std::vector<std::string> &attrs = std::get<NamesArg>( this->args ).Get();
1185  uint16_t timeout = pipelineTimeout < this->timeout ?
1186  pipelineTimeout : this->timeout;
1187  return this->file->GetXAttr( attrs, handler, timeout );
1188  }
1189  };
1190 
1191  //----------------------------------------------------------------------------
1194  //----------------------------------------------------------------------------
1195  inline GetXAttrBulkImpl<false> GetXAttr( Ctx<File> file, Arg<std::vector<std::string>> attrs )
1196  {
1197  return GetXAttrBulkImpl<false>( std::move( file ), std::move( attrs ) );
1198  }
1199 
1200  //----------------------------------------------------------------------------
1202  //----------------------------------------------------------------------------
1203  template<bool HasHndl>
1204  class DelXAttrImpl: public FileOperation<DelXAttrImpl, HasHndl, Resp<void>,
1205  Arg<std::string>>
1206  {
1207  public:
1208 
1209  //------------------------------------------------------------------------
1211  //------------------------------------------------------------------------
1213 
1214  //------------------------------------------------------------------------
1216  //------------------------------------------------------------------------
1217  enum { NameArg };
1218 
1219  //------------------------------------------------------------------------
1221  //------------------------------------------------------------------------
1222  std::string ToString()
1223  {
1224  return "DelXAttrImpl";
1225  }
1226 
1227  protected:
1228 
1229  //------------------------------------------------------------------------
1235  //------------------------------------------------------------------------
1236  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
1237  {
1238  std::string &name = std::get<NameArg>( this->args ).Get();
1239  // wrap the argument with a vector
1240  std::vector<std::string> attrs;
1241  attrs.push_back( name );
1242  // wrap the PipelineHandler so the response gets unpacked properly
1244  uint16_t timeout = pipelineTimeout < this->timeout ?
1245  pipelineTimeout : this->timeout;
1246  XRootDStatus st = this->file->DelXAttr( attrs, h, timeout );
1247  if( !st.IsOK() ) delete h;
1248  return st;
1249  }
1250  };
1251 
1252  //----------------------------------------------------------------------------
1255  //----------------------------------------------------------------------------
1257  {
1258  return DelXAttrImpl<false>( std::move( file ), std::move( name ) );
1259  }
1260 
1261  //----------------------------------------------------------------------------
1263  //----------------------------------------------------------------------------
1264  template<bool HasHndl>
1265  class DelXAttrBulkImpl: public FileOperation<DelXAttrBulkImpl, HasHndl,
1266  Resp<std::vector<XAttrStatus>>, Arg<std::vector<std::string>>>
1267  {
1268  public:
1269 
1270  //------------------------------------------------------------------------
1272  //------------------------------------------------------------------------
1275 
1276  //------------------------------------------------------------------------
1278  //------------------------------------------------------------------------
1279  enum { NamesArg };
1280 
1281  //------------------------------------------------------------------------
1283  //------------------------------------------------------------------------
1284  std::string ToString()
1285  {
1286  return "DelXAttrBulkImpl";
1287  }
1288 
1289 
1290  protected:
1291 
1292  //------------------------------------------------------------------------
1298  //------------------------------------------------------------------------
1299  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
1300  {
1301  std::vector<std::string> &attrs = std::get<NamesArg>( this->args ).Get();
1302  uint16_t timeout = pipelineTimeout < this->timeout ?
1303  pipelineTimeout : this->timeout;
1304  return this->file->DelXAttr( attrs, handler, timeout );
1305  }
1306  };
1307 
1308  //----------------------------------------------------------------------------
1311  //----------------------------------------------------------------------------
1312  inline DelXAttrBulkImpl<false> DelXAttr( Ctx<File> file, Arg<std::vector<std::string>> attrs )
1313  {
1314  return DelXAttrBulkImpl<false>( std::move( file ), std::move( attrs ) );
1315  }
1316 
1317  //----------------------------------------------------------------------------
1319  //----------------------------------------------------------------------------
1320  template<bool HasHndl>
1321  class ListXAttrImpl: public FileOperation<ListXAttrImpl, HasHndl,
1322  Resp<std::vector<XAttr>>>
1323  {
1324  public:
1325 
1326  //------------------------------------------------------------------------
1328  //------------------------------------------------------------------------
1330 
1331  //------------------------------------------------------------------------
1333  //------------------------------------------------------------------------
1334  std::string ToString()
1335  {
1336  return "ListXAttrImpl";
1337  }
1338 
1339 
1340  protected:
1341 
1342  //------------------------------------------------------------------------
1348  //------------------------------------------------------------------------
1349  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
1350  {
1351  uint16_t timeout = pipelineTimeout < this->timeout ?
1352  pipelineTimeout : this->timeout;
1353  return this->file->ListXAttr( handler, timeout );
1354  }
1355  };
1356 
1357  //----------------------------------------------------------------------------
1360  //----------------------------------------------------------------------------
1362  {
1363  return ListXAttrImpl<false>( std::move( file ) );
1364  }
1365 }
1366 
1367 #endif // __XRD_CL_FILE_OPERATIONS_HH__
1368 
int open(const char *path, int oflag,...)
int Mode
bool Create
Binary blob representation.
Definition: XrdClBuffer.hh:34
Close operation (.
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
uint16_t timeout
Operation timeout.
Derived< HasHndl > Timeout(uint16_t timeout)
Set operation timeout.
DelXAttr bulk operation (.
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
DelXAttr operation (.
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Fcntl operation (.
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
FileOperation(Ctx< File > f, Arguments... args)
virtual ~FileOperation()
Destructor.
FileOperation(FileOperation< Derived, from, Response, Arguments... > &&op)
Ctx< File > file
The file object itself.
GetXAttr bulk operation (.
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
GetXAttr operation (.
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
ListXAttr bulk operation (.
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Open operation (.
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
OpenImpl(OpenImpl< from > &&open)
OpenImpl< true > operator>>(Hdlr &&hdlr)
std::string ToString()
OpenImpl(Ctx< File > f, Arg< std::string > url, Arg< OpenFlags::Flags > flags, Arg< Access::Mode > mode=Access::None)
Constructor (.
std::unique_ptr< PipelineHandler > handler
Operation handler.
PgRead operation (.
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
PgWrite operation (.
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Read operation (.
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
std::string ToString()
Handle an async response.
SetXAttr bulk operation (.
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
SetXAttr operation (.
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Stat operation (.
std::string ToString()
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Object stat info.
Sync operation (.
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
std::string ToString()
Truncate operation (.
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Helper class for unpacking single XAttrStatus from bulk response.
Helper class for unpacking single XAttr from bulk response.
VectorRead operation (.
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
VectorWrite operation (.
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Visa operation (.
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
std::string ToString()
Write operation (.
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
WriteV operation (.
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
VectorWriteImpl< false > VectorWrite(Ctx< File > file, Arg< ChunkList > chunks, uint16_t timeout=0)
Factory for creating VectorWriteImpl objects.
DelXAttrImpl< false > DelXAttr(Ctx< File > file, Arg< std::string > name)
StatImpl< false > Stat(Ctx< File > file, Arg< bool > force, uint16_t timeout=0)
WriteImpl< false > Write(Ctx< File > file, Arg< uint64_t > offset, Arg< uint32_t > size, Arg< const void * > buffer, uint16_t timeout=0)
Factory for creating WriteImpl objects.
SetXAttrImpl< false > SetXAttr(Ctx< File > file, Arg< std::string > name, Arg< std::string > value)
ReadImpl< false > Read(Ctx< File > file, Arg< uint64_t > offset, Arg< uint32_t > size, Arg< void * > buffer, uint16_t timeout=0)
Factory for creating ReadImpl objects.
ReadImpl< false > RdWithRsp< ChunkInfo >(Ctx< File > file, Arg< uint64_t > offset, Arg< uint32_t > size, Arg< void * > buffer, uint16_t timeout)
GetXAttrImpl< false > GetXAttr(Ctx< File > file, Arg< std::string > name)
OpenImpl< false > Open(Ctx< File > file, Arg< std::string > url, Arg< OpenFlags::Flags > flags, Arg< Access::Mode > mode=Access::None, uint16_t timeout=0)
Factory for creating ReadImpl objects.
FcntlImpl< false > Fcntl
PgWriteImpl< false > PgWrite(Ctx< File > file, Arg< uint64_t > offset, Arg< uint32_t > size, Arg< void * > buffer, Arg< std::vector< uint32_t >> cksums, uint16_t timeout=0)
Factory for creating PgReadImpl objects.
VisaImpl< false > Visa
SyncImpl< false > Sync(Ctx< File > file, uint16_t timeout=0)
Factory for creating SyncImpl objects.
std::tuple< std::string, std::string > xattr_t
Extended attribute key - value pair.
VectorReadImpl< false > VectorRead(Ctx< File > file, Arg< ChunkList > chunks, Arg< void * > buffer, uint16_t timeout=0)
Factory for creating VectorReadImpl objects.
std::vector< ChunkInfo > ChunkList
List of chunks.
ReadTrait< RSP >::RET RdWithRsp(Ctx< File > file, Arg< uint64_t > offset, Arg< uint32_t > size, Arg< void * > buffer, uint16_t timeout=0)
TruncateImpl< false > Truncate(Ctx< File > file, Arg< uint64_t > size, uint16_t timeout)
ListXAttrImpl< false > ListXAttr(Ctx< File > file)
WriteVImpl< false > WriteV(Ctx< File > file, Arg< uint64_t > offset, Arg< std::vector< iovec >> iov, uint16_t timeout=0)
Factory for creating WriteVImpl objects.
PgReadImpl< false > RdWithRsp< PageInfo >(Ctx< File > file, Arg< uint64_t > offset, Arg< uint32_t > size, Arg< void * > buffer, uint16_t timeout)
PgReadImpl< false > PgRead(Ctx< File > file, Arg< uint64_t > offset, Arg< uint32_t > size, Arg< void * > buffer, uint16_t timeout=0)
Factory for creating PgReadImpl objects.
CloseImpl< false > Close(Ctx< File > file, uint16_t timeout=0)
Factory for creating CloseImpl objects.
RdWithRsp: factory for creating ReadImpl/PgReadImpl objects.
Access mode.
Mode
Access mode.
Describe a data chunk for vector read.
Utility class for storing a pointer to operation context.
Definition: XrdClCtx.hh:39
Open flags, may be or'd when appropriate.
Flags
Open flags, may be or'd when appropriate.
bool IsOK() const
We're fine.
Definition: XrdClStatus.hh:124