|
|
|||
File indexing completed on 2026-06-24 08:38:07
0001 //------------------------------------------------------------------------------ 0002 // Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN) 0003 // Author: Lukasz Janyst <ljanyst@cern.ch> 0004 //------------------------------------------------------------------------------ 0005 // XRootD is free software: you can redistribute it and/or modify 0006 // it under the terms of the GNU Lesser General Public License as published by 0007 // the Free Software Foundation, either version 3 of the License, or 0008 // (at your option) any later version. 0009 // 0010 // XRootD is distributed in the hope that it will be useful, 0011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 // GNU General Public License for more details. 0014 // 0015 // You should have received a copy of the GNU Lesser General Public License 0016 // along with XRootD. If not, see <http://www.gnu.org/licenses/>. 0017 //------------------------------------------------------------------------------ 0018 0019 #ifndef __XRD_CL_XROOTD_RESPONSES_HH__ 0020 #define __XRD_CL_XROOTD_RESPONSES_HH__ 0021 0022 #include "XrdCl/XrdClBuffer.hh" 0023 #include "XrdCl/XrdClStatus.hh" 0024 #include "XrdCl/XrdClURL.hh" 0025 #include "XrdCl/XrdClAnyObject.hh" 0026 #include "XProtocol/XProtocol.hh" 0027 0028 #include <string> 0029 #include <vector> 0030 #include <list> 0031 #include <ctime> 0032 #include <tuple> 0033 #include <memory> 0034 #include <functional> 0035 0036 #include <sys/uio.h> 0037 0038 namespace XrdCl 0039 { 0040 //---------------------------------------------------------------------------- 0041 //! Path location info 0042 //---------------------------------------------------------------------------- 0043 class LocationInfo 0044 { 0045 public: 0046 //------------------------------------------------------------------------ 0047 //! Describes the node type and file status for a given location 0048 //------------------------------------------------------------------------ 0049 enum LocationType 0050 { 0051 ManagerOnline, //!< manager node where the file is online 0052 ManagerPending, //!< manager node where the file is pending to be online 0053 ServerOnline, //!< server node where the file is online 0054 ServerPending //!< server node where the file is pending to be online 0055 }; 0056 0057 //------------------------------------------------------------------------ 0058 //! Describes the allowed access type for the file at given location 0059 //------------------------------------------------------------------------ 0060 enum AccessType 0061 { 0062 Read, //!< read access is allowed 0063 ReadWrite //!< write access is allowed 0064 }; 0065 0066 //------------------------------------------------------------------------ 0067 //! Location 0068 //------------------------------------------------------------------------ 0069 class Location 0070 { 0071 public: 0072 0073 //-------------------------------------------------------------------- 0074 //! Constructor 0075 //-------------------------------------------------------------------- 0076 Location( const std::string &address, 0077 LocationType type, 0078 AccessType access ): 0079 pAddress( address ), 0080 pType( type ), 0081 pAccess( access ) {} 0082 0083 //-------------------------------------------------------------------- 0084 //! Get address 0085 //-------------------------------------------------------------------- 0086 const std::string &GetAddress() const 0087 { 0088 return pAddress; 0089 } 0090 0091 //-------------------------------------------------------------------- 0092 //! Get location type 0093 //-------------------------------------------------------------------- 0094 LocationType GetType() const 0095 { 0096 return pType; 0097 } 0098 0099 //-------------------------------------------------------------------- 0100 //! Get access type 0101 //-------------------------------------------------------------------- 0102 AccessType GetAccessType() const 0103 { 0104 return pAccess; 0105 } 0106 0107 //-------------------------------------------------------------------- 0108 //! Check whether the location is a server 0109 //-------------------------------------------------------------------- 0110 bool IsServer() const 0111 { 0112 return pType == ServerOnline || pType == ServerPending; 0113 } 0114 0115 //-------------------------------------------------------------------- 0116 //! Check whether the location is a manager 0117 //-------------------------------------------------------------------- 0118 bool IsManager() const 0119 { 0120 return pType == ManagerOnline || pType == ManagerPending; 0121 } 0122 0123 private: 0124 std::string pAddress; 0125 LocationType pType; 0126 AccessType pAccess; 0127 }; 0128 0129 //------------------------------------------------------------------------ 0130 //! List of locations 0131 //------------------------------------------------------------------------ 0132 typedef std::vector<Location> LocationList; 0133 0134 //------------------------------------------------------------------------ 0135 //! Iterator over locations 0136 //------------------------------------------------------------------------ 0137 typedef LocationList::iterator Iterator; 0138 0139 //------------------------------------------------------------------------ 0140 //! Iterator over locations 0141 //------------------------------------------------------------------------ 0142 typedef LocationList::const_iterator ConstIterator; 0143 0144 //------------------------------------------------------------------------ 0145 //! Constructor 0146 //------------------------------------------------------------------------ 0147 LocationInfo(); 0148 0149 //------------------------------------------------------------------------ 0150 //! Get number of locations 0151 //------------------------------------------------------------------------ 0152 uint32_t GetSize() const 0153 { 0154 return pLocations.size(); 0155 } 0156 0157 //------------------------------------------------------------------------ 0158 //! Get the location at index 0159 //------------------------------------------------------------------------ 0160 Location &At( uint32_t index ) 0161 { 0162 return pLocations[index]; 0163 } 0164 0165 //------------------------------------------------------------------------ 0166 //! Get the location begin iterator 0167 //------------------------------------------------------------------------ 0168 Iterator Begin() 0169 { 0170 return pLocations.begin(); 0171 } 0172 0173 //------------------------------------------------------------------------ 0174 //! Get the location begin iterator 0175 //------------------------------------------------------------------------ 0176 ConstIterator Begin() const 0177 { 0178 return pLocations.begin(); 0179 } 0180 0181 //------------------------------------------------------------------------ 0182 //! Get the location end iterator 0183 //------------------------------------------------------------------------ 0184 Iterator End() 0185 { 0186 return pLocations.end(); 0187 } 0188 0189 //------------------------------------------------------------------------ 0190 //! Get the location end iterator 0191 //------------------------------------------------------------------------ 0192 ConstIterator End() const 0193 { 0194 return pLocations.end(); 0195 } 0196 0197 //------------------------------------------------------------------------ 0198 //! Add a location 0199 //------------------------------------------------------------------------ 0200 void Add( const Location &location ) 0201 { 0202 pLocations.push_back( location ); 0203 } 0204 0205 //------------------------------------------------------------------------ 0206 //! Parse server response and fill up the object 0207 //------------------------------------------------------------------------ 0208 bool ParseServerResponse( const char *data ); 0209 0210 private: 0211 bool ProcessLocation( std::string &location ); 0212 LocationList pLocations; 0213 }; 0214 0215 //---------------------------------------------------------------------------- 0216 //! Request status 0217 //---------------------------------------------------------------------------- 0218 class XRootDStatus: public Status 0219 { 0220 public: 0221 //------------------------------------------------------------------------ 0222 //! Constructor 0223 //------------------------------------------------------------------------ 0224 XRootDStatus( uint16_t st = 0, 0225 uint16_t code = 0, 0226 uint32_t errN = 0, 0227 const std::string &message = "" ): 0228 Status( st, code, errN ), 0229 pMessage( message ) {} 0230 0231 //------------------------------------------------------------------------ 0232 //! Constructor 0233 //------------------------------------------------------------------------ 0234 XRootDStatus( const Status &st, 0235 const std::string &message = "" ): 0236 Status( st ), 0237 pMessage( message ) {} 0238 0239 //------------------------------------------------------------------------ 0240 //! Get error message 0241 //------------------------------------------------------------------------ 0242 const std::string &GetErrorMessage() const 0243 { 0244 return pMessage; 0245 } 0246 0247 //------------------------------------------------------------------------ 0248 //! Set the error message 0249 //------------------------------------------------------------------------ 0250 void SetErrorMessage( const std::string &message ) 0251 { 0252 pMessage = message; 0253 } 0254 0255 //------------------------------------------------------------------------ 0256 //! Convert to string 0257 //------------------------------------------------------------------------ 0258 std::string ToStr() const 0259 { 0260 if( code == errErrorResponse ) 0261 { 0262 std::ostringstream o; 0263 o << "[ERROR] Server responded with an error: [" << errNo << "] "; 0264 o << pMessage << std::endl; 0265 return o.str(); 0266 } 0267 std::string str = ToString(); 0268 if( !pMessage.empty() ) 0269 str += ": " + pMessage; 0270 return str; 0271 } 0272 0273 private: 0274 std::string pMessage; 0275 }; 0276 0277 //---------------------------------------------------------------------------- 0278 //! Tuple indexes of name and value fields in xattr_t 0279 //---------------------------------------------------------------------------- 0280 enum 0281 { 0282 xattr_name = 0, 0283 xattr_value = 1 0284 }; 0285 0286 //---------------------------------------------------------------------------- 0287 //! Extended attribute key - value pair 0288 //---------------------------------------------------------------------------- 0289 typedef std::tuple<std::string, std::string> xattr_t; 0290 0291 //---------------------------------------------------------------------------- 0292 //! Extended attribute operation status 0293 //---------------------------------------------------------------------------- 0294 struct XAttrStatus 0295 { 0296 friend class FileStateHandler; 0297 friend class FileSystem; 0298 0299 XAttrStatus( const std::string &name, const XRootDStatus &status ) : 0300 name( name ), status( status ) 0301 { 0302 0303 } 0304 0305 std::string name; 0306 XRootDStatus status; 0307 }; 0308 0309 //---------------------------------------------------------------------------- 0310 //! Extended attributes with status 0311 //---------------------------------------------------------------------------- 0312 struct XAttr : public XAttrStatus 0313 { 0314 friend class FileStateHandler; 0315 friend class FileSystem; 0316 0317 XAttr( const std::string &name, const XRootDStatus &status ) : 0318 XAttrStatus( name, status ) 0319 { 0320 0321 } 0322 0323 XAttr( const std::string &name, const std::string &value = "", 0324 const XRootDStatus &status = XRootDStatus() ) : 0325 XAttrStatus( name, status ), value( value ) 0326 { 0327 0328 } 0329 0330 std::string value; 0331 }; 0332 0333 //---------------------------------------------------------------------------- 0334 //! Binary buffer 0335 //---------------------------------------------------------------------------- 0336 typedef Buffer BinaryDataInfo; 0337 0338 //---------------------------------------------------------------------------- 0339 //! Protocol response 0340 //---------------------------------------------------------------------------- 0341 class ProtocolInfo 0342 { 0343 public: 0344 //------------------------------------------------------------------------ 0345 //! Types of XRootD servers 0346 //------------------------------------------------------------------------ 0347 enum HostTypes 0348 { 0349 IsManager = kXR_isManager, //!< Manager 0350 IsServer = kXR_isServer, //!< Data server 0351 AttrCache = kXR_attrCache, //!< Cache attribute 0352 AttrMeta = kXR_attrMeta, //!< Meta attribute 0353 AttrProxy = kXR_attrProxy, //!< Proxy attribute 0354 AttrSuper = kXR_attrSuper //!< Supervisor attribute 0355 }; 0356 0357 //------------------------------------------------------------------------ 0358 //! Constructor 0359 //------------------------------------------------------------------------ 0360 ProtocolInfo( uint32_t version, uint32_t hostInfo ): 0361 pVersion( version ), pHostInfo( hostInfo ) {} 0362 0363 //------------------------------------------------------------------------ 0364 //! Get version info 0365 //------------------------------------------------------------------------ 0366 uint32_t GetVersion() const 0367 { 0368 return pVersion; 0369 } 0370 0371 //------------------------------------------------------------------------ 0372 //! Get host info 0373 //------------------------------------------------------------------------ 0374 uint32_t GetHostInfo() const 0375 { 0376 return pHostInfo; 0377 } 0378 0379 //------------------------------------------------------------------------ 0380 //! Test host info flags 0381 //------------------------------------------------------------------------ 0382 bool TestHostInfo( uint32_t flags ) 0383 { 0384 return pHostInfo & flags; 0385 } 0386 0387 private: 0388 uint32_t pVersion; 0389 uint32_t pHostInfo; 0390 }; 0391 0392 //---------------------------------------------------------------------------- 0393 //! Object stat info implementation forward declaration 0394 //---------------------------------------------------------------------------- 0395 struct StatInfoImpl; 0396 0397 //---------------------------------------------------------------------------- 0398 //! Object stat info 0399 //---------------------------------------------------------------------------- 0400 class StatInfo 0401 { 0402 public: 0403 //------------------------------------------------------------------------ 0404 //! Flags 0405 //------------------------------------------------------------------------ 0406 enum Flags 0407 { 0408 XBitSet = kXR_xset, //!< Executable/searchable bit set 0409 IsDir = kXR_isDir, //!< This is a directory 0410 Other = kXR_other, //!< Neither a file nor a directory 0411 Offline = kXR_offline, //!< File is not online (ie. on disk) 0412 POSCPending = kXR_poscpend, //!< File opened with POST flag, not yet 0413 //!< successfully closed 0414 IsReadable = kXR_readable, //!< Read access is allowed 0415 IsWritable = kXR_writable, //!< Write access is allowed 0416 BackUpExists = kXR_bkpexist //!< Back up copy exists 0417 }; 0418 0419 //------------------------------------------------------------------------ 0420 //! Constructor 0421 //------------------------------------------------------------------------ 0422 StatInfo(); 0423 0424 //------------------------------------------------------------------------ 0425 //! Constructor 0426 //------------------------------------------------------------------------ 0427 StatInfo( const std::string &id, uint64_t size, uint32_t flags, 0428 uint64_t modTime ); 0429 0430 //------------------------------------------------------------------------ 0431 //! Copy constructor 0432 //------------------------------------------------------------------------ 0433 StatInfo( const StatInfo &info ); 0434 0435 //------------------------------------------------------------------------ 0436 //! Destructor 0437 //------------------------------------------------------------------------ 0438 ~StatInfo(); 0439 0440 //------------------------------------------------------------------------ 0441 //! Get id 0442 //------------------------------------------------------------------------ 0443 const std::string& GetId() const; 0444 0445 //------------------------------------------------------------------------ 0446 //! Get size (in bytes) 0447 //------------------------------------------------------------------------ 0448 uint64_t GetSize() const; 0449 0450 //------------------------------------------------------------------------ 0451 //! Set size 0452 //------------------------------------------------------------------------ 0453 void SetSize( uint64_t size ); 0454 0455 //------------------------------------------------------------------------ 0456 //! Get flags 0457 //------------------------------------------------------------------------ 0458 uint32_t GetFlags() const; 0459 0460 //------------------------------------------------------------------------ 0461 //! Set flags 0462 //------------------------------------------------------------------------ 0463 void SetFlags( uint32_t flags ); 0464 0465 //------------------------------------------------------------------------ 0466 //! Test flags 0467 //------------------------------------------------------------------------ 0468 bool TestFlags( uint32_t flags ) const; 0469 0470 //------------------------------------------------------------------------ 0471 //! Get modification time (in seconds since epoch) 0472 //------------------------------------------------------------------------ 0473 uint64_t GetModTime() const; 0474 0475 //------------------------------------------------------------------------ 0476 //! Get modification time 0477 //------------------------------------------------------------------------ 0478 std::string GetModTimeAsString() const; 0479 0480 //------------------------------------------------------------------------ 0481 //! Get change time (in seconds since epoch) 0482 //------------------------------------------------------------------------ 0483 uint64_t GetChangeTime() const; 0484 0485 //------------------------------------------------------------------------ 0486 //! Get change time 0487 //------------------------------------------------------------------------ 0488 std::string GetChangeTimeAsString() const; 0489 0490 //------------------------------------------------------------------------ 0491 //! Get change time (in seconds since epoch) 0492 //------------------------------------------------------------------------ 0493 uint64_t GetAccessTime() const; 0494 0495 //------------------------------------------------------------------------ 0496 //! Get change time 0497 //------------------------------------------------------------------------ 0498 std::string GetAccessTimeAsString() const; 0499 0500 //------------------------------------------------------------------------ 0501 //! Get mode 0502 //------------------------------------------------------------------------ 0503 const std::string& GetModeAsString() const; 0504 0505 //------------------------------------------------------------------------ 0506 //! Get mode 0507 //------------------------------------------------------------------------ 0508 const std::string GetModeAsOctString() const; 0509 0510 //------------------------------------------------------------------------ 0511 //! Get owner 0512 //------------------------------------------------------------------------ 0513 const std::string& GetOwner() const; 0514 0515 //------------------------------------------------------------------------ 0516 //! Get group 0517 //------------------------------------------------------------------------ 0518 const std::string& GetGroup() const; 0519 0520 //------------------------------------------------------------------------ 0521 //! Get checksum 0522 //------------------------------------------------------------------------ 0523 const std::string& GetChecksum() const; 0524 0525 //------------------------------------------------------------------------ 0526 //! Parse server response and fill up the object 0527 //------------------------------------------------------------------------ 0528 bool ParseServerResponse( const char *data ); 0529 0530 //------------------------------------------------------------------------ 0531 //! Has extended stat information 0532 //------------------------------------------------------------------------ 0533 bool ExtendedFormat() const; 0534 0535 //------------------------------------------------------------------------ 0536 //! Has checksum 0537 //------------------------------------------------------------------------ 0538 bool HasChecksum() const; 0539 0540 private: 0541 0542 static inline std::string TimeToString( uint64_t time ) 0543 { 0544 char ts[256]; 0545 time_t modTime = time; 0546 tm *t = gmtime( &modTime ); 0547 strftime( ts, 255, "%F %T", t ); 0548 return ts; 0549 } 0550 0551 static inline void OctToString( uint8_t oct, std::string &str ) 0552 { 0553 static const uint8_t r_mask = 0x4; 0554 static const uint8_t w_mask = 0x2; 0555 static const uint8_t x_mask = 0x1; 0556 0557 if( r_mask & oct ) str.push_back( 'r' ); 0558 else str.push_back( '-' ); 0559 0560 if( w_mask & oct ) str.push_back( 'w' ); 0561 else str.push_back( '-' ); 0562 0563 if( x_mask & oct ) str.push_back( 'x' ); 0564 else str.push_back( '-' ); 0565 } 0566 0567 std::unique_ptr<StatInfoImpl> pImpl; 0568 }; 0569 0570 //---------------------------------------------------------------------------- 0571 //! VFS stat info 0572 //---------------------------------------------------------------------------- 0573 class StatInfoVFS 0574 { 0575 public: 0576 //------------------------------------------------------------------------ 0577 //! Constructor 0578 //------------------------------------------------------------------------ 0579 StatInfoVFS(); 0580 0581 //------------------------------------------------------------------------ 0582 //! Get number of nodes that can provide read/write space 0583 //------------------------------------------------------------------------ 0584 uint64_t GetNodesRW() const 0585 { 0586 return pNodesRW; 0587 } 0588 0589 //------------------------------------------------------------------------ 0590 //! Get size of the largest contiguous area of free r/w space (in MB) 0591 //------------------------------------------------------------------------ 0592 uint64_t GetFreeRW() const 0593 { 0594 return pFreeRW; 0595 } 0596 0597 //------------------------------------------------------------------------ 0598 //! Get percentage of the partition utilization represented by FreeRW 0599 //------------------------------------------------------------------------ 0600 uint8_t GetUtilizationRW() const 0601 { 0602 return pUtilizationRW; 0603 } 0604 0605 //------------------------------------------------------------------------ 0606 //! Get number of nodes that can provide staging space 0607 //------------------------------------------------------------------------ 0608 uint64_t GetNodesStaging() const 0609 { 0610 return pNodesStaging; 0611 } 0612 0613 //------------------------------------------------------------------------ 0614 //! Get size of the largest contiguous area of free staging space (in MB) 0615 //------------------------------------------------------------------------ 0616 uint64_t GetFreeStaging() const 0617 { 0618 return pFreeStaging; 0619 } 0620 0621 //------------------------------------------------------------------------ 0622 //! Get percentage of the partition utilization represented by FreeStaging 0623 //------------------------------------------------------------------------ 0624 uint8_t GetUtilizationStaging() const 0625 { 0626 return pUtilizationStaging; 0627 } 0628 0629 //------------------------------------------------------------------------ 0630 //! Parse server response and fill up the object 0631 //------------------------------------------------------------------------ 0632 bool ParseServerResponse( const char *data ); 0633 0634 private: 0635 0636 //------------------------------------------------------------------------ 0637 // kXR_vfs stat 0638 //------------------------------------------------------------------------ 0639 uint64_t pNodesRW; 0640 uint64_t pFreeRW; 0641 uint32_t pUtilizationRW; 0642 uint64_t pNodesStaging; 0643 uint64_t pFreeStaging; 0644 uint32_t pUtilizationStaging; 0645 }; 0646 0647 //---------------------------------------------------------------------------- 0648 //! Directory list 0649 //---------------------------------------------------------------------------- 0650 class DirectoryList 0651 { 0652 public: 0653 0654 //------------------------------------------------------------------------ 0655 //! Directory entry 0656 //------------------------------------------------------------------------ 0657 class ListEntry 0658 { 0659 public: 0660 //-------------------------------------------------------------------- 0661 //! Constructor 0662 //-------------------------------------------------------------------- 0663 ListEntry( const std::string &hostAddress, 0664 const std::string &name, 0665 StatInfo *statInfo = 0): 0666 pHostAddress( hostAddress ), 0667 pName( SanitizeName( name ) ), 0668 pStatInfo( statInfo ) 0669 {} 0670 0671 //-------------------------------------------------------------------- 0672 //! Destructor 0673 //-------------------------------------------------------------------- 0674 ~ListEntry() 0675 { 0676 delete pStatInfo; 0677 } 0678 0679 //-------------------------------------------------------------------- 0680 //! Get host address 0681 //-------------------------------------------------------------------- 0682 const std::string &GetHostAddress() const 0683 { 0684 return pHostAddress; 0685 } 0686 0687 //-------------------------------------------------------------------- 0688 //! Get file name 0689 //-------------------------------------------------------------------- 0690 const std::string &GetName() const 0691 { 0692 return pName; 0693 } 0694 0695 //-------------------------------------------------------------------- 0696 //! Get the stat info object 0697 //-------------------------------------------------------------------- 0698 StatInfo *GetStatInfo() 0699 { 0700 return pStatInfo; 0701 } 0702 0703 //-------------------------------------------------------------------- 0704 //! Get the stat info object 0705 //-------------------------------------------------------------------- 0706 const StatInfo *GetStatInfo() const 0707 { 0708 return pStatInfo; 0709 } 0710 0711 //-------------------------------------------------------------------- 0712 //! Set the stat info object (and transfer the ownership) 0713 //-------------------------------------------------------------------- 0714 void SetStatInfo( StatInfo *info ) 0715 { 0716 pStatInfo = info; 0717 } 0718 0719 private: 0720 0721 inline static std::string SanitizeName( const std::string &name ) 0722 { 0723 const char *cstr = name.c_str(); 0724 while( *cstr == '/' ) // the C string is guaranteed to end with '\0' 0725 ++cstr; 0726 return cstr; 0727 } 0728 0729 std::string pHostAddress; 0730 std::string pName; 0731 StatInfo *pStatInfo; 0732 }; 0733 0734 //------------------------------------------------------------------------ 0735 //! Constructor 0736 //------------------------------------------------------------------------ 0737 DirectoryList(); 0738 0739 //------------------------------------------------------------------------ 0740 //! Destructor 0741 //------------------------------------------------------------------------ 0742 ~DirectoryList(); 0743 0744 //------------------------------------------------------------------------ 0745 //! Directory listing 0746 //------------------------------------------------------------------------ 0747 typedef std::vector<ListEntry*> DirList; 0748 0749 //------------------------------------------------------------------------ 0750 //! Directory listing iterator 0751 //------------------------------------------------------------------------ 0752 typedef DirList::iterator Iterator; 0753 0754 //------------------------------------------------------------------------ 0755 //! Directory listing const iterator 0756 //------------------------------------------------------------------------ 0757 typedef DirList::const_iterator ConstIterator; 0758 0759 //------------------------------------------------------------------------ 0760 //! Add an entry to the list - takes ownership 0761 //------------------------------------------------------------------------ 0762 void Add( ListEntry *entry ) 0763 { 0764 pDirList.push_back( entry ); 0765 } 0766 0767 //------------------------------------------------------------------------ 0768 //! Get an entry at given index 0769 //------------------------------------------------------------------------ 0770 ListEntry *At( uint32_t index ) 0771 { 0772 return pDirList[index]; 0773 } 0774 0775 //------------------------------------------------------------------------ 0776 //! Get the begin iterator 0777 //------------------------------------------------------------------------ 0778 Iterator Begin() 0779 { 0780 return pDirList.begin(); 0781 } 0782 0783 //------------------------------------------------------------------------ 0784 //! Get the begin iterator 0785 //------------------------------------------------------------------------ 0786 ConstIterator Begin() const 0787 { 0788 return pDirList.begin(); 0789 } 0790 0791 //------------------------------------------------------------------------ 0792 //! Get the end iterator 0793 //------------------------------------------------------------------------ 0794 Iterator End() 0795 { 0796 return pDirList.end(); 0797 } 0798 0799 //------------------------------------------------------------------------ 0800 //! Get the end iterator 0801 //------------------------------------------------------------------------ 0802 ConstIterator End() const 0803 { 0804 return pDirList.end(); 0805 } 0806 0807 //------------------------------------------------------------------------ 0808 //! Get the size of the listing 0809 //------------------------------------------------------------------------ 0810 uint32_t GetSize() const 0811 { 0812 return pDirList.size(); 0813 } 0814 0815 //------------------------------------------------------------------------ 0816 //! Get parent directory name 0817 //------------------------------------------------------------------------ 0818 const std::string &GetParentName() const 0819 { 0820 return pParent; 0821 } 0822 0823 //------------------------------------------------------------------------ 0824 //! Set name of the parent directory 0825 //------------------------------------------------------------------------ 0826 void SetParentName( const std::string &parent ) 0827 { 0828 size_t pos = parent.find( '?' ); 0829 pParent = pos == std::string::npos ? parent : parent.substr( 0, pos ); 0830 if( !pParent.empty() && pParent[pParent.length()-1] != '/' ) 0831 pParent += "/"; 0832 } 0833 0834 //------------------------------------------------------------------------ 0835 //! Parse server response and fill up the object 0836 //------------------------------------------------------------------------ 0837 bool ParseServerResponse( const std::string &hostId, 0838 const char *data ); 0839 0840 //------------------------------------------------------------------------ 0841 //! Parse chunked server response and fill up the object 0842 //------------------------------------------------------------------------ 0843 bool ParseServerResponse( const std::string &hostId, 0844 const char *data, 0845 bool isDStat ); 0846 0847 //------------------------------------------------------------------------ 0848 //! Returns true if data contain stat info 0849 //------------------------------------------------------------------------ 0850 static bool HasStatInfo( const char *data ); 0851 0852 private: 0853 DirList pDirList; 0854 std::string pParent; 0855 0856 static const std::string dStatPrefix; 0857 }; 0858 0859 //---------------------------------------------------------------------------- 0860 //! Information returned by file open operation 0861 //---------------------------------------------------------------------------- 0862 class OpenInfo 0863 { 0864 public: 0865 //------------------------------------------------------------------------ 0866 //! Constructor 0867 //------------------------------------------------------------------------ 0868 OpenInfo( const uint8_t *fileHandle, 0869 uint64_t sessionId, 0870 StatInfo *statInfo = 0 ): 0871 pSessionId(sessionId), pStatInfo( statInfo ) 0872 { 0873 memcpy( pFileHandle, fileHandle, 4 ); 0874 } 0875 0876 //------------------------------------------------------------------------ 0877 //! Destructor 0878 //------------------------------------------------------------------------ 0879 ~OpenInfo() 0880 { 0881 delete pStatInfo; 0882 } 0883 0884 //------------------------------------------------------------------------ 0885 //! Get the file handle (4bytes) 0886 //------------------------------------------------------------------------ 0887 void GetFileHandle( uint8_t *fileHandle ) const 0888 { 0889 memcpy( fileHandle, pFileHandle, 4 ); 0890 } 0891 0892 //------------------------------------------------------------------------ 0893 //! Get the stat info 0894 //------------------------------------------------------------------------ 0895 const StatInfo *GetStatInfo() const 0896 { 0897 return pStatInfo; 0898 } 0899 0900 //------------------------------------------------------------------------ 0901 // Get session ID 0902 //------------------------------------------------------------------------ 0903 uint64_t GetSessionId() const 0904 { 0905 return pSessionId; 0906 } 0907 0908 private: 0909 uint8_t pFileHandle[4]; 0910 uint64_t pSessionId; 0911 StatInfo *pStatInfo; 0912 }; 0913 0914 //---------------------------------------------------------------------------- 0915 //! Describe a data chunk for vector read 0916 //---------------------------------------------------------------------------- 0917 struct ChunkInfo 0918 { 0919 //-------------------------------------------------------------------------- 0920 //! Constructor 0921 //-------------------------------------------------------------------------- 0922 ChunkInfo( uint64_t off = 0, uint32_t len = 0, void *buff = 0 ): 0923 offset( off ), length( len ), buffer(buff) {} 0924 0925 //---------------------------------------------------------------------------- 0926 //! Get the offset 0927 //---------------------------------------------------------------------------- 0928 inline uint64_t GetOffset() const 0929 { 0930 return offset; 0931 } 0932 0933 //---------------------------------------------------------------------------- 0934 //! Get the data length 0935 //---------------------------------------------------------------------------- 0936 inline uint32_t GetLength() const 0937 { 0938 return length; 0939 } 0940 0941 //---------------------------------------------------------------------------- 0942 //! Get the buffer 0943 //---------------------------------------------------------------------------- 0944 inline void* GetBuffer() 0945 { 0946 return buffer; 0947 } 0948 0949 uint64_t offset; //! offset in the file 0950 uint32_t length; //! length of the chunk 0951 void *buffer; //! optional buffer pointer 0952 }; 0953 0954 struct PageInfoImpl; 0955 0956 struct PageInfo 0957 { 0958 //---------------------------------------------------------------------------- 0959 //! Default constructor 0960 //---------------------------------------------------------------------------- 0961 PageInfo( uint64_t offset = 0, uint32_t length = 0, void *buffer = 0, 0962 std::vector<uint32_t> &&cksums = std::vector<uint32_t>() ); 0963 0964 //---------------------------------------------------------------------------- 0965 //! Move constructor 0966 //---------------------------------------------------------------------------- 0967 PageInfo( PageInfo &&pginf ); 0968 0969 //---------------------------------------------------------------------------- 0970 //! Move assigment operator 0971 //---------------------------------------------------------------------------- 0972 PageInfo& operator=( PageInfo &&pginf ); 0973 0974 //---------------------------------------------------------------------------- 0975 //! Destructor 0976 //---------------------------------------------------------------------------- 0977 ~PageInfo(); 0978 0979 //---------------------------------------------------------------------------- 0980 //! Get the offset 0981 //---------------------------------------------------------------------------- 0982 uint64_t GetOffset() const; 0983 0984 //---------------------------------------------------------------------------- 0985 //! Get the data length 0986 //---------------------------------------------------------------------------- 0987 uint32_t GetLength() const; 0988 0989 //---------------------------------------------------------------------------- 0990 //! Get the buffer 0991 //---------------------------------------------------------------------------- 0992 void* GetBuffer(); 0993 0994 //---------------------------------------------------------------------------- 0995 //! Get the checksums 0996 //---------------------------------------------------------------------------- 0997 std::vector<uint32_t>& GetCksums(); 0998 0999 //---------------------------------------------------------------------------- 1000 //! Get number of repaired pages 1001 //---------------------------------------------------------------------------- 1002 size_t GetNbRepair(); 1003 1004 //---------------------------------------------------------------------------- 1005 //! Set number of repaired pages 1006 //---------------------------------------------------------------------------- 1007 void SetNbRepair( size_t nbrepair ); 1008 1009 private: 1010 //-------------------------------------------------------------------------- 1011 //! pointer to implementation 1012 //-------------------------------------------------------------------------- 1013 std::unique_ptr<PageInfoImpl> pImpl; 1014 }; 1015 1016 struct RetryInfoImpl; 1017 1018 struct RetryInfo 1019 { 1020 //---------------------------------------------------------------------------- 1021 //! Constructor 1022 //---------------------------------------------------------------------------- 1023 RetryInfo( std::vector<std::tuple<uint64_t, uint32_t>> && retries ); 1024 1025 //---------------------------------------------------------------------------- 1026 //! Destructor 1027 //---------------------------------------------------------------------------- 1028 ~RetryInfo(); 1029 1030 //---------------------------------------------------------------------------- 1031 //! @return : true if some pages need retrying, false otherwise 1032 //---------------------------------------------------------------------------- 1033 bool NeedRetry(); 1034 1035 //---------------------------------------------------------------------------- 1036 //! @return number of pages that need to be retransmitted 1037 //---------------------------------------------------------------------------- 1038 size_t Size(); 1039 1040 //---------------------------------------------------------------------------- 1041 //! @return : offset and size of respective page that requires to be 1042 // retransmitted 1043 //---------------------------------------------------------------------------- 1044 std::tuple<uint64_t, uint32_t> At( size_t i ); 1045 1046 private: 1047 //-------------------------------------------------------------------------- 1048 //! pointer to implementation 1049 //-------------------------------------------------------------------------- 1050 std::unique_ptr<RetryInfoImpl> pImpl; 1051 }; 1052 1053 //---------------------------------------------------------------------------- 1054 //! List of chunks 1055 //---------------------------------------------------------------------------- 1056 typedef std::vector<ChunkInfo> ChunkList; 1057 1058 //---------------------------------------------------------------------------- 1059 //! Vector read info 1060 //---------------------------------------------------------------------------- 1061 class VectorReadInfo 1062 { 1063 public: 1064 //------------------------------------------------------------------------ 1065 //! Constructor 1066 //------------------------------------------------------------------------ 1067 VectorReadInfo(): pSize( 0 ) {} 1068 1069 //------------------------------------------------------------------------ 1070 //! Get Size 1071 //------------------------------------------------------------------------ 1072 uint32_t GetSize() const 1073 { 1074 return pSize; 1075 } 1076 1077 //------------------------------------------------------------------------ 1078 //! Set size 1079 //------------------------------------------------------------------------ 1080 void SetSize( uint32_t size ) 1081 { 1082 pSize = size; 1083 } 1084 1085 //------------------------------------------------------------------------ 1086 //! Get chunks 1087 //------------------------------------------------------------------------ 1088 ChunkList &GetChunks() 1089 { 1090 return pChunks; 1091 } 1092 1093 //------------------------------------------------------------------------ 1094 //! Get chunks 1095 //------------------------------------------------------------------------ 1096 const ChunkList &GetChunks() const 1097 { 1098 return pChunks; 1099 } 1100 1101 private: 1102 ChunkList pChunks; 1103 uint32_t pSize; 1104 }; 1105 1106 //---------------------------------------------------------------------------- 1107 // List of URLs 1108 //---------------------------------------------------------------------------- 1109 struct HostInfo 1110 { 1111 HostInfo(): 1112 flags(0), protocol(0), loadBalancer(false) {} 1113 HostInfo( const URL &u, bool lb = false ): 1114 flags(0), protocol(0), loadBalancer(lb), url(u) {} 1115 uint32_t flags; //!< Host type 1116 uint32_t protocol; //!< Version of the protocol the host is speaking 1117 bool loadBalancer; //!< Was the host used as a load balancer 1118 URL url; //!< URL of the host 1119 }; 1120 1121 typedef std::vector<HostInfo> HostList; 1122 1123 //---------------------------------------------------------------------------- 1124 //! Handle an async response 1125 //---------------------------------------------------------------------------- 1126 class ResponseHandler 1127 { 1128 public: 1129 virtual ~ResponseHandler() {} 1130 1131 //------------------------------------------------------------------------ 1132 //! Called when a response to associated request arrives or an error 1133 //! occurs 1134 //! 1135 //! @param status status of the request 1136 //! @param response an object associated with the response 1137 //! (request dependent) 1138 //! @param hostList list of hosts the request was redirected to 1139 //------------------------------------------------------------------------ 1140 virtual void HandleResponseWithHosts( XRootDStatus *status, 1141 AnyObject *response, 1142 HostList *hostList ) 1143 { 1144 delete hostList; 1145 HandleResponse( status, response ); 1146 } 1147 1148 //------------------------------------------------------------------------ 1149 //! Called when a response to associated request arrives or an error 1150 //! occurs 1151 //! 1152 //! @param status status of the request 1153 //! @param response an object associated with the response 1154 //! (request dependent) 1155 //------------------------------------------------------------------------ 1156 virtual void HandleResponse( XRootDStatus *status, 1157 AnyObject *response ) 1158 { 1159 (void)status; (void)response; 1160 } 1161 1162 //------------------------------------------------------------------------ 1163 //! Factory function for generating handler objects from lambdas 1164 //! 1165 //! @param func : the callback, must not throw 1166 //! @return : ResponseHandler wrapper with the user callback 1167 //------------------------------------------------------------------------ 1168 static ResponseHandler* Wrap( std::function<void(XRootDStatus&, AnyObject&)> func ); 1169 1170 //------------------------------------------------------------------------ 1171 //! Factory function for generating handler objects from lambdas 1172 //! 1173 //! @param func : the callback, must not throw 1174 //! @return : ResponseHandler wrapper with the user callback 1175 //------------------------------------------------------------------------ 1176 static ResponseHandler* Wrap( std::function<void(XRootDStatus*, AnyObject*)> func ); 1177 }; 1178 } 1179 1180 #endif // __XRD_CL_XROOTD_RESPONSES_HH__
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|