xrootd
XrdCksCalc.hh
Go to the documentation of this file.
1 #ifndef __XRDCKSCALC_HH__
2 #define __XRDCKSCALC_HH__
3 /******************************************************************************/
4 /* */
5 /* X r d C k s C a l c . h h */
6 /* */
7 /* (c) 2011 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /******************************************************************************/
12 
13 // This class defines the interface to a checksum computation. When this class
14 // is used to define a plugin computation, the initial XrdCksCalc computation object
15 // is created by the XrdCksCalcInit() function defined at the end of this file.
16 
18 {
19 public:
20 
21 // Calc() Calculates a one-time checksum. The obvious default implementation
22 // is provided and assumes that Init() may be called more than once.
23 //
24 virtual char *Calc(const char *Buff, int BLen)
25  {Init(); Update(Buff, BLen); return Final();}
26 
27 // Current() returns the current binary checksum value (defaults to final).
28 // The final checksum result is not affected.
29 //
30 virtual char *Current() {return Final();}
31 
32 // Final() Returns the actual checksum in binary format.
33 //
34 virtual char *Final() = 0;
35 
36 // Init() Initializes data structures (must be called by constructor). This
37 // is always called to reuse the object for a new checksum.
38 //
39 virtual void Init() = 0;
40 
41 // New() Must provide a new instance of the underlying object.
42 //
43 virtual
44 XrdCksCalc *New() = 0;
45 
46 // Recycle() Is called when the object is no longer needed. A default is given.
47 //
48 virtual void Recycle() {delete this;}
49 
50 // Type() returns the character name of the checksum object and the number
51 // bytes (i.e. size) required for the checksum value.
52 //
53 virtual const char *Type(int &csSize) = 0;
54 
55 // Update() computes a running checksum and may be called repeatedly for
56 // data segments; with Final() returning the full checksum.
57 //
58 virtual void Update(const char *Buff, int BLen) = 0;
59 
61 virtual ~XrdCksCalc() {}
62 };
63 
64 /******************************************************************************/
65 /* C h e c k s u m O b j e c t C r e a t o r */
66 /******************************************************************************/
67 
68 /* When building a shared library plugin, the following "C" entry point must
69  exist in the library:
70 
71  extern "C"
72  {XrdCksCalc *XrdCksCalcInit(XrdSysError *eDest, // The error msg object
73  const char *csName, // Name of checksum
74  const char *cFN, // Config file name
75  const char *Parms); // Parms on lib directive
76  }
77 
78  This entry is called to get an instance of the checksum object which must
79  match the passed checksum name. If the object cannot be created; return 0.
80 */
81 #endif