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