00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef __XRD_CL_FILE_SYSTEM_OPERATIONS_HH__
00027 #define __XRD_CL_FILE_SYSTEM_OPERATIONS_HH__
00028
00029 #include "XrdCl/XrdClFileSystem.hh"
00030 #include "XrdCl/XrdClOperations.hh"
00031 #include "XrdCl/XrdClOperationHandlers.hh"
00032
00033 namespace XrdCl
00034 {
00035
00036
00042
00043 template<template<bool> class Derived, bool HasHndl, typename Response, typename ... Args>
00044 class FileSystemOperation: public ConcreteOperation<Derived, HasHndl, Response, Args...>
00045 {
00046
00047 template<template<bool> class, bool, typename, typename ...> friend class FileSystemOperation;
00048
00049 public:
00050
00055
00056 FileSystemOperation( FileSystem *fs, Args... args): ConcreteOperation<Derived,
00057 false, Response, Args...>( std::move( args )... ), filesystem(fs)
00058 {
00059 }
00060
00061
00066
00067 FileSystemOperation( FileSystem &fs, Args... args): FileSystemOperation( &fs, std::move( args )... )
00068 {
00069 }
00070
00071
00077
00078 template<bool from>
00079 FileSystemOperation( FileSystemOperation<Derived, from, Response, Args...> && op ):
00080 ConcreteOperation<Derived, HasHndl, Response, Args...>( std::move( op ) ), filesystem( op.filesystem )
00081 {
00082 }
00083
00084
00086
00087 virtual ~FileSystemOperation()
00088 {
00089 }
00090
00091 protected:
00092
00093
00095
00096 FileSystem *filesystem;
00097 };
00098
00099
00101
00102 template<bool HasHndl>
00103 class LocateImpl: public FileSystemOperation<LocateImpl, HasHndl, Resp<LocationInfo>,
00104 Arg<std::string>, Arg<OpenFlags::Flags>>
00105 {
00106 public:
00107
00108
00110
00111 using FileSystemOperation<LocateImpl, HasHndl, Resp<LocationInfo>, Arg<std::string>,
00112 Arg<OpenFlags::Flags>>::FileSystemOperation;
00113
00114
00116
00117 enum { PathArg, FlagsArg };
00118
00119
00121
00122 std::string ToString()
00123 {
00124 return "Locate";
00125 }
00126
00127 protected:
00128
00129
00135
00136 XRootDStatus RunImpl()
00137 {
00138 try
00139 {
00140 std::string path = std::get<PathArg>( this->args ).Get();
00141 OpenFlags::Flags flags = std::get<FlagsArg>( this->args ).Get();
00142 return this->filesystem->Locate( path, flags, this->handler.get() );
00143 }
00144 catch( const PipelineException& ex )
00145 {
00146 return ex.GetError();
00147 }
00148 catch( const std::exception& ex )
00149 {
00150 return XRootDStatus( stError, ex.what() );
00151 }
00152 }
00153 };
00154 typedef LocateImpl<false> Locate;
00155
00156
00158
00159 template<bool HasHndl>
00160 class DeepLocateImpl: public FileSystemOperation<DeepLocateImpl, HasHndl,
00161 Resp<LocationInfo>, Arg<std::string>, Arg<OpenFlags::Flags>>
00162 {
00163 public:
00164
00165
00167
00168 using FileSystemOperation<DeepLocateImpl, HasHndl, Resp<LocationInfo>, Arg<std::string>,
00169 Arg<OpenFlags::Flags>>::FileSystemOperation;
00170
00171
00173
00174 enum { PathArg, FlagsArg };
00175
00176
00178
00179 std::string ToString()
00180 {
00181 return "DeepLocate";
00182 }
00183
00184 protected:
00185
00186
00192
00193 XRootDStatus RunImpl()
00194 {
00195 try
00196 {
00197 std::string path = std::get<PathArg>( this->args ).Get();
00198 OpenFlags::Flags flags = std::get<FlagsArg>( this->args ).Get();
00199 return this->filesystem->DeepLocate( path, flags, this->handler.get() );
00200 }
00201 catch( const PipelineException& ex )
00202 {
00203 return ex.GetError();
00204 }
00205 catch( const std::exception& ex )
00206 {
00207 return XRootDStatus( stError, ex.what() );
00208 }
00209 }
00210 };
00211 typedef DeepLocateImpl<false> DeepLocate;
00212
00213
00215
00216 template<bool HasHndl>
00217 class MvImpl: public FileSystemOperation<MvImpl, HasHndl, Resp<void>, Arg<std::string>,
00218 Arg<std::string>>
00219 {
00220 public:
00221
00222
00224
00225 using FileSystemOperation<MvImpl, HasHndl, Resp<void>, Arg<std::string>,
00226 Arg<std::string>>::FileSystemOperation;
00227
00228
00230
00231 enum { SourceArg, DestArg };
00232
00233
00235
00236 std::string ToString()
00237 {
00238 return "Mv";
00239 }
00240
00241 protected:
00242
00243
00249
00250 XRootDStatus RunImpl()
00251 {
00252 try
00253 {
00254 std::string source = std::get<SourceArg>( this->args ).Get();
00255 std::string dest = std::get<DestArg>( this->args ).Get();
00256 return this->filesystem->Mv( source, dest, this->handler.get() );
00257 }
00258 catch( const PipelineException& ex )
00259 {
00260 return ex.GetError();
00261 }
00262 catch( const std::exception& ex )
00263 {
00264 return XRootDStatus( stError, ex.what() );
00265 }
00266 }
00267 };
00268 typedef MvImpl<false> Mv;
00269
00270
00272
00273 template<bool HasHndl>
00274 class QueryImpl: public FileSystemOperation<QueryImpl, HasHndl, Resp<Buffer>,
00275 Arg<QueryCode::Code>, Arg<Buffer>>
00276 {
00277 public:
00278
00279
00281
00282 using FileSystemOperation<QueryImpl, HasHndl, Resp<Buffer>, Arg<QueryCode::Code>,
00283 Arg<Buffer>>::FileSystemOperation;
00284
00285
00287
00288 enum { QueryCodeArg, BufferArg };
00289
00290
00292
00293 std::string ToString()
00294 {
00295 return "Query";
00296 }
00297
00298 protected:
00299
00300
00306
00307 XRootDStatus RunImpl()
00308 {
00309 try
00310 {
00311 QueryCode::Code queryCode = std::get<QueryCodeArg>( this->args ).Get();
00312 const Buffer buffer( std::get<BufferArg>( this->args ).Get() );
00313 return this->filesystem->Query( queryCode, buffer, this->handler.get() );
00314 }
00315 catch( const PipelineException& ex )
00316 {
00317 return ex.GetError();
00318 }
00319 catch( const std::exception& ex )
00320 {
00321 return XRootDStatus( stError, ex.what() );
00322 }
00323 }
00324 };
00325 typedef QueryImpl<false> Query;
00326
00327
00329
00330 template<bool HasHndl>
00331 class TruncateFsImpl: public FileSystemOperation<TruncateFsImpl, HasHndl, Resp<void>,
00332 Arg<std::string>, Arg<uint64_t>>
00333 {
00334 public:
00335
00336
00338
00339 using FileSystemOperation<TruncateFsImpl, HasHndl, Resp<void>, Arg<std::string>,
00340 Arg<uint64_t>>::FileSystemOperation;
00341
00342
00344
00345 enum { PathArg, SizeArg };
00346
00347
00349
00350 std::string ToString()
00351 {
00352 return "Truncate";
00353 }
00354
00355 protected:
00356
00357
00363
00364 XRootDStatus RunImpl()
00365 {
00366 try
00367 {
00368 std::string path = std::get<PathArg>( this->args ).Get();
00369 uint64_t size = std::get<SizeArg>( this->args ).Get();
00370 return this->filesystem->Truncate( path, size, this->handler.get() );
00371 }
00372 catch( const PipelineException& ex )
00373 {
00374 return ex.GetError();
00375 }
00376 catch( const std::exception& ex )
00377 {
00378 return XRootDStatus( stError, ex.what() );
00379 }
00380 }
00381 };
00382
00383 TruncateFsImpl<false> Truncate( FileSystem *fs, Arg<std::string> path, Arg<uint64_t> size )
00384 {
00385 return TruncateFsImpl<false>( fs, std::move( path ), std::move( size ) );
00386 }
00387
00388 TruncateFsImpl<false> Truncate( FileSystem &fs, Arg<std::string> path, Arg<uint64_t> size )
00389 {
00390 return TruncateFsImpl<false>( fs, std::move( path ), std::move( size ) );
00391 }
00392
00393
00395
00396 template<bool HasHndl>
00397 class RmImpl: public FileSystemOperation<RmImpl, HasHndl, Resp<void>, Arg<std::string>>
00398 {
00399 public:
00400
00401
00403
00404 using FileSystemOperation<RmImpl, HasHndl, Resp<void>, Arg<std::string>>::FileSystemOperation;
00405
00406
00408
00409 enum { PathArg };
00410
00411
00413
00414 std::string ToString()
00415 {
00416 return "Rm";
00417 }
00418
00419 protected:
00420
00421
00427
00428 XRootDStatus RunImpl()
00429 {
00430 try
00431 {
00432 std::string path = std::get<PathArg>( this->args ).Get();
00433 return this->filesystem->Rm( path, this->handler.get() );
00434 }
00435 catch( const PipelineException& ex )
00436 {
00437 return ex.GetError();
00438 }
00439 catch( const std::exception& ex )
00440 {
00441 return XRootDStatus( stError, ex.what() );
00442 }
00443 }
00444 };
00445 typedef RmImpl<false> Rm;
00446
00447
00449
00450 template<bool HasHndl>
00451 class MkDirImpl: public FileSystemOperation<MkDirImpl, HasHndl, Resp<void>,
00452 Arg<std::string>, Arg<MkDirFlags::Flags>, Arg<Access::Mode>>
00453 {
00454 public:
00455
00456
00458
00459 using FileSystemOperation<MkDirImpl, HasHndl, Resp<void>, Arg<std::string>,
00460 Arg<MkDirFlags::Flags>, Arg<Access::Mode>>::FileSystemOperation;
00461
00462
00464
00465 enum { PathArg, FlagsArg, ModeArg };
00466
00467
00469
00470 std::string ToString()
00471 {
00472 return "MkDir";
00473 }
00474
00475 protected:
00476
00477
00483
00484 XRootDStatus RunImpl()
00485 {
00486 try
00487 {
00488 std::string path = std::get<PathArg>( this->args ).Get();
00489 MkDirFlags::Flags flags = std::get<FlagsArg>( this->args ).Get();
00490 Access::Mode mode = std::get<ModeArg>( this->args ).Get();
00491 return this->filesystem->MkDir( path, flags, mode, this->handler.get() );
00492 }
00493 catch( const PipelineException& ex )
00494 {
00495 return ex.GetError();
00496 }
00497 catch( const std::exception& ex )
00498 {
00499 return XRootDStatus( stError, ex.what() );
00500 }
00501 }
00502 };
00503 typedef MkDirImpl<false> MkDir;
00504
00505
00507
00508 template<bool HasHndl>
00509 class RmDirImpl: public FileSystemOperation<RmDirImpl, HasHndl, Resp<void>,
00510 Arg<std::string>>
00511 {
00512 public:
00513
00514
00516
00517 using FileSystemOperation<RmDirImpl, HasHndl, Resp<void>, Arg<std::string>>::FileSystemOperation;
00518
00519
00521
00522 enum { PathArg };
00523
00524
00526
00527 std::string ToString()
00528 {
00529 return "RmDir";
00530 }
00531
00532 protected:
00533
00534
00540
00541 XRootDStatus RunImpl()
00542 {
00543 try
00544 {
00545 std::string path = std::get<PathArg>( this->args ).Get();
00546 return this->filesystem->RmDir( path, this->handler.get() );
00547 }
00548 catch( const PipelineException& ex )
00549 {
00550 return ex.GetError();
00551 }
00552 catch( const std::exception& ex )
00553 {
00554 return XRootDStatus( stError, ex.what() );
00555 }
00556 }
00557 };
00558 typedef RmDirImpl<false> RmDir;
00559
00560
00562
00563 template<bool HasHndl>
00564 class ChModImpl: public FileSystemOperation<ChModImpl, HasHndl, Resp<void>,
00565 Arg<std::string>, Arg<Access::Mode>>
00566 {
00567 public:
00568
00569
00571
00572 using FileSystemOperation<ChModImpl, HasHndl, Resp<void>, Arg<std::string>,
00573 Arg<Access::Mode>>::FileSystemOperation;
00574
00575
00577
00578 enum { PathArg, ModeArg };
00579
00580
00582
00583 std::string ToString()
00584 {
00585 return "ChMod";
00586 }
00587
00588 protected:
00589
00590
00596
00597 XRootDStatus RunImpl()
00598 {
00599 try
00600 {
00601 std::string path = std::get<PathArg>( this->args ).Get();
00602 Access::Mode mode = std::get<ModeArg>( this->args ).Get();
00603 return this->filesystem->ChMod( path, mode, this->handler.get() );
00604 }
00605 catch( const PipelineException& ex )
00606 {
00607 return ex.GetError();
00608 }
00609 catch( const std::exception& ex )
00610 {
00611 return XRootDStatus( stError, ex.what() );
00612 }
00613 }
00614 };
00615 typedef ChModImpl<false> ChMod;
00616
00617
00619
00620 template<bool HasHndl>
00621 class PingImpl: public FileSystemOperation<PingImpl, HasHndl, Resp<void>>
00622 {
00623 public:
00624
00625
00627
00628 using FileSystemOperation<PingImpl, HasHndl, Resp<void>>::FileSystemOperation;
00629
00630
00632
00633 std::string ToString()
00634 {
00635 return "Ping";
00636 }
00637
00638 protected:
00639
00640
00646
00647 XRootDStatus RunImpl()
00648 {
00649 return this->filesystem->Ping( this->handler.get() );
00650 }
00651 };
00652 typedef PingImpl<false> Ping;
00653
00654
00656
00657 template<bool HasHndl>
00658 class StatFsImpl: public FileSystemOperation<StatFsImpl, HasHndl, Resp<StatInfo>,
00659 Arg<std::string>>
00660 {
00661 public:
00662
00663
00665
00666 using FileSystemOperation<StatFsImpl, HasHndl, Resp<StatInfo>,
00667 Arg<std::string>>::FileSystemOperation;
00668
00669
00671
00672 enum { PathArg };
00673
00674
00676
00677 std::string ToString()
00678 {
00679 return "Stat";
00680 }
00681
00682 protected:
00683
00684
00690
00691 XRootDStatus RunImpl()
00692 {
00693 try
00694 {
00695 std::string path = std::get<PathArg>( this->args ).Get();
00696 return this->filesystem->RmDir( path, this->handler.get() );
00697 }
00698 catch( const PipelineException& ex )
00699 {
00700 return ex.GetError();
00701 }
00702 catch( const std::exception& ex )
00703 {
00704 return XRootDStatus( stError, ex.what() );
00705 }
00706 }
00707 };
00708
00709 StatFsImpl<false> Stat( FileSystem *fs, Arg<std::string> path )
00710 {
00711 return StatFsImpl<false>( fs, std::move( path ) );
00712 }
00713
00714 StatFsImpl<false> Stat( FileSystem &fs, Arg<std::string> path )
00715 {
00716 return StatFsImpl<false>( fs, std::move( path ) );
00717 }
00718
00719
00721
00722 template<bool HasHndl>
00723 class StatVFSImpl: public FileSystemOperation<StatVFSImpl, HasHndl,
00724 Resp<StatInfoVFS>, Arg<std::string>>
00725 {
00726 public:
00727
00728
00730
00731 using FileSystemOperation<StatVFSImpl, HasHndl, Resp<StatInfoVFS>,
00732 Arg<std::string>>::FileSystemOperation;
00733
00734
00736
00737 enum { PathArg };
00738
00739
00741
00742 std::string ToString()
00743 {
00744 return "StatVFS";
00745 }
00746
00747 protected:
00748
00749
00755
00756 XRootDStatus RunImpl()
00757 {
00758 try
00759 {
00760 std::string path = std::get<PathArg>( this->args ).Get();
00761 return this->filesystem->StatVFS( path, this->handler.get() );
00762 }
00763 catch( const PipelineException& ex )
00764 {
00765 return ex.GetError();
00766 }
00767 catch( const std::exception& ex )
00768 {
00769 return XRootDStatus( stError, ex.what() );
00770 }
00771 }
00772 };
00773 typedef StatVFSImpl<false> StatVFS;
00774
00775
00777
00778 template<bool HasHndl>
00779 class ProtocolImpl: public FileSystemOperation<ProtocolImpl, HasHndl,
00780 Resp<ProtocolInfo>>
00781 {
00782 public:
00783
00784
00786
00787 using FileSystemOperation<ProtocolImpl, HasHndl, Resp<ProtocolInfo>>::FileSystemOperation;
00788
00789
00791
00792 std::string ToString()
00793 {
00794 return "Protocol";
00795 }
00796
00797 protected:
00798
00799
00805
00806 XRootDStatus RunImpl()
00807 {
00808 return this->filesystem->Protocol( this->handler.get() );
00809 }
00810 };
00811 typedef ProtocolImpl<false> Protocol;
00812
00813
00815
00816 template<bool HasHndl>
00817 class DirListImpl: public FileSystemOperation<DirListImpl, HasHndl, Resp<DirectoryList>,
00818 Arg<std::string>, Arg<DirListFlags::Flags>>
00819 {
00820 public:
00821
00822
00824
00825 using FileSystemOperation<DirListImpl, HasHndl, Resp<DirectoryList>, Arg<std::string>,
00826 Arg<DirListFlags::Flags>>::FileSystemOperation;
00827
00828
00830
00831 enum { PathArg, FlagsArg };
00832
00833
00835
00836 std::string ToString()
00837 {
00838 return "DirList";
00839 }
00840
00841 protected:
00842
00843
00849
00850 XRootDStatus RunImpl()
00851 {
00852 try
00853 {
00854 std::string path = std::get<PathArg>( this->args ).Get();
00855 DirListFlags::Flags flags = std::get<FlagsArg>( this->args ).Get();
00856 return this->filesystem->DirList( path, flags, this->handler.get() );
00857 }
00858 catch( const PipelineException& ex )
00859 {
00860 return ex.GetError();
00861 }
00862 catch( const std::exception& ex )
00863 {
00864 return XRootDStatus( stError, ex.what() );
00865 }
00866 }
00867 };
00868 typedef DirListImpl<false> DirList;
00869
00870
00872
00873 template<bool HasHndl>
00874 class SendInfoImpl: public FileSystemOperation<SendInfoImpl, HasHndl, Resp<Buffer>,
00875 Arg<std::string>>
00876 {
00877 public:
00878
00879
00881
00882 using FileSystemOperation<SendInfoImpl, HasHndl, Resp<Buffer>,
00883 Arg<std::string>>::FileSystemOperation;
00884
00885
00887
00888 enum { InfoArg };
00889
00890
00892
00893 std::string ToString()
00894 {
00895 return "SendInfo";
00896 }
00897
00898 protected:
00899
00900
00906
00907 XRootDStatus RunImpl()
00908 {
00909 try
00910 {
00911 std::string info = std::get<InfoArg>( this->args ).Get();
00912 return this->filesystem->SendInfo( info, this->handler.get() );
00913 }
00914 catch( const PipelineException& ex )
00915 {
00916 return ex.GetError();
00917 }
00918 catch( const std::exception& ex )
00919 {
00920 return XRootDStatus( stError, ex.what() );
00921 }
00922 }
00923 };
00924 typedef SendInfoImpl<false> SendInfo;
00925
00926
00928
00929 template<bool HasHndl>
00930 class PrepareImpl: public FileSystemOperation<PrepareImpl, HasHndl, Resp<Buffer>,
00931 Arg<std::vector<std::string>>, Arg<PrepareFlags::Flags>, Arg<uint8_t>>
00932 {
00933 public:
00934
00935
00937
00938 using FileSystemOperation<PrepareImpl, HasHndl, Resp<Buffer>, Arg<std::vector<std::string>>,
00939 Arg<PrepareFlags::Flags>, Arg<uint8_t>>::FileSystemOperation;
00940
00941
00943
00944 enum { FileListArg, FlagsArg, PriorityArg };
00945
00946
00948
00949 std::string ToString()
00950 {
00951 return "Prepare";
00952 }
00953
00954 protected:
00955
00956
00962
00963 XRootDStatus RunImpl()
00964 {
00965 try
00966 {
00967 std::vector<std::string> fileList = std::get<FileListArg>( this->args ).Get();
00968 PrepareFlags::Flags flags = std::get<FlagsArg>( this->args ).Get();
00969 uint8_t priority = std::get<PriorityArg>( this->args ).Get();
00970 return this->filesystem->Prepare( fileList, flags, priority,
00971 this->handler.get() );
00972 }
00973 catch( const PipelineException& ex )
00974 {
00975 return ex.GetError();
00976 }
00977 catch( const std::exception& ex )
00978 {
00979 return XRootDStatus( stError, ex.what() );
00980 }
00981 }
00982 };
00983 typedef PrepareImpl<false> Prepare;
00984 }
00985
00986 #endif // __XRD_CL_FILE_SYSTEM_OPERATIONS_HH__