XRootD
XrdSutBuffer.hh
Go to the documentation of this file.
1 #ifndef __SUT_BUFFER_H__
2 #define __SUT_BUFFER_H__
3 /******************************************************************************/
4 /* */
5 /* X r d S u t B u f f e r . h h */
6 /* */
7 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* Produced by Geri 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 #ifndef __SUT_BUCKLIST_H__
32 #include "XrdSut/XrdSutBuckList.hh"
33 #endif
34 
35 /******************************************************************************/
36 /* */
37 /* Buffer structure for managing exchanged buckets */
38 /* */
39 /******************************************************************************/
40 
41 class XrdOucString;
42 
43 class XrdSutBuffer {
44 
45 private:
46 
47  XrdSutBuckList fBuckets;
48  XrdOucString fOptions;
49  XrdOucString fProtocol;
50  kXR_int32 fStep;
51 
52 public:
53  XrdSutBuffer(const char *prot, const char *opts = 0)
54  {fOptions = opts; fProtocol = prot; fStep = 0;}
55  XrdSutBuffer(const char *buffer, kXR_int32 length);
56 
57  virtual ~XrdSutBuffer();
58 
59  int AddBucket(char *bp=0, int sz=0, int ty=0)
60  { XrdSutBucket *b = new XrdSutBucket(bp,sz,ty);
61  if (b) { fBuckets.PushBack(b); return 0;} return -1; }
62  int AddBucket(XrdOucString s, int ty=0)
63  { XrdSutBucket *b = new XrdSutBucket(s,ty);
64  if (b) { fBuckets.PushBack(b); return 0;} return -1; }
66  { if (b) { fBuckets.PushBack(b); return 0;} return -1; }
67 
68  int UpdateBucket(const char *bp, int sz, int ty);
69  int UpdateBucket(XrdOucString s, int ty);
70 
71  // Remove from the list, to avoid destroy by ~XrdSutBuffer
72  void Remove(XrdSutBucket *b) { fBuckets.Remove(b); }
73 
74  void Dump(const char *stepstr = 0, bool all = false);
75  void Message(const char *prepose = 0);
76  int Serialized(char **buffer, char opt = 'n');
77 
78  void Deactivate(kXR_int32 type); // Deactivate bucket (type=-1 for cleanup)
79 
80  // To fill / access buckets containing 4-byte integers (status codes, versions ...)
83 
84  XrdSutBucket *GetBucket(kXR_int32 type, const char *tag = 0);
85  XrdSutBuckList *GetBuckList() const { return (XrdSutBuckList *)&fBuckets; }
86  int GetNBuckets() const { return fBuckets.Size(); }
87  const char *GetOptions() const { return fOptions.c_str(); }
88  const char *GetProtocol() const { return fProtocol.c_str(); }
89  int GetStep() const { return (int)fStep; }
90  void SetStep(int s) { fStep = (kXR_int32)s; }
91  void IncrementStep() { fStep++; }
92 };
93 
94 #endif
95 
int kXR_int32
Definition: XPtypes.hh:89
struct myOpts opts
const char * c_str() const
void Remove(XrdSutBucket *b)
void PushBack(XrdSutBucket *b)
int Size() const
int AddBucket(char *bp=0, int sz=0, int ty=0)
Definition: XrdSutBuffer.hh:59
int UpdateBucket(const char *bp, int sz, int ty)
void Message(const char *prepose=0)
int AddBucket(XrdOucString s, int ty=0)
Definition: XrdSutBuffer.hh:62
int Serialized(char **buffer, char opt='n')
const char * GetOptions() const
Definition: XrdSutBuffer.hh:87
int GetNBuckets() const
Definition: XrdSutBuffer.hh:86
void SetStep(int s)
Definition: XrdSutBuffer.hh:90
XrdSutBuffer(const char *prot, const char *opts=0)
Definition: XrdSutBuffer.hh:53
XrdSutBuckList * GetBuckList() const
Definition: XrdSutBuffer.hh:85
void IncrementStep()
Definition: XrdSutBuffer.hh:91
void Dump(const char *stepstr=0, bool all=false)
virtual ~XrdSutBuffer()
int GetStep() const
Definition: XrdSutBuffer.hh:89
int AddBucket(XrdSutBucket *b)
Definition: XrdSutBuffer.hh:65
XrdSutBucket * GetBucket(kXR_int32 type, const char *tag=0)
kXR_int32 MarshalBucket(kXR_int32 type, kXR_int32 code)
void Remove(XrdSutBucket *b)
Definition: XrdSutBuffer.hh:72
const char * GetProtocol() const
Definition: XrdSutBuffer.hh:88
void Deactivate(kXR_int32 type)
kXR_int32 UnmarshalBucket(kXR_int32 type, kXR_int32 &code)