CMS 3D CMS Logo

ConsRegMessage.cc

Go to the documentation of this file.
00001 
00009 #include "IOPool/Streamer/interface/ConsRegMessage.h"
00010 #include "FWCore/Utilities/interface/Exception.h"
00011 #include <cassert>
00012 
00016 ConsRegRequestBuilder::ConsRegRequestBuilder(void* buf, uint32 bufSize,
00017                                              std::string const& consumerName,
00018                                              std::string const& consumerPriority,
00019                                              std::string const& requestParamSet):
00020   buf_((uint8*)buf),bufSize_(bufSize)
00021 {
00022   uint8* bufPtr;
00023   uint32 len;
00024 
00025   // update the buffer pointer to just beyond the header
00026   bufPtr = buf_ + sizeof(Header);
00027   //std::cout << "bufPtr = 0x" << hex << ((uint32) bufPtr) << dec << std::endl;
00028   //std::cout << "buf_ = 0x" << hex << ((uint32) buf_) << dec << std::endl;
00029   //std::cout << "bufSize_ = " << bufSize_ << std::endl;
00030   assert(((uint32) (bufPtr - buf_)) <= bufSize_);
00031 
00032   // copy the consumer name into the message
00033   len = consumerName.length();
00034   assert(((uint32) (bufPtr + len + sizeof(uint32) - buf_)) <= bufSize_);
00035   convert(len, bufPtr);
00036   bufPtr += sizeof(uint32);
00037   consumerName.copy((char *) bufPtr, len);
00038   bufPtr += len;
00039 
00040   // copy the consumer priority into the message
00041   len = consumerPriority.length();
00042   assert(((uint32) (bufPtr + len + sizeof(uint32) - buf_)) <= bufSize_);
00043   convert(len, bufPtr);
00044   bufPtr += sizeof(uint32);
00045   consumerPriority.copy((char *) bufPtr, len);
00046   bufPtr += len;
00047 
00048   // copy the request parameter set into the message
00049   len = requestParamSet.length();
00050   assert(((uint32) (bufPtr + len + sizeof(uint32) - buf_)) <= bufSize_);
00051   convert(len, bufPtr);
00052   bufPtr += sizeof(uint32);
00053   requestParamSet.copy((char *) bufPtr, len);
00054   bufPtr += len;
00055 
00056   // create the message header now that we now the full size
00057   //std::cout << "bufPtr = 0x" << hex << ((uint32) bufPtr) << dec << std::endl;
00058   //std::cout << "buf_ = 0x" << hex << ((uint32) buf_) << dec << std::endl;
00059   new (buf_) Header(Header::CONS_REG_REQUEST, (bufPtr - buf_));
00060 }
00061 
00065 uint32 ConsRegRequestBuilder::size() const
00066 {
00067   HeaderView hview(buf_);
00068   return hview.size();
00069 }
00070 
00074 ConsRegRequestView::ConsRegRequestView(void* buf):
00075   buf_((uint8*)buf),head_(buf)
00076 {
00077   uint8* bufPtr;
00078   uint32 len;
00079 
00080   // verify that the buffer actually contains a registration request
00081   if (this->code() != Header::CONS_REG_REQUEST)
00082     {
00083       throw cms::Exception("MessageDecoding","ConsRegRequestView")
00084         << "Invalid consumer registration request message code ("
00085         << this->code() << "). Should be " << Header::CONS_REG_REQUEST << "\n";
00086     }
00087 
00088   // update the buffer pointer to just beyond the header
00089   bufPtr = buf_ + sizeof(Header);
00090 
00091   // determine the consumer name
00092   len = convert32(bufPtr);
00093   bufPtr += sizeof(uint32);
00094   if (len >= 0)
00095     {
00096       if (len <= 256)
00097         {
00098           consumerName_.append((char *) bufPtr, len);
00099         }
00100       bufPtr += len;
00101     }
00102 
00103   // determine the consumer priority
00104   len = convert32(bufPtr);
00105   bufPtr += sizeof(uint32);
00106   if (len >= 0)
00107     {
00108       if (len <= 64)
00109         {
00110           consumerPriority_.append((char *) bufPtr, len);
00111         }
00112       bufPtr += len;
00113     }
00114 
00115   // determine the request parameter set (maintain backward compatibility
00116   // with sources of registration requests that don't have the param set)
00117   if (bufPtr < (buf_ + this->size()))
00118     {
00119       len = convert32(bufPtr);
00120       bufPtr += sizeof(uint32);
00121       if (len >= 0)
00122         {
00123           // what is a reasonable limit?  This is just to prevent
00124           // a bogus, really large value from being used...
00125           if (len <= 65000)
00126             {
00127               requestParameterSet_.append((char *) bufPtr, len);
00128             }
00129           bufPtr += len;
00130         }
00131     }
00132 }
00133 
00137 ConsRegResponseBuilder::ConsRegResponseBuilder(void* buf, uint32 bufSize,
00138                                                uint32 status,
00139                                                uint32 consumerId):
00140   buf_((uint8*)buf),bufSize_(bufSize)
00141 {
00142   uint8* bufPtr;
00143 
00144   // update the buffer pointer to just beyond the header
00145   bufPtr = buf_ + sizeof(Header);
00146   assert(((uint32) (bufPtr - buf_)) <= bufSize_);
00147 
00148   // encode the status
00149   assert(((uint32) (bufPtr + sizeof(uint32) - buf_)) <= bufSize_);
00150   convert (status, bufPtr);
00151   bufPtr += sizeof(uint32);
00152 
00153   // encode the consumer ID
00154   assert(((uint32) (bufPtr + sizeof(uint32) - buf_)) <= bufSize_);
00155   convert (consumerId, bufPtr);
00156   bufPtr += sizeof(uint32);
00157 
00158   // create the message header now that we now the full size
00159   new (buf_) Header(Header::CONS_REG_RESPONSE, (bufPtr - buf_));
00160 }
00161 
00165 uint32 ConsRegResponseBuilder::size() const
00166 {
00167   HeaderView hview(buf_);
00168   return hview.size();
00169 }
00170 
00175 void ConsRegResponseBuilder::
00176 setStreamSelectionTable(std::map<std::string, Strings> const& selTable)
00177 {
00178   // add the table just beyond the existing data
00179   uint8* bufPtr = buf_ + size();
00180 
00181   // add the number of entries in the table to the message
00182   convert (static_cast<uint32>(selTable.size()), bufPtr);
00183   bufPtr += sizeof(uint32);
00184   assert(((uint32) (bufPtr - buf_)) <= bufSize_);
00185 
00186   // add each entry in the table to the message
00187   std::map<std::string, Strings>::const_iterator mapIter;
00188   for (mapIter = selTable.begin(); mapIter != selTable.end(); mapIter++)
00189     {
00190       // create a new string list with the map key as the last entry
00191       Strings workList = mapIter->second;
00192       workList.push_back(mapIter->first);
00193 
00194       // copy the string list into the message
00195       bufPtr = MsgTools::fillNames(workList, bufPtr);
00196       assert(((uint32) (bufPtr - buf_)) <= bufSize_);
00197     }
00198 
00199   // update the message header with the new full size
00200   new (buf_) Header(Header::CONS_REG_RESPONSE, (bufPtr - buf_));
00201 }
00202 
00206 ConsRegResponseView::ConsRegResponseView(void* buf):
00207   buf_((uint8*)buf),head_(buf)
00208 {
00209   uint8* bufPtr;
00210 
00211   // verify that the buffer actually contains a registration response
00212   if (this->code() != Header::CONS_REG_RESPONSE)
00213     {
00214       throw cms::Exception("MessageDecoding","ConsRegResponseView")
00215         << "Invalid consumer registration response message code ("
00216         << this->code() << "). Should be " << Header::CONS_REG_RESPONSE << "\n";
00217     }
00218 
00219   // update the buffer pointer to just beyond the header
00220   bufPtr = buf_ + sizeof(Header);
00221 
00222   // decode the status
00223   status_ = convert32(bufPtr);
00224   bufPtr += sizeof(uint32);
00225 
00226   // decode the consumer ID
00227   consumerId_ = convert32(bufPtr);
00228   bufPtr += sizeof(uint32);
00229 }
00230 
00235 std::map<std::string, Strings> ConsRegResponseView::getStreamSelectionTable()
00236 {
00237   std::map<std::string, Strings> selTable;
00238 
00239   // check if there is more than just the status code and consumer id
00240   if (size() >= (3 * sizeof(uint32)))
00241     {
00242       // initialize the data pointer to the start of the map data
00243       uint8* bufPtr = buf_ + sizeof(Header);
00244       bufPtr += (2 * sizeof(uint32));
00245 
00246       // decode the number of streams in the table
00247       uint32 streamCount = convert32(bufPtr);
00248       bufPtr += sizeof(uint32);
00249 
00250       // loop over each stream
00251       for (uint32 idx = 0; idx < streamCount; idx++)
00252         {
00253           // decode the vector of strings for the stream
00254           Strings workList;
00255           //uint32 listCount = convert32(bufPtr);
00256           bufPtr += sizeof(uint32);
00257           uint32 listLen = convert32(bufPtr);
00258           bufPtr += sizeof(uint32);
00259           MsgTools::getNames(bufPtr, listLen, workList);
00260 
00261           // pull the map key off the end of the list 
00262           std::string streamLabel = workList.back();
00263           workList.pop_back();
00264           selTable[streamLabel] = workList;
00265 
00266           // move on to the next entry in the message
00267           bufPtr += listLen;
00268         }
00269     }
00270 
00271   return selTable;
00272 }

Generated on Tue Jun 9 17:39:18 2009 for CMSSW by  doxygen 1.5.4