xrootd
XrdMonSndCoder.hh
Go to the documentation of this file.
1 /*****************************************************************************/
2 /* */
3 /* XrdMonSndCoder.hh */
4 /* */
5 /* (c) 2005 by the Board of Trustees of the Leland Stanford, Jr., University */
6 /* All Rights Reserved */
7 /* Produced by Jacek Becla for Stanford University under contract */
8 /* DE-AC02-76SF00515 with the Department of Energy */
9 /*****************************************************************************/
10 
11 // $Id$
12 
13 #ifndef XRDMONSNDCODER_HH
14 #define XRDMONSNDCODER_HH
15 
16 #include "XrdMon/XrdMonCommon.hh"
18 #include "XrdMon/XrdMonSndDebug.hh"
23 #include "XrdSys/XrdSysPlatform.hh"
24 #include "XrdSys/XrdSysHeaders.hh"
25 #include <assert.h>
26 #include <netinet/in.h>
27 #include <utility> // for pair
28 #include <vector>
29 using std::cerr;
30 using std::cout;
31 using std::endl;
32 using std::string;
33 using std::pair;
34 using std::vector;
35 
36 // The class responsible for coding data into a binary packet
37 
39 public:
41 
43  int prepare2Transfer(const vector<XrdMonSndTraceEntry>& vector);
44  int prepare2Transfer(const vector<kXR_int32>& vector);
47 
48  const XrdMonSndPacket& packet() { return _packet; }
49  void reset() { _packet.reset(); }
50  void printStats() const ;
51 
52 private:
53  char* writeHere() { return _packet.offset(_putOffset); }
54  int reinitXrdMonSndPacket(packetlen_t newSize, char packetCode);
55  pair<char, kXR_unt32> generateBigNumber(const char* descr);
56 
57  inline void add_int08_t(int8_t value) {
58  memcpy(writeHere(), &value, sizeof(int8_t));
60  cout << "stored int08_t value " << (int) value
61  << ", _putOffset " << _putOffset << endl;
62  }
63  _putOffset += sizeof(int8_t);
64  }
65  inline void add_kXR_int16(kXR_int16 value) {
66  kXR_int16 v = htons(value);
67  memcpy(writeHere(), &v, sizeof(kXR_int16));
69  cout << "stored kXR_int16 value " << value
70  << ", _putOffset " << _putOffset << endl;
71  }
72  _putOffset += sizeof(kXR_int16);
73  }
74  inline void add_kXR_unt16(kXR_unt16 value) {
75  kXR_unt16 v = htons(value);
76  memcpy(writeHere(), &v, sizeof(kXR_unt16));
78  cout << "stored kXR_unt16 value " << value
79  << ", _putOffset " << _putOffset << endl;
80  }
81  _putOffset += sizeof(kXR_unt16);
82  }
83  inline void add_kXR_int32(kXR_int32 value) {
84  kXR_int32 v = htonl(value);
85  memcpy(writeHere(), &v, sizeof(kXR_int32));
87  cout << "stored kXR_int32 value " << value
88  << ", _putOffset " << _putOffset << endl;
89  }
90  _putOffset += sizeof(kXR_int32);
91  }
92  inline void add_kXR_unt32(kXR_unt32 value) {
93  kXR_unt32 v = htonl(value);
94  memcpy(writeHere(), &v, sizeof(kXR_unt32));
96  cout << "stored kXR_unt32 value " << value
97  << ", _putOffset " << _putOffset << endl;
98  }
99  _putOffset += sizeof(kXR_unt32);
100  }
101  inline void add_kXR_int64(kXR_int64 value) {
102  kXR_int64 v = htonll(value);
103  memcpy(writeHere(), &v, sizeof(kXR_int64));
105  cout << "stored kXR_int64 value " << value
106  << ", _putOffset " << _putOffset << endl;
107  }
108  _putOffset += sizeof(kXR_int64);
109  }
110  inline void add_Mark(char mark, int noChars=8) {
111  assert(noChars<=8);
112  char x[8];
113  memset(x, 0, 8);
114  x[0] = mark;
115  memcpy(writeHere(), x, 1);
117  cout << "stored mark " << mark
118  << ", _putOffset " << _putOffset << endl;
119  }
120 
121  _putOffset += noChars;
122  }
123  inline void add_string(const string& s) {
124  kXR_int16 sLen = s.size();
125  if ( 0 == sLen ) {
126  cerr << "Error in add_string, size 0" << endl;
127  return;
128  }
129  memcpy(writeHere(), s.c_str(), sLen);
131  cout << "stored string " << s
132  << ", _putOffset " << _putOffset << endl;
133  }
134  _putOffset += sLen;
135  }
136 
137 private:
139  kXR_int32 _putOffset; // tracks where to write inside packet
141 
143 
144  // statistics
150 };
151 
152 #endif /* XRDMONSNDCODER_HH */