XrdMonDecOnePacket.cc

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /*                                                                           */
00003 /*                           XrdMonDecOnePacket.cc                           */
00004 /*                                                                           */
00005 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
00006 /*                            All Rights Reserved                            */
00007 /*       Produced by Jacek Becla for Stanford University under contract      */
00008 /*              DE-AC02-76SF00515 with the Department of Energy              */
00009 /*****************************************************************************/
00010 
00011 // $Id: XrdMonDecOnePacket.cc 22437 2008-03-04 14:35:16Z rdm $
00012 
00013 #include "XrdMon/XrdMonDecOnePacket.hh"
00014 #include "XrdMon/XrdMonHeader.hh"
00015 #include <iomanip>
00016 #include <netinet/in.h>
00017 #include <string.h>
00018 
00019 using std::setw;
00020 using std::streampos;
00021 
00022 long     XrdMonDecOnePacket::_nextNr    = 0;
00023 dictid_t XrdMonDecOnePacket::_minDictId = 0;
00024 dictid_t XrdMonDecOnePacket::_maxDictId = 0;
00025 
00026 XrdMonDecOnePacket::XrdMonDecOnePacket(bool)
00027     : _myNr(_nextNr++),
00028       _fPos(-1),
00029       _seq(LOST),
00030       _dictId(-1),
00031       _len(0)
00032 {}
00033 
00034 XrdMonDecOnePacket::XrdMonDecOnePacket(int errType, kXR_int64 pos)
00035     : _myNr(_nextNr++),
00036       _fPos(pos),
00037       _seq(errType),
00038       _dictId(-1),
00039       _len(0)
00040 {}
00041 
00042 int
00043 XrdMonDecOnePacket::init(const char* buf, int bytesLeft, kXR_int64 fPos)
00044 {
00045     if ( bytesLeft <= HDRLEN ) {
00046         return -1;
00047     }
00048         
00049     XrdMonHeader header;
00050     header.decode(buf);
00051 
00052     if ( header.packetLen() > bytesLeft ) {
00053         return -1;
00054     }
00055 
00056     _myNr = _nextNr++;
00057     
00058     
00059     _fPos   = fPos;
00060     _seq    = header.seqNo();
00061     _dictId = -1;
00062     _len    = header.packetLen();
00063     _stod   = header.stod();
00064     
00065     if ( header.packetType() == PACKET_TYPE_DICT ) {
00066         kXR_int32 x32;
00067         memcpy(&x32, buf+HDRLEN, sizeof(kXR_int32));
00068         _dictId = ntohl(x32);
00069     }
00070 
00071     if ( _dictId > 0 && _dictId < _minDictId ) {
00072         _minDictId = _dictId;
00073     }
00074     if ( _dictId > _maxDictId ) {
00075         _maxDictId = _dictId;
00076     }
00077 
00078     // skip the rest of the packet
00079     return header.packetLen();
00080 }
00081 
00082 ostream&
00083 operator<<(ostream& o, const XrdMonDecOnePacket& p)
00084 {
00085     o << setw(6)     << setw(5)  << p._myNr
00086       << ", fpos="   << setw(12) << p._fPos
00087       << ", seq="    << setw(3)  << p._seq 
00088       << ", dictId=" << setw(5)  << p._dictId;
00089 
00090     return o;
00091 }

Generated on Tue Jul 5 14:46:42 2011 for ROOT_528-00b_version by  doxygen 1.5.1