xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
XrdSutCacheEntry.hh
Go to the documentation of this file.
1 #ifndef __SUT_CACHEENTRY_H
2 #define __SUT_CACHEENTRY_H
3 /******************************************************************************/
4 /* */
5 /* X r d S u t C a c h e E n t r y . h h */
6 /* */
7 /* (c) 2005 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* Produced by Gerri Ganis for CERN */
9 /* */
10 /* This file is part of the XRootD software suite. */
11 /* */
12 /* XRootD is free software: you can redistribute it and/or modify it under */
13 /* the terms of the GNU Lesser General Public License as published by the */
14 /* Free Software Foundation, either version 3 of the License, or (at your */
15 /* option) any later version. */
16 /* */
17 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20 /* License for more details. */
21 /* */
22 /* You should have received a copy of the GNU Lesser General Public License */
23 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25 /* */
26 /* The copyright holder's institutional names and contributor's names may not */
27 /* be used to endorse or promote products derived from this software without */
28 /* specific prior written permission of the institution or contributor. */
29 /******************************************************************************/
30 
31 #include "XProtocol/XPtypes.hh"
32 #include "XrdSys/XrdSysPthread.hh"
33 
34 /******************************************************************************/
35 /* */
36 /* Class defining the basic cache entry */
37 /* */
38 /******************************************************************************/
39 
41  kCE_inactive = -2, // -2 inactive: eliminated at next trim
42  kCE_disabled, // -1 disabled, cannot be enabled
43  kCE_allowed, // 0 empty creds, can be enabled
44  kCE_expired, // 1 enabled, creds to be changed at next used
45  kCE_ok, // 2 enabled and OK
46  kCE_special // 3 special (non-creds) entry
47 };
48 
49 //
50 // Buffer used internally by XrdGCEntry
51 //
53 public:
54  char *buf;
56  XrdSutCacheEntryBuf(char *b = 0, kXR_int32 l = 0);
58 
59  virtual ~XrdSutCacheEntryBuf() { if (len > 0 && buf) delete[] buf; }
60 
61  void SetBuf(const char *b = 0, kXR_int32 l = 0);
62 };
63 
64 //
65 // Generic cache entry: it stores a
66 //
67 // name
68 // status 2 bytes
69 // cnt 2 bytes
70 // mtime 4 bytes
71 // buf1, buf2, buf3, buf4
72 //
73 // The buffers are generic buffers to store bufferized info
74 //
76 public:
77  char *name;
78  short status;
79  short cnt; // counter
80  kXR_int32 mtime; // time of last modification / creation
85  XrdSysRWLock rwmtx; // Locked when reference is outstanding
86  XrdSutCacheEntry(const char *n = 0, short st = 0, short cn = 0,
87  kXR_int32 mt = 0);
89  virtual ~XrdSutCacheEntry() { if (name) delete[] name; }
90  kXR_int32 Length() const { return (buf1.len + buf2.len + 2*sizeof(short) +
91  buf3.len + buf4.len + 5*sizeof(kXR_int32)); }
92  void Reset();
93  void SetName(const char *n = 0);
94  char *AsString() const;
95 
97 };
98 
100 {
101 public:
102 
103 inline void ReadLock(XrdSysRWLock *lock = 0)
104  { if (lock) Set(lock);
105  rwlock->ReadLock();
106  };
107 
108 inline void WriteLock(XrdSysRWLock *lock = 0)
109  { if (lock) Set(lock);
110  rwlock->WriteLock();
111  };
112 
113 inline void Set(XrdSysRWLock *lock)
114  {if (rwlock) {if (rwlock != lock) rwlock->UnLock();
115  else return;
116  }
117  rwlock = lock;
118  };
119 
120 inline void UnLock(bool reset = true) {if (rwlock) {rwlock->UnLock(); if (reset) rwlock = 0; }}
121 
122  XrdSutCERef() : rwlock(0) {}
123 
124  ~XrdSutCERef() {if (rwlock) UnLock(); rwlock = 0; }
125 protected:
127 };
128 
129 #endif
kXR_int32 len
Definition: XrdSutCacheEntry.hh:55
XrdSutCERef()
Definition: XrdSutCacheEntry.hh:122
Definition: XrdSutCacheEntry.hh:46
void UnLock(bool reset=true)
Definition: XrdSutCacheEntry.hh:120
Definition: XrdSysPthread.hh:329
short status
Definition: XrdSutCacheEntry.hh:78
Definition: XrdSutCacheEntry.hh:99
kXR_int32 mtime
Definition: XrdSutCacheEntry.hh:80
void SetName(const char *n=0)
void ReadLock(XrdSysRWLock *lock=0)
Definition: XrdSutCacheEntry.hh:103
char * AsString() const
virtual ~XrdSutCacheEntryBuf()
Definition: XrdSutCacheEntry.hh:59
Definition: XrdSutCacheEntry.hh:45
XrdSutCacheEntryBuf buf4
Definition: XrdSutCacheEntry.hh:84
XrdSysRWLock rwmtx
Definition: XrdSutCacheEntry.hh:85
void ReadLock()
Definition: XrdSysPthread.hh:342
Definition: XrdSutCacheEntry.hh:43
char * name
Definition: XrdSutCacheEntry.hh:77
XrdSutCacheEntryBuf(char *b=0, kXR_int32 l=0)
kCEntryStatus
Definition: XrdSutCacheEntry.hh:40
XrdSutCacheEntry(const char *n=0, short st=0, short cn=0, kXR_int32 mt=0)
Definition: XrdSutCacheEntry.hh:44
Definition: XrdSutCacheEntry.hh:42
void WriteLock()
Definition: XrdSysPthread.hh:343
void WriteLock(XrdSysRWLock *lock=0)
Definition: XrdSutCacheEntry.hh:108
XrdSutCacheEntry & operator=(const XrdSutCacheEntry &pfe)
XrdSysRWLock * rwlock
Definition: XrdSutCacheEntry.hh:126
Definition: XrdSutCacheEntry.hh:41
Definition: XrdSutCacheEntry.hh:75
Definition: XrdSutCacheEntry.hh:52
XrdSutCacheEntryBuf buf2
Definition: XrdSutCacheEntry.hh:82
virtual ~XrdSutCacheEntry()
Definition: XrdSutCacheEntry.hh:89
XrdSutCacheEntryBuf buf3
Definition: XrdSutCacheEntry.hh:83
~XrdSutCERef()
Definition: XrdSutCacheEntry.hh:124
kXR_int32 Length() const
Definition: XrdSutCacheEntry.hh:90
int kXR_int32
Definition: XPtypes.hh:89
short cnt
Definition: XrdSutCacheEntry.hh:79
char * buf
Definition: XrdSutCacheEntry.hh:54
XrdSutCacheEntryBuf buf1
Definition: XrdSutCacheEntry.hh:81
void Set(XrdSysRWLock *lock)
Definition: XrdSutCacheEntry.hh:113
void UnLock()
Definition: XrdSysPthread.hh:348
void SetBuf(const char *b=0, kXR_int32 l=0)