CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ConsRegMessage.cc
Go to the documentation of this file.
1 
11 #include <cassert>
12 
18  std::string const& requestParamSet):
19  buf_((uint8*)buf),bufSize_(bufSize)
20 {
21  // update the buffer pointer to just beyond the header
22  uint8* bufPtr = buf_ + sizeof(Header);
23  //std::cout << "bufPtr = 0x" << hex << ((uint32) bufPtr) << dec << std::endl;
24  //std::cout << "buf_ = 0x" << hex << ((uint32) buf_) << dec << std::endl;
25  //std::cout << "bufSize_ = " << bufSize_ << std::endl;
26  assert(((uint32) (bufPtr - buf_)) <= bufSize_);
27 
28  // copy the consumer name into the message
29  uint32 len = consumerName.length();
30  assert(((uint32) (bufPtr + len + sizeof(uint32) - buf_)) <= bufSize_);
31  convert(len, bufPtr);
32  bufPtr += sizeof(uint32);
33  consumerName.copy((char *) bufPtr, len);
34  bufPtr += len;
35 
36  // copy the request parameter set into the message
37  len = requestParamSet.length();
38  assert(((uint32) (bufPtr + len + sizeof(uint32) - buf_)) <= bufSize_);
39  convert(len, bufPtr);
40  bufPtr += sizeof(uint32);
41  requestParamSet.copy((char *) bufPtr, len);
42  bufPtr += len;
43 
44  // create the message header now that we now the full size
45  //std::cout << "bufPtr = 0x" << hex << ((uint32) bufPtr) << dec << std::endl;
46  //std::cout << "buf_ = 0x" << hex << ((uint32) buf_) << dec << std::endl;
47  new (buf_) Header(Header::CONS_REG_REQUEST, (bufPtr - buf_));
48 }
49 
54 {
55  HeaderView hview(buf_);
56  return hview.size();
57 }
58 
63  buf_((uint8*)buf),head_(buf)
64 {
65  // verify that the buffer actually contains a registration request
66  if (this->code() != Header::CONS_REG_REQUEST)
67  {
68  throw cms::Exception("MessageDecoding","ConsRegRequestView")
69  << "Invalid consumer registration request message code ("
70  << this->code() << "). Should be " << Header::CONS_REG_REQUEST << "\n";
71  }
72 
73  // update the buffer pointer to just beyond the header
74  uint8* bufPtr = buf_ + sizeof(Header);
75 
76  // determine the consumer name
77  uint32 len = convert32(bufPtr);
78  bufPtr += sizeof(uint32);
79  if (len <= 256) // len >= 0, since len is unsigned
80  {
81  consumerName_.append((char *) bufPtr, len);
82  }
83  bufPtr += len;
84 
85  // determine the request parameter set (maintain backward compatibility
86  // with sources of registration requests that don't have the param set)
87  if (bufPtr < (buf_ + this->size()))
88  {
89  len = convert32(bufPtr);
90  bufPtr += sizeof(uint32);
91  // what is a reasonable limit? This is just to prevent
92  // a bogus, really large value from being used...
93  if (len <= 65000) // len >= 0, since len is unsigned
94  {
95  requestParameterSet_.append((char *) bufPtr, len);
96  }
97  bufPtr += len;
98  assert(bufPtr); // silence clang static analyzer
99  }
100 }
101 
106  uint32 status,
107  uint32 consumerId):
108  buf_((uint8*)buf),bufSize_(bufSize)
109 {
110  // update the buffer pointer to just beyond the header
111  uint8* bufPtr = buf_ + sizeof(Header);
112  assert(((uint32) (bufPtr - buf_)) <= bufSize_);
113 
114  // encode the status
115  assert(((uint32) (bufPtr + sizeof(uint32) - buf_)) <= bufSize_);
116  convert (status, bufPtr);
117  bufPtr += sizeof(uint32);
118 
119  // encode the consumer ID
120  assert(((uint32) (bufPtr + sizeof(uint32) - buf_)) <= bufSize_);
121  convert (consumerId, bufPtr);
122  bufPtr += sizeof(uint32);
123 
124  // create the message header now that we now the full size
125  new (buf_) Header(Header::CONS_REG_RESPONSE, (bufPtr - buf_));
126 }
127 
132 {
133  HeaderView hview(buf_);
134  return hview.size();
135 }
136 
142 setStreamSelectionTable(std::map<std::string, Strings> const& selTable)
143 {
144  // add the table just beyond the existing data
145  uint8* bufPtr = buf_ + size();
146 
147  // add the number of entries in the table to the message
148  convert (static_cast<uint32>(selTable.size()), bufPtr);
149  bufPtr += sizeof(uint32);
150  assert(((uint32) (bufPtr - buf_)) <= bufSize_);
151 
152  // add each entry in the table to the message
153  std::map<std::string, Strings>::const_iterator mapIter;
154  for (mapIter = selTable.begin(); mapIter != selTable.end(); mapIter++)
155  {
156  // create a new string list with the map key as the last entry
157  Strings workList = mapIter->second;
158  workList.push_back(mapIter->first);
159 
160  // copy the string list into the message
161  bufPtr = MsgTools::fillNames(workList, bufPtr);
162  assert(((uint32) (bufPtr - buf_)) <= bufSize_);
163  }
164 
165  // update the message header with the new full size
166  new (buf_) Header(Header::CONS_REG_RESPONSE, (bufPtr - buf_));
167 }
168 
173  buf_((uint8*)buf),head_(buf)
174 {
175  // verify that the buffer actually contains a registration response
176  if (this->code() != Header::CONS_REG_RESPONSE)
177  {
178  throw cms::Exception("MessageDecoding","ConsRegResponseView")
179  << "Invalid consumer registration response message code ("
180  << this->code() << "). Should be " << Header::CONS_REG_RESPONSE << "\n";
181  }
182 
183  // update the buffer pointer to just beyond the header
184  uint8* bufPtr = buf_ + sizeof(Header);
185 
186  // decode the status
187  status_ = convert32(bufPtr);
188  bufPtr += sizeof(uint32);
189 
190  // decode the consumer ID
191  consumerId_ = convert32(bufPtr);
192  bufPtr += sizeof(uint32);
193 
194  assert(bufPtr); // silence clang static analyzer
195 }
196 
201 std::map<std::string, Strings> ConsRegResponseView::getStreamSelectionTable()
202 {
203  std::map<std::string, Strings> selTable;
204 
205  // check if there is more than just the status code and consumer id
206  if (size() >= (3 * sizeof(uint32)))
207  {
208  // initialize the data pointer to the start of the map data
209  uint8* bufPtr = buf_ + sizeof(Header);
210  bufPtr += (2 * sizeof(uint32));
211 
212  // decode the number of streams in the table
213  uint32 streamCount = convert32(bufPtr);
214  bufPtr += sizeof(uint32);
215 
216  // loop over each stream
217  for (uint32 idx = 0; idx < streamCount; idx++)
218  {
219  // decode the vector of strings for the stream
220  Strings workList;
221  //uint32 listCount = convert32(bufPtr);
222  bufPtr += sizeof(uint32);
223  uint32 listLen = convert32(bufPtr);
224  bufPtr += sizeof(uint32);
225  MsgTools::getNames(bufPtr, listLen, workList);
226 
227  // pull the map key off the end of the list
228  std::string streamLabel = workList.back();
229  workList.pop_back();
230  selTable[streamLabel] = workList;
231 
232  // move on to the next entry in the message
233  bufPtr += listLen;
234  }
235  }
236 
237  return selTable;
238 }
std::vector< std::string > Strings
Definition: MsgTools.h:18
ConsRegResponseView(void *buf)
static int const bufSize
Definition: Guid.cc:24
void convert(uint32 i, char_uint32 v)
Definition: MsgTools.h:46
ConsRegResponseBuilder(void *buf, uint32 bufSize, uint32 status, uint32 consumerId)
uint32 size() const
std::string requestParameterSet_
ConsRegRequestView(void *buf)
ConsRegRequestBuilder(void *buf, uint32 bufSize, std::string const &consumerName, std::string const &requestParameterSet)
uint32 code() const
unsigned int uint32
Definition: MsgTools.h:13
uint32 size() const
Definition: MsgHeader.h:35
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
uint32 convert32(char_uint32 v)
Definition: MsgTools.h:30
unsigned char uint8
Definition: MsgTools.h:11
uint8 * fillNames(const Strings &names, uint8 *pos)
Definition: MsgTools.h:75
std::map< std::string, Strings > getStreamSelectionTable()
void setStreamSelectionTable(std::map< std::string, Strings > const &selTable)
uint32 code() const
void getNames(uint8 *from, uint32 from_len, Strings &to)
Definition: MsgTools.h:91
tuple status
Definition: ntuplemaker.py:245
uint32 size() const
std::string consumerName_
uint32 size() const