XrdClXRootDResponses.hh

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
00003 // Author: Lukasz Janyst <ljanyst@cern.ch>
00004 //------------------------------------------------------------------------------
00005 // XRootD is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU Lesser General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // XRootD is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with XRootD.  If not, see <http://www.gnu.org/licenses/>.
00017 //------------------------------------------------------------------------------
00018 
00019 #ifndef __XRD_CL_XROOTD_RESPONSES_HH__
00020 #define __XRD_CL_XROOTD_RESPONSES_HH__
00021 
00022 #include "XrdCl/XrdClBuffer.hh"
00023 #include "XrdCl/XrdClStatus.hh"
00024 #include "XrdCl/XrdClURL.hh"
00025 #include "XrdCl/XrdClAnyObject.hh"
00026 #include "XProtocol/XProtocol.hh"
00027 #include <string>
00028 #include <vector>
00029 #include <list>
00030 #include <ctime>
00031 
00032 namespace XrdCl
00033 {
00034   //----------------------------------------------------------------------------
00036   //----------------------------------------------------------------------------
00037   class LocationInfo
00038   {
00039     public:
00040       //------------------------------------------------------------------------
00042       //------------------------------------------------------------------------
00043       enum LocationType
00044       {
00045         ManagerOnline,   
00046         ManagerPending,  
00047         ServerOnline,    
00048         ServerPending    
00049       };
00050 
00051       //------------------------------------------------------------------------
00053       //------------------------------------------------------------------------
00054       enum AccessType
00055       {
00056         Read,            
00057         ReadWrite        
00058       };
00059 
00060       //------------------------------------------------------------------------
00062       //------------------------------------------------------------------------
00063       class Location
00064       {
00065         public:
00066 
00067           //--------------------------------------------------------------------
00069           //--------------------------------------------------------------------
00070           Location( const std::string  &address,
00071                     LocationType        type,
00072                     AccessType          access ):
00073             pAddress( address ),
00074             pType( type ),
00075             pAccess( access ) {}
00076 
00077           //--------------------------------------------------------------------
00079           //--------------------------------------------------------------------
00080           const std::string &GetAddress() const
00081           {
00082             return pAddress;
00083           }
00084 
00085           //--------------------------------------------------------------------
00087           //--------------------------------------------------------------------
00088           LocationType GetType() const
00089           {
00090             return pType;
00091           }
00092 
00093           //--------------------------------------------------------------------
00095           //--------------------------------------------------------------------
00096           AccessType GetAccessType() const
00097           {
00098             return pAccess;
00099           }
00100 
00101           //--------------------------------------------------------------------
00103           //--------------------------------------------------------------------
00104           bool IsServer() const
00105           {
00106             return pType == ServerOnline || pType == ServerPending;
00107           }
00108 
00109           //--------------------------------------------------------------------
00111           //--------------------------------------------------------------------
00112           bool IsManager() const
00113           {
00114             return pType == ManagerOnline || pType == ManagerPending;
00115           }
00116 
00117         private:
00118           std::string  pAddress;
00119           LocationType pType;
00120           AccessType   pAccess;
00121       };
00122 
00123       //------------------------------------------------------------------------
00125       //------------------------------------------------------------------------
00126       typedef std::vector<Location>        LocationList;
00127 
00128       //------------------------------------------------------------------------
00130       //------------------------------------------------------------------------
00131       typedef LocationList::iterator       Iterator;
00132 
00133       //------------------------------------------------------------------------
00135       //------------------------------------------------------------------------
00136       typedef LocationList::const_iterator ConstIterator;
00137 
00138       //------------------------------------------------------------------------
00140       //------------------------------------------------------------------------
00141       LocationInfo();
00142 
00143       //------------------------------------------------------------------------
00145       //------------------------------------------------------------------------
00146       uint32_t GetSize() const
00147       {
00148         return pLocations.size();
00149       }
00150 
00151       //------------------------------------------------------------------------
00153       //------------------------------------------------------------------------
00154       Location &At( uint32_t index )
00155       {
00156         return pLocations[index];
00157       }
00158 
00159       //------------------------------------------------------------------------
00161       //------------------------------------------------------------------------
00162       Iterator Begin()
00163       {
00164         return pLocations.begin();
00165       }
00166 
00167       //------------------------------------------------------------------------
00169       //------------------------------------------------------------------------
00170       ConstIterator Begin() const
00171       {
00172         return pLocations.begin();
00173       }
00174 
00175       //------------------------------------------------------------------------
00177       //------------------------------------------------------------------------
00178       Iterator End()
00179       {
00180         return pLocations.end();
00181       }
00182 
00183       //------------------------------------------------------------------------
00185       //------------------------------------------------------------------------
00186       ConstIterator End() const
00187       {
00188         return pLocations.end();
00189       }
00190 
00191       //------------------------------------------------------------------------
00193       //------------------------------------------------------------------------
00194       void Add( const Location &location )
00195       {
00196         pLocations.push_back( location );
00197       }
00198 
00199       //------------------------------------------------------------------------
00201       //------------------------------------------------------------------------
00202       bool ParseServerResponse( const char *data );
00203 
00204     private:
00205       bool ProcessLocation( std::string &location );
00206       LocationList pLocations;
00207   };
00208 
00209   //----------------------------------------------------------------------------
00211   //----------------------------------------------------------------------------
00212   class XRootDStatus: public Status
00213   {
00214     public:
00215       //------------------------------------------------------------------------
00217       //------------------------------------------------------------------------
00218       XRootDStatus( uint16_t           st      = 0,
00219                     uint16_t           code    = 0,
00220                     uint32_t           errN    = 0,
00221                     const std::string &message = "" ):
00222         Status( st, code, errN ),
00223         pMessage( message ) {}
00224 
00225       //------------------------------------------------------------------------
00227       //------------------------------------------------------------------------
00228       XRootDStatus( const Status      &st,
00229                     const std::string &message = "" ):
00230         Status( st ),
00231         pMessage( message ) {}
00232 
00233       //------------------------------------------------------------------------
00235       //------------------------------------------------------------------------
00236       const std::string &GetErrorMessage() const
00237       {
00238         return pMessage;
00239       }
00240 
00241       //------------------------------------------------------------------------
00243       //------------------------------------------------------------------------
00244       void SetErrorMessage( const std::string &message )
00245       {
00246         pMessage = message;
00247       }
00248 
00249       //------------------------------------------------------------------------
00251       //------------------------------------------------------------------------
00252       std::string ToStr() const
00253       {
00254         if( code == errErrorResponse )
00255         {
00256           std::ostringstream o;
00257           o << "[ERROR] Server responded with an error: [" << errNo << "] ";
00258           o << pMessage << std::endl;
00259           return o.str();
00260         }
00261         std::string str = ToString();
00262         if( !pMessage.empty() )
00263           str += ": " + pMessage;
00264         return str;
00265       }
00266 
00267     private:
00268       std::string pMessage;
00269   };
00270 
00271   //----------------------------------------------------------------------------
00273   //----------------------------------------------------------------------------
00274   typedef Buffer BinaryDataInfo;
00275 
00276   //----------------------------------------------------------------------------
00278   //----------------------------------------------------------------------------
00279   class ProtocolInfo
00280   {
00281     public:
00282       //------------------------------------------------------------------------
00284       //------------------------------------------------------------------------
00285       enum HostTypes
00286       {
00287         IsManager = kXR_isManager,   
00288         IsServer  = kXR_isServer,    
00289         AttrMeta  = kXR_attrMeta,    
00290         AttrProxy = kXR_attrProxy,   
00291         AttrSuper = kXR_attrSuper    
00292       };
00293 
00294       //------------------------------------------------------------------------
00296       //------------------------------------------------------------------------
00297       ProtocolInfo( uint32_t version, uint32_t hostInfo ):
00298         pVersion( version ), pHostInfo( hostInfo ) {}
00299 
00300       //------------------------------------------------------------------------
00302       //------------------------------------------------------------------------
00303       uint32_t GetVersion() const
00304       {
00305         return pVersion;
00306       }
00307 
00308       //------------------------------------------------------------------------
00310       //------------------------------------------------------------------------
00311       uint32_t GetHostInfo() const
00312       {
00313         return pHostInfo;
00314       }
00315 
00316       //------------------------------------------------------------------------
00318       //------------------------------------------------------------------------
00319       bool TestHostInfo( uint32_t flags )
00320       {
00321         return pHostInfo & flags;
00322       }
00323 
00324     private:
00325       uint32_t pVersion;
00326       uint32_t pHostInfo;
00327   };
00328 
00329   //----------------------------------------------------------------------------
00331   //----------------------------------------------------------------------------
00332   class StatInfo
00333   {
00334     public:
00335       //------------------------------------------------------------------------
00337       //------------------------------------------------------------------------
00338       enum Flags
00339       {
00340         XBitSet      = kXR_xset,      
00341         IsDir        = kXR_isDir,     
00342         Other        = kXR_other,     
00343         Offline      = kXR_offline,   
00344         POSCPending  = kXR_poscpend,  
00345 
00346         IsReadable   = kXR_readable,  
00347         IsWritable   = kXR_writable,  
00348         BackUpExists = kXR_bkpexist   
00349       };
00350 
00351       //------------------------------------------------------------------------
00353       //------------------------------------------------------------------------
00354       StatInfo();
00355 
00356       //------------------------------------------------------------------------
00358       //------------------------------------------------------------------------
00359       const std::string GetId() const
00360       {
00361         return pId;
00362       }
00363 
00364       //------------------------------------------------------------------------
00366       //------------------------------------------------------------------------
00367       uint64_t GetSize() const
00368       {
00369         return pSize;
00370       }
00371 
00372       //------------------------------------------------------------------------
00374       //------------------------------------------------------------------------
00375       uint32_t GetFlags() const
00376       {
00377         return pFlags;
00378       }
00379 
00380       //------------------------------------------------------------------------
00382       //------------------------------------------------------------------------
00383       bool TestFlags( uint32_t flags ) const
00384       {
00385         return pFlags & flags;
00386       }
00387 
00388       //------------------------------------------------------------------------
00390       //------------------------------------------------------------------------
00391       uint64_t GetModTime() const
00392       {
00393         return pModTime;
00394       }
00395 
00396       //------------------------------------------------------------------------
00398       //------------------------------------------------------------------------
00399       std::string GetModTimeAsString() const
00400       {
00401         char ts[256];
00402         time_t modTime = pModTime;
00403         tm *t = gmtime( &modTime );
00404         strftime( ts, 255, "%F %T", t );
00405         return ts;
00406       }
00407 
00408       //------------------------------------------------------------------------
00410       //------------------------------------------------------------------------
00411       bool ParseServerResponse( const char *data );
00412 
00413     private:
00414 
00415       //------------------------------------------------------------------------
00416       // Normal stat
00417       //------------------------------------------------------------------------
00418       std::string pId;
00419       uint64_t    pSize;
00420       uint32_t    pFlags;
00421       uint64_t    pModTime;
00422   };
00423 
00424   //----------------------------------------------------------------------------
00426   //----------------------------------------------------------------------------
00427   class StatInfoVFS
00428   {
00429     public:
00430       //------------------------------------------------------------------------
00432       //------------------------------------------------------------------------
00433       StatInfoVFS();
00434 
00435       //------------------------------------------------------------------------
00437       //------------------------------------------------------------------------
00438       uint64_t GetNodesRW() const
00439       {
00440         return pNodesRW;
00441       }
00442 
00443       //------------------------------------------------------------------------
00445       //------------------------------------------------------------------------
00446       uint64_t GetFreeRW() const
00447       {
00448         return pFreeRW;
00449       }
00450 
00451       //------------------------------------------------------------------------
00453       //------------------------------------------------------------------------
00454       uint8_t GetUtilizationRW() const
00455       {
00456         return pUtilizationRW;
00457       }
00458 
00459       //------------------------------------------------------------------------
00461       //------------------------------------------------------------------------
00462       uint64_t GetNodesStaging() const
00463       {
00464         return pNodesStaging;
00465       }
00466 
00467       //------------------------------------------------------------------------
00469       //------------------------------------------------------------------------
00470       uint64_t GetFreeStaging() const
00471       {
00472         return pFreeStaging;
00473       }
00474 
00475       //------------------------------------------------------------------------
00477       //------------------------------------------------------------------------
00478       uint8_t GetUtilizationStaging() const
00479       {
00480         return pUtilizationStaging;
00481       }
00482 
00483       //------------------------------------------------------------------------
00485       //------------------------------------------------------------------------
00486       bool ParseServerResponse( const char *data );
00487 
00488     private:
00489 
00490       //------------------------------------------------------------------------
00491       // kXR_vfs stat
00492       //------------------------------------------------------------------------
00493       uint64_t    pNodesRW;
00494       uint64_t    pFreeRW;
00495       uint32_t    pUtilizationRW;
00496       uint64_t    pNodesStaging;
00497       uint64_t    pFreeStaging;
00498       uint32_t    pUtilizationStaging;
00499   };
00500 
00501   //----------------------------------------------------------------------------
00503   //----------------------------------------------------------------------------
00504   class DirectoryList
00505   {
00506     public:
00507       //------------------------------------------------------------------------
00509       //------------------------------------------------------------------------
00510       class ListEntry
00511       {
00512         public:
00513           //--------------------------------------------------------------------
00515           //--------------------------------------------------------------------
00516           ListEntry( const std::string &hostAddress,
00517                      const std::string &name,
00518                      StatInfo          *statInfo = 0):
00519             pHostAddress( hostAddress ),
00520             pName( name ),
00521             pStatInfo( statInfo )
00522           {}
00523 
00524           //--------------------------------------------------------------------
00526           //--------------------------------------------------------------------
00527           ~ListEntry()
00528           {
00529             delete pStatInfo;
00530           }
00531 
00532           //--------------------------------------------------------------------
00534           //--------------------------------------------------------------------
00535           const std::string &GetHostAddress() const
00536           {
00537             return pHostAddress;
00538           }
00539 
00540           //--------------------------------------------------------------------
00542           //--------------------------------------------------------------------
00543           const std::string &GetName() const
00544           {
00545             return pName;
00546           }
00547 
00548           //--------------------------------------------------------------------
00550           //--------------------------------------------------------------------
00551           StatInfo *GetStatInfo()
00552           {
00553             return pStatInfo;
00554           }
00555 
00556           //--------------------------------------------------------------------
00558           //--------------------------------------------------------------------
00559           const StatInfo *GetStatInfo() const
00560           {
00561             return pStatInfo;
00562           }
00563 
00564           //--------------------------------------------------------------------
00566           //--------------------------------------------------------------------
00567           void SetStatInfo( StatInfo *info )
00568           {
00569             pStatInfo = info;
00570           }
00571 
00572         private:
00573           std::string  pHostAddress;
00574           std::string  pName;
00575           StatInfo    *pStatInfo;
00576       };
00577 
00578       //------------------------------------------------------------------------
00580       //------------------------------------------------------------------------
00581       DirectoryList();
00582 
00583       //------------------------------------------------------------------------
00585       //------------------------------------------------------------------------
00586       ~DirectoryList();
00587 
00588       //------------------------------------------------------------------------
00590       //------------------------------------------------------------------------
00591       typedef std::vector<ListEntry*>  DirList;
00592 
00593       //------------------------------------------------------------------------
00595       //------------------------------------------------------------------------
00596       typedef DirList::iterator       Iterator;
00597 
00598       //------------------------------------------------------------------------
00600       //------------------------------------------------------------------------
00601       typedef DirList::const_iterator ConstIterator;
00602 
00603       //------------------------------------------------------------------------
00605       //------------------------------------------------------------------------
00606       void Add( ListEntry *entry )
00607       {
00608         pDirList.push_back( entry );
00609       }
00610 
00611       //------------------------------------------------------------------------
00613       //------------------------------------------------------------------------
00614       ListEntry *At( uint32_t index )
00615       {
00616         return pDirList[index];
00617       }
00618 
00619       //------------------------------------------------------------------------
00621       //------------------------------------------------------------------------
00622       Iterator Begin()
00623       {
00624         return pDirList.begin();
00625       }
00626 
00627       //------------------------------------------------------------------------
00629       //------------------------------------------------------------------------
00630       ConstIterator Begin() const
00631       {
00632         return pDirList.begin();
00633       }
00634 
00635       //------------------------------------------------------------------------
00637       //------------------------------------------------------------------------
00638       Iterator End()
00639       {
00640         return pDirList.end();
00641       }
00642 
00643       //------------------------------------------------------------------------
00645       //------------------------------------------------------------------------
00646       ConstIterator End() const
00647       {
00648         return pDirList.end();
00649       }
00650 
00651       //------------------------------------------------------------------------
00653       //------------------------------------------------------------------------
00654       uint32_t GetSize() const
00655       {
00656         return pDirList.size();
00657       }
00658 
00659       //------------------------------------------------------------------------
00661       //------------------------------------------------------------------------
00662       const std::string &GetParentName() const
00663       {
00664         return pParent;
00665       }
00666 
00667       //------------------------------------------------------------------------
00669       //------------------------------------------------------------------------
00670       void SetParentName( const std::string &parent )
00671       {
00672         pParent = parent;
00673         if( !pParent.empty() && pParent[pParent.length()-1] != '/' )
00674           pParent += "/";
00675       }
00676 
00677       //------------------------------------------------------------------------
00679       //------------------------------------------------------------------------
00680       bool ParseServerResponse( const std::string &hostId,
00681                                 const char *data );
00682 
00683     private:
00684       DirList     pDirList;
00685       std::string pParent;
00686   };
00687 
00688   //----------------------------------------------------------------------------
00690   //----------------------------------------------------------------------------
00691   class OpenInfo
00692   {
00693     public:
00694       //------------------------------------------------------------------------
00696       //------------------------------------------------------------------------
00697       OpenInfo( const uint8_t *fileHandle,
00698                 uint64_t       sessionId,
00699                 StatInfo *statInfo        = 0 ):
00700         pSessionId(sessionId), pStatInfo( statInfo )
00701       {
00702         memcpy( pFileHandle, fileHandle, 4 );
00703       }
00704 
00705       //------------------------------------------------------------------------
00707       //------------------------------------------------------------------------
00708       ~OpenInfo()
00709       {
00710         delete pStatInfo;
00711       }
00712 
00713       //------------------------------------------------------------------------
00715       //------------------------------------------------------------------------
00716       void GetFileHandle( uint8_t *fileHandle ) const
00717       {
00718         memcpy( fileHandle, pFileHandle, 4 );
00719       }
00720 
00721       //------------------------------------------------------------------------
00723       //------------------------------------------------------------------------
00724       const StatInfo *GetStatInfo() const
00725       {
00726         return pStatInfo;
00727       }
00728 
00729       //------------------------------------------------------------------------
00730       // Get session ID
00731       //------------------------------------------------------------------------
00732       uint64_t GetSessionId() const
00733       {
00734         return pSessionId;
00735       }
00736 
00737     private:
00738       uint8_t   pFileHandle[4];
00739       uint64_t  pSessionId;
00740       StatInfo *pStatInfo;
00741   };
00742 
00743   //----------------------------------------------------------------------------
00745   //----------------------------------------------------------------------------
00746   struct ChunkInfo
00747   {
00748     //--------------------------------------------------------------------------
00750     //--------------------------------------------------------------------------
00751     ChunkInfo( uint64_t off = 0, uint32_t len = 0, void *buff = 0 ):
00752       offset( off ), length( len ), buffer(buff) {}
00753 
00754     uint64_t  offset; 
00755     uint32_t  length; 
00756     void     *buffer; 
00757   };
00758 
00759   //----------------------------------------------------------------------------
00761   //----------------------------------------------------------------------------
00762   typedef std::vector<ChunkInfo> ChunkList;
00763 
00764   //----------------------------------------------------------------------------
00766   //----------------------------------------------------------------------------
00767   class VectorReadInfo
00768   {
00769     public:
00770       //------------------------------------------------------------------------
00772       //------------------------------------------------------------------------
00773       VectorReadInfo(): pSize( 0 ) {}
00774 
00775       //------------------------------------------------------------------------
00777       //------------------------------------------------------------------------
00778       uint32_t GetSize() const
00779       {
00780         return pSize;
00781       }
00782 
00783       //------------------------------------------------------------------------
00785       //------------------------------------------------------------------------
00786       void SetSize( uint32_t size )
00787       {
00788         pSize = size;
00789       }
00790 
00791       //------------------------------------------------------------------------
00793       //------------------------------------------------------------------------
00794       ChunkList &GetChunks()
00795       {
00796         return pChunks;
00797       }
00798 
00799       //------------------------------------------------------------------------
00801       //------------------------------------------------------------------------
00802       const ChunkList &GetChunks() const
00803       {
00804         return pChunks;
00805       }
00806 
00807     private:
00808       ChunkList pChunks;
00809       uint32_t  pSize;
00810   };
00811 
00812   //----------------------------------------------------------------------------
00813   // List of URLs
00814   //----------------------------------------------------------------------------
00815   struct HostInfo
00816   {
00817     HostInfo():
00818       flags(0), protocol(0), loadBalancer(false) {}
00819     HostInfo( const URL &u, bool lb = false ):
00820       flags(0), protocol(0), loadBalancer(lb), url(u) {}
00821     uint32_t flags;        
00822     uint32_t protocol;     
00823     bool     loadBalancer; 
00824     URL      url;          
00825   };
00826 
00827   typedef std::vector<HostInfo> HostList;
00828 
00829   //----------------------------------------------------------------------------
00831   //----------------------------------------------------------------------------
00832   class ResponseHandler
00833   {
00834     public:
00835       virtual ~ResponseHandler() {}
00836 
00837       //------------------------------------------------------------------------
00845       //------------------------------------------------------------------------
00846       virtual void HandleResponseWithHosts( XRootDStatus *status,
00847                                             AnyObject    *response,
00848                                             HostList     *hostList )
00849       {
00850         delete hostList;
00851         HandleResponse( status, response );
00852       }
00853 
00854       //------------------------------------------------------------------------
00861       //------------------------------------------------------------------------
00862       virtual void HandleResponse( XRootDStatus *status,
00863                                    AnyObject    *response )
00864       {
00865         (void)status; (void)response;
00866       }
00867   };
00868 }
00869 
00870 #endif // __XRD_CL_XROOTD_RESPONSES_HH__

Generated on 12 Dec 2014 for xrootd by  doxygen 1.4.7