XrdSutPFile.hh

Go to the documentation of this file.
00001 // $Id: XrdSutPFile.hh 22437 2008-03-04 14:35:16Z rdm $
00002 #ifndef __SUT_PFILE_H
00003 #define __SUT_PFILE_H
00004 
00005 /******************************************************************************/
00006 /*                                                                            */
00007 /*                      X r d S u t P F i l e . h h                           */
00008 /*                                                                            */
00009 /* (c) 2005 by the Board of Trustees of the Leland Stanford, Jr., University  */
00010 /*       All Rights Reserved. See XrdInfo.cc for complete License Terms       */
00011 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00012 /*              DE-AC03-76-SFO0515 with the Department of Energy              */
00013 /******************************************************************************/
00014 
00015 #ifndef __XPROTOCOL_H
00016 #include <XProtocol/XProtocol.hh>
00017 #endif
00018 #ifndef __OOUC_HASH__
00019 #include <XrdOuc/XrdOucHash.hh>
00020 #endif
00021 #ifndef __OUC_STRING_H__
00022 #include <XrdOuc/XrdOucString.hh>
00023 #endif
00024 /******************************************************************************/
00025 /*                                                                            */
00026 /*  Interface class to file to store login-related information                */
00027 /*                                                                            */
00028 /******************************************************************************/
00029 
00030 #define kFileIDSize  8
00031 #define kDefFileID  "XrdIF"
00032 #define kXrdIFVersion  1
00033 
00034 #define kOfsFileID   0
00035 #define kOfsVersion  8     // == kFileIDSize (if this changes remember to scale
00036 #define kOfsCtime    12    //                 accordingly the other offsets ...)
00037 #define kOfsItime    16
00038 #define kOfsEntries  20
00039 #define kOfsIndOfs   24
00040 #define kOfsJnkSiz   28
00041 
00042 #define kPFEcreate   0x1
00043 #define kPFEopen     0x2
00044 
00045 #define kMaxLockTries  3
00046 
00047 enum EPFileErrors {
00048    kPFErrBadInputs,
00049    kPFErrFileAlreadyOpen,
00050    kPFErrNoFile,
00051    kPFErrFileRename,
00052    kPFErrStat,
00053    kPFErrFileOpen,
00054    kPFErrFileNotOpen,
00055    kPFErrLocking,
00056    kPFErrUnlocking,
00057    kPFErrFileLocked,
00058    kPFErrSeek,
00059    kPFErrRead,
00060    kPFErrOutOfMemory,
00061    kPFErrLenMismatch,
00062    kPFErrBadOp
00063 };
00064 
00065 class XrdSutPFEntry;
00066 
00067 class XrdSutPFEntInd {
00068 public:
00069    char  *name;
00070    kXR_int32  nxtofs;
00071    kXR_int32  entofs;
00072    kXR_int32  entsiz;
00073    XrdSutPFEntInd(const char *n = 0,
00074                   kXR_int32 no = 0, kXR_int32 eo = 0, kXR_int32 es = 0);
00075    XrdSutPFEntInd(const XrdSutPFEntInd &ei);
00076    virtual ~XrdSutPFEntInd() { if (name) delete[] name; } 
00077 
00078    kXR_int32 Length() const { return (strlen(name) + 4*sizeof(kXR_int32)); }
00079    void SetName(const char *n = 0);
00080 
00081    // Assignement operator
00082    XrdSutPFEntInd &operator=(const XrdSutPFEntInd ei);
00083 };
00084 
00085 class XrdSutPFHeader {
00086 public:
00087    char   fileID[kFileIDSize];
00088    kXR_int32  version;
00089    kXR_int32  ctime;           // time of file change
00090    kXR_int32  itime;           // time of index change
00091    kXR_int32  entries;
00092    kXR_int32  indofs;
00093    kXR_int32  jnksiz;          // number of unreachable bytes
00094    XrdSutPFHeader(const char *id = "       ", kXR_int32 v = 0, kXR_int32 ct = 0,
00095                   kXR_int32 it = 0, kXR_int32 ent = 0, kXR_int32 ofs = 0);
00096    XrdSutPFHeader(const XrdSutPFHeader &fh);
00097    virtual ~XrdSutPFHeader() { }
00098    void Print() const;
00099 
00100    static kXR_int32 Length() { return (kFileIDSize + 6*sizeof(kXR_int32)); }
00101 };
00102 
00103 
00104 class XrdSutPFile {
00105 
00106    friend class XrdSutCache;          // for open/close operation;
00107 
00108 private:
00109    char                  *name;
00110    bool                   valid;      // If the file is usable ...
00111    kXR_int32              fFd;
00112    XrdOucHash<kXR_int32> *fHashTable; // Reflects the file index structure
00113    kXR_int32              fHTutime;   // time at which fHashTable was updated
00114    kXR_int32              fError;     // last error
00115    XrdOucString           fErrStr;    // description of last error
00116 
00117    // Entry low level access
00118    kXR_int32 WriteHeader(XrdSutPFHeader hd);
00119    kXR_int32 ReadHeader(XrdSutPFHeader &hd);
00120    kXR_int32 WriteInd(kXR_int32 ofs, XrdSutPFEntInd ind);
00121    kXR_int32 ReadInd(kXR_int32 ofs, XrdSutPFEntInd &ind);
00122    kXR_int32 WriteEnt(kXR_int32 ofs, XrdSutPFEntry ent);
00123    kXR_int32 ReadEnt(kXR_int32 ofs, XrdSutPFEntry &ent);
00124 
00125    // Reset (set inactive)
00126    kXR_int32 Reset(kXR_int32 ofs, kXR_int32 size);
00127 
00128    // Hash table operations
00129    kXR_int32 UpdateHashTable(bool force = 0);
00130 
00131    // For errors
00132    kXR_int32 Err(kXR_int32 code, const char *loc,
00133                  const char *em1 = 0, const char *em2 = 0);
00134 
00135 public:
00136    XrdSutPFile(const char *n, kXR_int32 openmode = kPFEcreate,
00137                kXR_int32 createmode = 0600, bool hashtab = 1);
00138    XrdSutPFile(const XrdSutPFile &f);
00139    virtual ~XrdSutPFile();
00140 
00141    // Initialization method
00142    bool Init(const char *n, kXR_int32 openmode = kPFEcreate,
00143              kXR_int32 createmode = 0600, bool hashtab = 1);
00144 
00145    // Open/Close operations
00146    kXR_int32 Open(kXR_int32 opt, bool *wasopen = 0,
00147                   const char *nam = 0, kXR_int32 createmode = 0600);
00148    kXR_int32 Close(kXR_int32 d = -1);
00149 
00150    // File name
00151    const char *Name() const { return (const char *)name; }
00152    // (Un)Successful attachement
00153    bool IsValid() const { return valid; }
00154    // Last error
00155    kXR_int32 LastError() const { return fError; }
00156    const char *LastErrStr() const { return (const char *)fErrStr.c_str(); }
00157 
00158    // Update Methods
00159    kXR_int32 RemoveEntry(const char *name);
00160    kXR_int32 RemoveEntry(kXR_int32 ofs);
00161    kXR_int32 RemoveEntries(const char *name, char opt);
00162    kXR_int32 Trim(const char *fbak = 0);
00163    kXR_int32 UpdateHeader(XrdSutPFHeader hd);
00164    kXR_int32 WriteEntry(XrdSutPFEntry ent);
00165    kXR_int32 UpdateCount(const char *nm, int *cnt = 0, int step = 1, bool reset = 0);
00166    kXR_int32 ResetCount(const char *nm) { return UpdateCount(nm,0,0,1); }
00167    kXR_int32 ReadCount(const char *nm, int &cnt) { return UpdateCount(nm,&cnt,0); }
00168 
00169    // Access methods   
00170    kXR_int32 RetrieveHeader(XrdSutPFHeader &hd);
00171    kXR_int32 ReadEntry(const char *name, XrdSutPFEntry &ent, int opt = 0);
00172    kXR_int32 ReadEntry(kXR_int32 ofs, XrdSutPFEntry &ent);
00173    kXR_int32 SearchEntries(const char *name, char opt,
00174                            kXR_int32 *ofs = 0, kXR_int32 nofs = 1);
00175    kXR_int32 SearchSpecialEntries(kXR_int32 *ofs = 0, kXR_int32 nofs = 1);
00176 
00177    // Browser
00178    kXR_int32 Browse(void *out = 0);
00179 };
00180 
00181 #endif

Generated on Tue Jul 5 14:47:03 2011 for ROOT_528-00b_version by  doxygen 1.5.1