XRootD
XrdSutPFEntry.cc
Go to the documentation of this file.
1
/******************************************************************************/
2
/* */
3
/* X r d S u t P F E n t r y . c c */
4
/* */
5
/* (c) 2012 by the Board of Trustees of the Leland Stanford, Jr., University */
6
/* Produced by Gerri Ganis for CERN */
7
/* */
8
/* This file is part of the XRootD software suite. */
9
/* */
10
/* XRootD is free software: you can redistribute it and/or modify it under */
11
/* the terms of the GNU Lesser General Public License as published by the */
12
/* Free Software Foundation, either version 3 of the License, or (at your */
13
/* option) any later version. */
14
/* */
15
/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
16
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
17
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
18
/* License for more details. */
19
/* */
20
/* You should have received a copy of the GNU Lesser General Public License */
21
/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
22
/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
23
/* */
24
/* The copyright holder's institutional names and contributor's names may not */
25
/* be used to endorse or promote products derived from this software without */
26
/* specific prior written permission of the institution or contributor. */
27
/******************************************************************************/
28
29
#include <cstdio>
30
#include <cstring>
31
#include <ctime>
32
33
#include "
XrdSutAux.hh
"
34
#include "
XrdSutPFEntry.hh
"
35
36
//__________________________________________________________________
37
XrdSutPFBuf::XrdSutPFBuf
(
char
*b,
kXR_int32
l)
38
{
39
// Constructor
40
41
len
= 0;
42
buf
= 0;
43
if
(b) {
44
buf
= b;
45
len
= l;
46
}
47
}
48
49
//__________________________________________________________________
50
XrdSutPFBuf::XrdSutPFBuf
(
const
XrdSutPFBuf
&b)
51
{
52
//Copy constructor
53
54
buf
= 0;
55
len
= 0;
56
if
(b.
buf
) {
57
buf
=
new
char
[b.
len
];
58
if
(
buf
) {
59
memcpy(
buf
,b.
buf
,b.
len
);
60
len
= b.
len
;
61
}
62
}
63
}
64
65
//__________________________________________________________________
66
void
XrdSutPFBuf::SetBuf
(
const
char
*b,
kXR_int32
l)
67
{
68
// Set the buffer
69
70
len
= 0;
71
if
(
buf
) {
72
delete
[]
buf
;
73
buf
= 0;
74
}
75
if
(b && l > 0) {
76
buf
=
new
char
[l];
77
if
(
buf
) {
78
memcpy(
buf
,b,l);
79
len
= l;
80
}
81
}
82
}
83
84
//____________________________________________________________________
85
XrdSutPFEntry::XrdSutPFEntry
(
const
char
*n,
short
st,
short
cn,
86
kXR_int32
mt)
87
{
88
// Constructor
89
90
name
= 0;
91
status
= st;
92
cnt
= cn;
93
mtime
= (mt > 0) ? mt : (
kXR_int32
)time(0);
94
if
(n) {
95
name
=
new
char
[strlen(n)+1];
96
if
(
name
)
97
strcpy(
name
,n);
98
}
99
}
100
101
//_____________________________________________________________________
102
XrdSutPFEntry::XrdSutPFEntry
(
const
XrdSutPFEntry
&e) : buf1(e.buf1),
103
buf2(e.buf2), buf3(e.buf3), buf4(e.buf4)
104
{
105
// Copy constructor
106
107
name
= 0;
108
status
= e.
status
;
109
cnt
= e.
cnt
;
110
mtime
= e.
mtime
;
111
if
(e.
name
) {
112
name
=
new
char
[strlen(e.
name
)+1];
113
if
(
name
)
114
strcpy(
name
,e.
name
);
115
}
116
}
117
118
//____________________________________________________________________
119
void
XrdSutPFEntry::Reset
()
120
{
121
// Resetting entry
122
123
if
(
name
)
124
delete
[]
name
;
125
name
= 0;
126
status
= 0;
127
cnt
= 0;
128
mtime
= (
kXR_int32
)time(0);
129
buf1
.
SetBuf
();
130
buf2
.
SetBuf
();
131
buf3
.
SetBuf
();
132
buf4
.
SetBuf
();
133
}
134
135
//_____________________________________________________________________
136
void
XrdSutPFEntry::SetName
(
const
char
*n)
137
{
138
// Set the name
139
140
if
(
name
) {
141
delete
[]
name
;
142
name
= 0;
143
}
144
if
(n) {
145
name
=
new
char
[strlen(n)+1];
146
if
(
name
)
147
strcpy(
name
,n);
148
}
149
}
150
151
//_____________________________________________________________________
152
char
*
XrdSutPFEntry::AsString
()
const
153
{
154
// Return a string with serialized information
155
// For print purposes
156
// The output string points to a static buffer, so it must
157
// not be deleted by the caller
158
static
char
pbuf[2048];
159
160
char
smt[20] = {0};
161
XrdSutTimeString
(
mtime
,smt);
162
163
sprintf(pbuf,
"st:%d cn:%d buf:%d,%d,%d,%d modified:%s name:%s"
,
164
status
,
cnt
,
buf1
.
len
,
buf2
.
len
,
buf3
.
len
,
buf4
.
len
,smt,
name
);
165
166
return
pbuf;
167
}
168
169
//______________________________________________________________________________
170
XrdSutPFEntry
&
XrdSutPFEntry::operator=
(
const
XrdSutPFEntry
&e)
171
{
172
// Assign entry e to local entry.
173
174
SetName
(
name
);
175
status
= e.
status
;
176
cnt
= e.
cnt
;
// counter
177
mtime
= e.
mtime
;
// time of last modification / creation
178
buf1
.
SetBuf
(e.
buf1
.
buf
);
179
buf2
.
SetBuf
(e.
buf2
.
buf
);
180
buf3
.
SetBuf
(e.
buf3
.
buf
);
181
buf4
.
SetBuf
(e.
buf4
.
buf
);
182
183
return
(*
this
);
184
}
kXR_int32
int kXR_int32
Definition:
XPtypes.hh:89
XrdSutTimeString
int XrdSutTimeString(int t, char *st, int opt)
Definition:
XrdSutAux.cc:311
XrdSutAux.hh
XrdSutPFEntry.hh
XrdSutPFBuf
Definition:
XrdSutPFEntry.hh:55
XrdSutPFBuf::SetBuf
void SetBuf(const char *b=0, kXR_int32 l=0)
Definition:
XrdSutPFEntry.cc:66
XrdSutPFBuf::buf
char * buf
Definition:
XrdSutPFEntry.hh:57
XrdSutPFBuf::XrdSutPFBuf
XrdSutPFBuf(char *b=0, kXR_int32 l=0)
Definition:
XrdSutPFEntry.cc:37
XrdSutPFBuf::len
kXR_int32 len
Definition:
XrdSutPFEntry.hh:58
XrdSutPFEntry
Definition:
XrdSutPFEntry.hh:78
XrdSutPFEntry::mtime
kXR_int32 mtime
Definition:
XrdSutPFEntry.hh:83
XrdSutPFEntry::buf3
XrdSutPFBuf buf3
Definition:
XrdSutPFEntry.hh:86
XrdSutPFEntry::buf1
XrdSutPFBuf buf1
Definition:
XrdSutPFEntry.hh:84
XrdSutPFEntry::operator=
XrdSutPFEntry & operator=(const XrdSutPFEntry &pfe)
Definition:
XrdSutPFEntry.cc:170
XrdSutPFEntry::AsString
char * AsString() const
Definition:
XrdSutPFEntry.cc:152
XrdSutPFEntry::SetName
void SetName(const char *n=0)
Definition:
XrdSutPFEntry.cc:136
XrdSutPFEntry::status
short status
Definition:
XrdSutPFEntry.hh:81
XrdSutPFEntry::XrdSutPFEntry
XrdSutPFEntry(const char *n=0, short st=0, short cn=0, kXR_int32 mt=0)
Definition:
XrdSutPFEntry.cc:85
XrdSutPFEntry::buf2
XrdSutPFBuf buf2
Definition:
XrdSutPFEntry.hh:85
XrdSutPFEntry::buf4
XrdSutPFBuf buf4
Definition:
XrdSutPFEntry.hh:87
XrdSutPFEntry::Reset
void Reset()
Definition:
XrdSutPFEntry.cc:119
XrdSutPFEntry::cnt
short cnt
Definition:
XrdSutPFEntry.hh:82
XrdSutPFEntry::name
char * name
Definition:
XrdSutPFEntry.hh:80
XrdSut
XrdSutPFEntry.cc
Generated by
1.9.1