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 
17  std::string const& consumerName,
18  std::string const& consumerPriority,
19  std::string const& requestParamSet):
20  buf_((uint8*)buf),bufSize_(bufSize)
21 {
22  uint8* bufPtr;
23  uint32 len;
24 
25  // update the buffer pointer to just beyond the header
26  bufPtr = buf_ + sizeof(Header);
27  //std::cout << "bufPtr = 0x" << hex << ((uint32) bufPtr) << dec << std::endl;
28  //std::cout << "buf_ = 0x" << hex << ((uint32) buf_) << dec << std::endl;
29  //std::cout << "bufSize_ = " << bufSize_ << std::endl;
30  assert(((uint32) (bufPtr - buf_)) <= bufSize_);
31 
32  // copy the consumer name into the message
33  len = consumerName.length();
34  assert(((uint32) (bufPtr + len + sizeof(uint32) - buf_)) <= bufSize_);
35  convert(len, bufPtr);
36  bufPtr += sizeof(uint32);
37  consumerName.copy((char *) bufPtr, len);
38  bufPtr += len;
39 
40  // copy the consumer priority into the message
41  len = consumerPriority.length();
42  assert(((uint32) (bufPtr + len + sizeof(uint32) - buf_)) <= bufSize_);
43  convert(len, bufPtr);
44  bufPtr += sizeof(uint32);
45  consumerPriority.copy((char *) bufPtr, len);
46  bufPtr += len;
47 
48  // copy the request parameter set into the message
49  len = requestParamSet.length();
50  assert(((uint32) (bufPtr + len + sizeof(uint32) - buf_)) <= bufSize_);
51  convert(len, bufPtr);
52  bufPtr += sizeof(uint32);
53  requestParamSet.copy((char *) bufPtr, len);
54  bufPtr += len;
55 
56  // create the message header now that we now the full size
57  //std::cout << "bufPtr = 0x" << hex << ((uint32) bufPtr) << dec << std::endl;
58  //std::cout << "buf_ = 0x" << hex << ((uint32) buf_) << dec << std::endl;
59  new (buf_) Header(Header::CONS_REG_REQUEST, (bufPtr - buf_));
60 }
61 
66 {
67  HeaderView hview(buf_);
68  return hview.size();
69 }
70 
75  buf_((uint8*)buf),head_(buf)
76 {
77  uint8* bufPtr;
78  uint32 len;
79 
80  // verify that the buffer actually contains a registration request
81  if (this->code() != Header::CONS_REG_REQUEST)
82  {
83  throw cms::Exception("MessageDecoding","ConsRegRequestView")
84  << "Invalid consumer registration request message code ("
85  << this->code() << "). Should be " << Header::CONS_REG_REQUEST << "\n";
86  }
87 
88  // update the buffer pointer to just beyond the header
89  bufPtr = buf_ + sizeof(Header);
90 
91  // determine the consumer name
92  len = convert32(bufPtr);
93  bufPtr += sizeof(uint32);
94  if (len <= 256) // len >= 0, since len is unsigned
95  {
96  consumerName_.append((char *) bufPtr, len);
97  }
98  bufPtr += len;
99 
100  // determine the consumer priority
101  len = convert32(bufPtr);
102  bufPtr += sizeof(uint32);
103  if (len <= 64) // len >= 0, since len is unsigned
104  {
105  consumerPriority_.append((char *) bufPtr, len);
106  }
107  bufPtr += len;
108 
109  // determine the request parameter set (maintain backward compatibility
110  // with sources of registration requests that don't have the param set)
111  if (bufPtr < (buf_ + this->size()))
112  {
113  len = convert32(bufPtr);
114  bufPtr += sizeof(uint32);
115  // what is a reasonable limit? This is just to prevent
116  // a bogus, really large value from being used...
117  if (len <= 65000) // len >= 0, since len is unsigned
118  {
119  requestParameterSet_.append((char *) bufPtr, len);
120  }
121  bufPtr += len;
122  }
123 }
124 
129  uint32 status,
130  uint32 consumerId):
131  buf_((uint8*)buf),bufSize_(bufSize)
132 {
133  uint8* bufPtr;
134 
135  // update the buffer pointer to just beyond the header
136  bufPtr = buf_ + sizeof(Header);
137  assert(((uint32) (bufPtr - buf_)) <= bufSize_);
138 
139  // encode the status
140  assert(((uint32) (bufPtr + sizeof(uint32) - buf_)) <= bufSize_);
141  convert (status, bufPtr);
142  bufPtr += sizeof(uint32);
143 
144  // encode the consumer ID
145  assert(((uint32) (bufPtr + sizeof(uint32) - buf_)) <= bufSize_);
146  convert (consumerId, bufPtr);
147  bufPtr += sizeof(uint32);
148 
149  // create the message header now that we now the full size
150  new (buf_) Header(Header::CONS_REG_RESPONSE, (bufPtr - buf_));
151 }
152 
157 {
158  HeaderView hview(buf_);
159  return hview.size();
160 }
161 
167 setStreamSelectionTable(std::map<std::string, Strings> const& selTable)
168 {
169  // add the table just beyond the existing data
170  uint8* bufPtr = buf_ + size();
171 
172  // add the number of entries in the table to the message
173  convert (static_cast<uint32>(selTable.size()), bufPtr);
174  bufPtr += sizeof(uint32);
175  assert(((uint32) (bufPtr - buf_)) <= bufSize_);
176 
177  // add each entry in the table to the message
178  std::map<std::string, Strings>::const_iterator mapIter;
179  for (mapIter = selTable.begin(); mapIter != selTable.end(); mapIter++)
180  {
181  // create a new string list with the map key as the last entry
182  Strings workList = mapIter->second;
183  workList.push_back(mapIter->first);
184 
185  // copy the string list into the message
186  bufPtr = MsgTools::fillNames(workList, bufPtr);
187  assert(((uint32) (bufPtr - buf_)) <= bufSize_);
188  }
189 
190  // update the message header with the new full size
191  new (buf_) Header(Header::CONS_REG_RESPONSE, (bufPtr - buf_));
192 }
193 
198  buf_((uint8*)buf),head_(buf)
199 {
200  uint8* bufPtr;
201 
202  // verify that the buffer actually contains a registration response
203  if (this->code() != Header::CONS_REG_RESPONSE)
204  {
205  throw cms::Exception("MessageDecoding","ConsRegResponseView")
206  << "Invalid consumer registration response message code ("
207  << this->code() << "). Should be " << Header::CONS_REG_RESPONSE << "\n";
208  }
209 
210  // update the buffer pointer to just beyond the header
211  bufPtr = buf_ + sizeof(Header);
212 
213  // decode the status
214  status_ = convert32(bufPtr);
215  bufPtr += sizeof(uint32);
216 
217  // decode the consumer ID
218  consumerId_ = convert32(bufPtr);
219  bufPtr += sizeof(uint32);
220 }
221 
226 std::map<std::string, Strings> ConsRegResponseView::getStreamSelectionTable()
227 {
228  std::map<std::string, Strings> selTable;
229 
230  // check if there is more than just the status code and consumer id
231  if (size() >= (3 * sizeof(uint32)))
232  {
233  // initialize the data pointer to the start of the map data
234  uint8* bufPtr = buf_ + sizeof(Header);
235  bufPtr += (2 * sizeof(uint32));
236 
237  // decode the number of streams in the table
238  uint32 streamCount = convert32(bufPtr);
239  bufPtr += sizeof(uint32);
240 
241  // loop over each stream
242  for (uint32 idx = 0; idx < streamCount; idx++)
243  {
244  // decode the vector of strings for the stream
245  Strings workList;
246  //uint32 listCount = convert32(bufPtr);
247  bufPtr += sizeof(uint32);
248  uint32 listLen = convert32(bufPtr);
249  bufPtr += sizeof(uint32);
250  MsgTools::getNames(bufPtr, listLen, workList);
251 
252  // pull the map key off the end of the list
253  std::string streamLabel = workList.back();
254  workList.pop_back();
255  selTable[streamLabel] = workList;
256 
257  // move on to the next entry in the message
258  bufPtr += listLen;
259  }
260  }
261 
262  return selTable;
263 }
std::string consumerPriority_
std::vector< std::string > Strings
Definition: MsgTools.h:18
boost::shared_array< char > buf_
ConsRegResponseView(void *buf)
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)
uint32 code() const
unsigned int uint32
Definition: MsgTools.h:13
ConsRegRequestBuilder(void *buf, uint32 bufSize, std::string const &consumerName, std::string const &consumerPriority, std::string const &requestParameterSet)
uint32 size() const
Definition: MsgHeader.h:35
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