Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

XrdSutCache.hh

Go to the documentation of this file.
00001 // $Id: XrdSutCache.hh 22437 2008-03-04 14:35:16Z rdm $
00002 #ifndef __SUT_CACHE_H__
00003 #define __SUT_CACHE_H__
00004 /******************************************************************************/
00005 /*                                                                            */
00006 /*                      X r d S u t C a c h e . h h                           */
00007 /*                                                                            */
00008 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University  */
00009 /*       All Rights Reserved. See XrdInfo.cc for complete License Terms       */
00010 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00011 /*              DE-AC03-76-SFO0515 with the Department of Energy              */
00012 /******************************************************************************/
00013 
00014 #include <XProtocol/XPtypes.hh>
00015 #include <XrdSut/XrdSutPFEntry.hh>
00016 #include <XrdOuc/XrdOucHash.hh>
00017 #include <XrdOuc/XrdOucString.hh>
00018 #include <XrdSys/XrdSysPthread.hh>
00019 
00020 /******************************************************************************/
00021 /*                                                                            */
00022 /*  For caching temporary information during the authentication handshake     */
00023 /*                                                                            */
00024 /******************************************************************************/
00025 
00026 class XrdSutCache
00027 {
00028 private:
00029    XrdSysRWLock    rwlock;  // Access synchronizator
00030    int             cachesz; // Number of entries allocated
00031    int             cachemx; // Largest Index of allocated entries
00032    XrdSutPFEntry **cachent; // Pointers to filled entries
00033    kXR_int32       utime;   // time at which was last updated
00034    int             lifetime; // lifetime (in secs) of the cache info 
00035    XrdOucHash<kXR_int32> hashtable; // Reflects the file index structure
00036    kXR_int32       htmtime;   // time at which hash table was last rebuild
00037    XrdOucString    pfile;   // file name (if loaded from file)
00038 
00039 public:
00040    XrdSutCache() { cachemx = -1; cachesz = 0; cachent = 0; lifetime = 300;
00041                    utime = -1; htmtime = -1; pfile = "";}
00042    virtual ~XrdSutCache();
00043 
00044    // Status
00045    int            Entries() const { return (cachemx+1); }
00046    bool           Empty() const { return (cachemx == -1); }
00047 
00048    // Initialization methods
00049    int            Init(int capacity = 100);
00050    int            Reset(int newsz = -1);
00051    int            Load(const char *pfname);  // build cache of a pwd file
00052    int            Flush(const char *pfname = 0);   // flush content to pwd file
00053    int            Refresh();    // refresh content from source file
00054    int            Rehash(bool force = 0, bool lock = 1);  // (re)build hash table
00055    void           SetLifetime(int lifet = 300) { lifetime = lifet; }
00056 
00057    // Cache management
00058    XrdSutPFEntry *Get(int i) const { return (i<=cachemx) ? cachent[i] :
00059                                                           (XrdSutPFEntry *)0; }
00060    XrdSutPFEntry *Get(const char *ID, bool *wild = 0);
00061    XrdSutPFEntry *Add(const char *ID, bool force = 0);
00062    bool           Remove(const char *ID, int opt = 1);
00063    int            Trim(int lifet = 0);
00064 
00065    // For debug purposes
00066    void           Dump(const char *msg= 0);
00067 };
00068 
00069 #endif
00070 

Generated on Sun Nov 6 13:35:17 2011 for xrootd by  doxygen 1.3.9.1