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
00026 bufPtr = buf_ + sizeof(Header);
00027
00028
00029
00030 assert(((uint32) (bufPtr - buf_)) <= bufSize_);
00031
00032
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
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
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
00057
00058
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
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
00089 bufPtr = buf_ + sizeof(Header);
00090
00091
00092 len = convert32(bufPtr);
00093 bufPtr += sizeof(uint32);
00094 if (len <= 256)
00095 {
00096 consumerName_.append((char *) bufPtr, len);
00097 }
00098 bufPtr += len;
00099
00100
00101 len = convert32(bufPtr);
00102 bufPtr += sizeof(uint32);
00103 if (len <= 64)
00104 {
00105 consumerPriority_.append((char *) bufPtr, len);
00106 }
00107 bufPtr += len;
00108
00109
00110
00111 if (bufPtr < (buf_ + this->size()))
00112 {
00113 len = convert32(bufPtr);
00114 bufPtr += sizeof(uint32);
00115
00116
00117 if (len <= 65000)
00118 {
00119 requestParameterSet_.append((char *) bufPtr, len);
00120 }
00121 bufPtr += len;
00122 }
00123 }
00124
00128 ConsRegResponseBuilder::ConsRegResponseBuilder(void* buf, uint32 bufSize,
00129 uint32 status,
00130 uint32 consumerId):
00131 buf_((uint8*)buf),bufSize_(bufSize)
00132 {
00133 uint8* bufPtr;
00134
00135
00136 bufPtr = buf_ + sizeof(Header);
00137 assert(((uint32) (bufPtr - buf_)) <= bufSize_);
00138
00139
00140 assert(((uint32) (bufPtr + sizeof(uint32) - buf_)) <= bufSize_);
00141 convert (status, bufPtr);
00142 bufPtr += sizeof(uint32);
00143
00144
00145 assert(((uint32) (bufPtr + sizeof(uint32) - buf_)) <= bufSize_);
00146 convert (consumerId, bufPtr);
00147 bufPtr += sizeof(uint32);
00148
00149
00150 new (buf_) Header(Header::CONS_REG_RESPONSE, (bufPtr - buf_));
00151 }
00152
00156 uint32 ConsRegResponseBuilder::size() const
00157 {
00158 HeaderView hview(buf_);
00159 return hview.size();
00160 }
00161
00166 void ConsRegResponseBuilder::
00167 setStreamSelectionTable(std::map<std::string, Strings> const& selTable)
00168 {
00169
00170 uint8* bufPtr = buf_ + size();
00171
00172
00173 convert (static_cast<uint32>(selTable.size()), bufPtr);
00174 bufPtr += sizeof(uint32);
00175 assert(((uint32) (bufPtr - buf_)) <= bufSize_);
00176
00177
00178 std::map<std::string, Strings>::const_iterator mapIter;
00179 for (mapIter = selTable.begin(); mapIter != selTable.end(); mapIter++)
00180 {
00181
00182 Strings workList = mapIter->second;
00183 workList.push_back(mapIter->first);
00184
00185
00186 bufPtr = MsgTools::fillNames(workList, bufPtr);
00187 assert(((uint32) (bufPtr - buf_)) <= bufSize_);
00188 }
00189
00190
00191 new (buf_) Header(Header::CONS_REG_RESPONSE, (bufPtr - buf_));
00192 }
00193
00197 ConsRegResponseView::ConsRegResponseView(void* buf):
00198 buf_((uint8*)buf),head_(buf)
00199 {
00200 uint8* bufPtr;
00201
00202
00203 if (this->code() != Header::CONS_REG_RESPONSE)
00204 {
00205 throw cms::Exception("MessageDecoding","ConsRegResponseView")
00206 << "Invalid consumer registration response message code ("
00207 << this->code() << "). Should be " << Header::CONS_REG_RESPONSE << "\n";
00208 }
00209
00210
00211 bufPtr = buf_ + sizeof(Header);
00212
00213
00214 status_ = convert32(bufPtr);
00215 bufPtr += sizeof(uint32);
00216
00217
00218 consumerId_ = convert32(bufPtr);
00219 bufPtr += sizeof(uint32);
00220 }
00221
00226 std::map<std::string, Strings> ConsRegResponseView::getStreamSelectionTable()
00227 {
00228 std::map<std::string, Strings> selTable;
00229
00230
00231 if (size() >= (3 * sizeof(uint32)))
00232 {
00233
00234 uint8* bufPtr = buf_ + sizeof(Header);
00235 bufPtr += (2 * sizeof(uint32));
00236
00237
00238 uint32 streamCount = convert32(bufPtr);
00239 bufPtr += sizeof(uint32);
00240
00241
00242 for (uint32 idx = 0; idx < streamCount; idx++)
00243 {
00244
00245 Strings workList;
00246
00247 bufPtr += sizeof(uint32);
00248 uint32 listLen = convert32(bufPtr);
00249 bufPtr += sizeof(uint32);
00250 MsgTools::getNames(bufPtr, listLen, workList);
00251
00252
00253 std::string streamLabel = workList.back();
00254 workList.pop_back();
00255 selTable[streamLabel] = workList;
00256
00257
00258 bufPtr += listLen;
00259 }
00260 }
00261
00262 return selTable;
00263 }