XRootD
Loading...
Searching...
No Matches
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
40
enum
kCEntryStatus
{
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
//
52
class
XrdSutCacheEntryBuf
{
53
public
:
54
char
*
buf
;
55
kXR_int32
len
;
56
XrdSutCacheEntryBuf
(
char
*b = 0,
kXR_int32
l = 0);
57
XrdSutCacheEntryBuf
(
const
XrdSutCacheEntryBuf
&b);
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
//
75
class
XrdSutCacheEntry
{
76
public
:
77
char
*
name
;
78
short
status
;
79
short
cnt
;
// counter
80
kXR_int32
mtime
;
// time of last modification / creation
81
XrdSutCacheEntryBuf
buf1
;
82
XrdSutCacheEntryBuf
buf2
;
83
XrdSutCacheEntryBuf
buf3
;
84
XrdSutCacheEntryBuf
buf4
;
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);
88
XrdSutCacheEntry
(
const
XrdSutCacheEntry
&e);
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
96
XrdSutCacheEntry
&
operator=
(
const
XrdSutCacheEntry
&pfe);
97
};
98
99
class
XrdSutCERef
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
:
126
XrdSysRWLock
*
rwlock
;
127
};
128
129
#endif
XPtypes.hh
kXR_int32
int kXR_int32
Definition
XPtypes.hh:89
kCEntryStatus
kCEntryStatus
Definition
XrdSutCacheEntry.hh:40
kCE_special
@ kCE_special
Definition
XrdSutCacheEntry.hh:46
kCE_ok
@ kCE_ok
Definition
XrdSutCacheEntry.hh:45
kCE_allowed
@ kCE_allowed
Definition
XrdSutCacheEntry.hh:43
kCE_disabled
@ kCE_disabled
Definition
XrdSutCacheEntry.hh:42
kCE_inactive
@ kCE_inactive
Definition
XrdSutCacheEntry.hh:41
kCE_expired
@ kCE_expired
Definition
XrdSutCacheEntry.hh:44
XrdSysPthread.hh
XrdSutCERef
Definition
XrdSutCacheEntry.hh:100
XrdSutCERef::UnLock
void UnLock(bool reset=true)
Definition
XrdSutCacheEntry.hh:120
XrdSutCERef::WriteLock
void WriteLock(XrdSysRWLock *lock=0)
Definition
XrdSutCacheEntry.hh:108
XrdSutCERef::ReadLock
void ReadLock(XrdSysRWLock *lock=0)
Definition
XrdSutCacheEntry.hh:103
XrdSutCERef::rwlock
XrdSysRWLock * rwlock
Definition
XrdSutCacheEntry.hh:126
XrdSutCERef::Set
void Set(XrdSysRWLock *lock)
Definition
XrdSutCacheEntry.hh:113
XrdSutCERef::~XrdSutCERef
~XrdSutCERef()
Definition
XrdSutCacheEntry.hh:124
XrdSutCERef::XrdSutCERef
XrdSutCERef()
Definition
XrdSutCacheEntry.hh:122
XrdSutCacheEntryBuf
Definition
XrdSutCacheEntry.hh:52
XrdSutCacheEntryBuf::len
kXR_int32 len
Definition
XrdSutCacheEntry.hh:55
XrdSutCacheEntryBuf::buf
char * buf
Definition
XrdSutCacheEntry.hh:54
XrdSutCacheEntryBuf::~XrdSutCacheEntryBuf
virtual ~XrdSutCacheEntryBuf()
Definition
XrdSutCacheEntry.hh:59
XrdSutCacheEntryBuf::SetBuf
void SetBuf(const char *b=0, kXR_int32 l=0)
Definition
XrdSutCacheEntry.cc:66
XrdSutCacheEntry
Definition
XrdSutCacheEntry.hh:75
XrdSutCacheEntry::status
short status
Definition
XrdSutCacheEntry.hh:78
XrdSutCacheEntry::rwmtx
XrdSysRWLock rwmtx
Definition
XrdSutCacheEntry.hh:85
XrdSutCacheEntry::AsString
char * AsString() const
Definition
XrdSutCacheEntry.cc:152
XrdSutCacheEntry::SetName
void SetName(const char *n=0)
Definition
XrdSutCacheEntry.cc:136
XrdSutCacheEntry::~XrdSutCacheEntry
virtual ~XrdSutCacheEntry()
Definition
XrdSutCacheEntry.hh:89
XrdSutCacheEntry::name
char * name
Definition
XrdSutCacheEntry.hh:77
XrdSutCacheEntry::cnt
short cnt
Definition
XrdSutCacheEntry.hh:79
XrdSutCacheEntry::operator=
XrdSutCacheEntry & operator=(const XrdSutCacheEntry &pfe)
Definition
XrdSutCacheEntry.cc:170
XrdSutCacheEntry::Length
kXR_int32 Length() const
Definition
XrdSutCacheEntry.hh:90
XrdSutCacheEntry::mtime
kXR_int32 mtime
Definition
XrdSutCacheEntry.hh:80
XrdSutCacheEntry::buf2
XrdSutCacheEntryBuf buf2
Definition
XrdSutCacheEntry.hh:82
XrdSutCacheEntry::buf4
XrdSutCacheEntryBuf buf4
Definition
XrdSutCacheEntry.hh:84
XrdSutCacheEntry::buf1
XrdSutCacheEntryBuf buf1
Definition
XrdSutCacheEntry.hh:81
XrdSutCacheEntry::Reset
void Reset()
Definition
XrdSutCacheEntry.cc:119
XrdSutCacheEntry::buf3
XrdSutCacheEntryBuf buf3
Definition
XrdSutCacheEntry.hh:83
XrdSysRWLock
Definition
XrdSysPthread.hh:330
XrdSysRWLock::ReadLock
void ReadLock()
Definition
XrdSysPthread.hh:342
XrdSysRWLock::WriteLock
void WriteLock()
Definition
XrdSysPthread.hh:343
XrdSysRWLock::UnLock
void UnLock()
Definition
XrdSysPthread.hh:348
XrdSut
XrdSutCacheEntry.hh
Generated by
1.9.7