XrdMonHeader.cc

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /*                                                                           */
00003 /*                              XrdMonHeader.cc                              */
00004 /*                                                                           */
00005 /* (c) 2005 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: XrdMonHeader.cc 24468 2008-06-22 16:47:03Z ganis $
00012 
00013 #include "XrdMon/XrdMonException.hh"
00014 #include "XrdMon/XrdMonCommon.hh"
00015 #include "XrdMon/XrdMonErrors.hh"
00016 #include "XrdMon/XrdMonHeader.hh"
00017 #include <netinet/in.h>
00018 #include <stdio.h>
00019 #include <string.h>
00020 #include <iomanip>
00021 using std::setw;
00022 
00023 vector<kXR_int32> XrdMonHeader::_prevStod;
00024 
00025 bool
00026 XrdMonHeader::stodChanged(senderid_t senderId) const
00027 {
00028     bool ret = true;
00029     if (  _prevStod.size() > senderId ) {
00030         ret = ( _prevStod[senderId] != stod() );
00031         if ( ret ) {
00032             _prevStod[senderId] = stod();
00033         }
00034     } else {
00035         _prevStod.push_back(stod());
00036     }
00037     return ret;
00038 }
00039 
00040 void
00041 XrdMonHeader::decode(const char* packet)
00042 {
00043     memcpy(&_header, packet, sizeof(XrdXrootdMonHeader));
00044     _header.plen = ntohs(_header.plen);
00045     _header.stod = ntohl(_header.stod);
00046     
00047     if (packetType() != PACKET_TYPE_TRACE &&
00048         packetType() != PACKET_TYPE_DICT  &&
00049         packetType() != PACKET_TYPE_ADMIN &&
00050         packetType() != PACKET_TYPE_STAGE &&
00051         packetType() != PACKET_TYPE_USER     ) {
00052         char buf[64];
00053         sprintf(buf, "Invalid packet type %c", packetType());
00054         throw XrdMonException(ERR_INVPACKETTYPE, buf);
00055     }
00056     if ( packetLen() < HDRLEN ) {
00057         char buf[64];
00058         sprintf(buf, "Invalid packet length %d", packetLen());
00059         throw XrdMonException(ERR_INVPACKETLEN, buf);
00060     }
00061 }
00062 
00063 ostream&
00064 operator<<(ostream& o, const XrdMonHeader& header)
00065 {
00066     o << "seq: "   << setw(3) << (int) header.seqNo() 
00067       <<", type: " << static_cast<char>(header.packetType())
00068       << " len: "  << setw(4) << header.packetLen() 
00069       << " time: " << header.stod();
00070     return o;
00071 }

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