Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-03-13 09:31:07

0001 #ifndef __XRDXROOTDGSTREAM_HH_
0002 #define __XRDXROOTDGSTREAM_HH_
0003 /******************************************************************************/
0004 /*                                                                            */
0005 /*                    X r d X r o o t G S t r e a m . h h                     */
0006 /*                                                                            */
0007 /* (c) 2019 by the Board of Trustees of the Leland Stanford, Jr., University  */
0008 /*                            All Rights Reserved                             */
0009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
0010 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
0011 /*                                                                            */
0012 /* This file is part of the XRootD software suite.                            */
0013 /*                                                                            */
0014 /* XRootD is free software: you can redistribute it and/or modify it under    */
0015 /* the terms of the GNU Lesser General Public License as published by the     */
0016 /* Free Software Foundation, either version 3 of the License, or (at your     */
0017 /* option) any later version.                                                 */
0018 /*                                                                            */
0019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
0020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
0021 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
0022 /* License for more details.                                                  */
0023 /*                                                                            */
0024 /* You should have received a copy of the GNU Lesser General Public License   */
0025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
0026 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
0027 /*                                                                            */
0028 /* The copyright holder's institutional names and contributor's names may not */
0029 /* be used to endorse or promote products derived from this software without  */
0030 /* specific prior written permission of the institution or contributor.       */
0031 /******************************************************************************/
0032 
0033 #include <cstdint>
0034 
0035 //-----------------------------------------------------------------------------
0036 //! This class implements a generic reporter for the XRootD monitoring stream,
0037 //! also known as the G-Stream. It is passed to various plugins when monitoring
0038 //! is enabled to allow plugins to add monitoring information into the G-Stream.
0039 //-----------------------------------------------------------------------------
0040 
0041 class XrdXrootdGSReal;
0042 
0043 class XrdXrootdGStream
0044 {
0045 public:
0046 
0047 //-----------------------------------------------------------------------------
0048 //! Flush any pending monitoring messages to the data collector. Also, see
0049 //! the related SetAutoFlush() method.
0050 //-----------------------------------------------------------------------------
0051 
0052 void      Flush();
0053 
0054 //-----------------------------------------------------------------------------
0055 //! Obtain a dictionary ID to map a string to an integer ID. The mapping is
0056 //! automatically sent to the monitor collector for future use using the
0057 //! 'd' or 'i' mapping identifier.
0058 //!
0059 //! @param  text   -> the null terminated string to be assigned an ID. The
0060 //!                   text must be less than or equal to 1024 characters.
0061 //! @param isPath     when true the text specified a file system path and
0062 //!                   identified as a XROOTD_MON_MAPPATH item. Otherwise,
0063 //!                   it is identified as a XROOTD_MON_MAPINFO item.
0064 //!
0065 //! @return the integer identifier assigned to the string information. The
0066 //!         returned value is in network byte order!
0067 //-----------------------------------------------------------------------------
0068 
0069 uint32_t  GetDictID(const char *text, bool isPath=false);
0070 
0071 //-----------------------------------------------------------------------------
0072 //! Check if payload is fronted by a header.
0073 //!
0074 //! @return true      payload is fronted by a header.
0075 //! @return false     payload is not fronted by a header. GetDictID() mappings
0076 //!                   are not sent and must be manually included inline.
0077 //-----------------------------------------------------------------------------
0078 
0079 bool      HasHdr();
0080 
0081 //-----------------------------------------------------------------------------
0082 //! Insert information into the G-Stream.
0083 //!
0084 //! @param  data   -> to null-terminated text to be included in the G-Stream.
0085 //! @param  dlen      the length of the text *including* the null character.
0086 //!                   Requires that (8 <= dlen <= MaxDataLen); defined below.
0087 //!
0088 //! @return true      data included.
0089 //! @return false     data rejected; invalid length or is not null terminated.
0090 //-----------------------------------------------------------------------------
0091 
0092 bool      Insert(const char *data, int dlen);
0093 
0094 //-----------------------------------------------------------------------------
0095 //! Insert information into the G-Stream using the data placed in the buffer
0096 //! space obtained by a previous call to Reserve(). Upon return, this object
0097 //! is unlocked.
0098 //!
0099 //! @param  dlen      the number of bytes actually present in the buffer. The
0100 //!                   text must end with a null byte and dlen must be
0101 //!                   8 <= dlen <= dlen used in the previous Reserve() call.
0102 //!
0103 //! @return true      data included.
0104 //! @return false     data rejected; invalid length or no buffer outstanding.
0105 //-----------------------------------------------------------------------------
0106 
0107 bool      Insert(int dlen);
0108 
0109 //-----------------------------------------------------------------------------
0110 //! Obtain a buffer space for information. This object is locked and no other
0111 //! thread can insert information until the buffer is inserted using Insert().
0112 //!
0113 //! @param  dlen      the number of bytes required to be available for use.
0114 //!                   Requires that (8 <= dlen <= MaxDataLen); defined below.
0115 //!
0116 //! @return !0        pointer to a dlen sized buffer.
0117 //! @return =0        invalid length specified or a buffer is outstanding.
0118 //-----------------------------------------------------------------------------
0119 
0120 char     *Reserve(int dlen);
0121 
0122 //-----------------------------------------------------------------------------
0123 //! Set autoflush time interval (or disable it). Disabling autoflush may be
0124 //! useful when data is periodically generated at a low rate and manual
0125 //! flushing would produce more consistent results.
0126 //!
0127 //! @param  afsec     Number of seconds between autoflushing. A zero or
0128 //!                   negative value disables autoflush. The default is
0129 //!                   600 seconds (i.e. 10 minutes) subject to what is
0130 //!                   specified via the xrootd.monitor flush directive.
0131 //!                   Positive values less that 60 are considered to be 60.
0132 //!
0133 //! @return The previous auto-flush setting.
0134 //-----------------------------------------------------------------------------
0135 
0136 int       SetAutoFlush(int afsec);
0137 
0138 //-----------------------------------------------------------------------------
0139 //! Get the amount of buffer space remaining.
0140 //!
0141 //! @return The maximum number of bytes that can be inserted at time of call.
0142 //-----------------------------------------------------------------------------
0143 
0144 int       Space();
0145 
0146 //-----------------------------------------------------------------------------
0147 //! The larest amount of data that can be inserted in a single call to GStream.
0148 //-----------------------------------------------------------------------------
0149 static
0150 const int MaxDataLen = 65280;
0151 
0152 //-----------------------------------------------------------------------------
0153 //! Constructor
0154 //!
0155 //! @param  gsRef     refrence to the G-Stream implementation.
0156 //-----------------------------------------------------------------------------
0157 
0158           XrdXrootdGStream(XrdXrootdGSReal &gsRef) : gStream(gsRef) {}
0159 
0160 protected:
0161 
0162 //-----------------------------------------------------------------------------
0163 //! Destructor. This stream should never be directly deleted.
0164 //-----------------------------------------------------------------------------
0165 
0166          ~XrdXrootdGStream() {}
0167 
0168 private:
0169 
0170 XrdXrootdGSReal &gStream;
0171 };
0172 #endif