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& requestParamSet):
00019 buf_((uint8*)buf),bufSize_(bufSize)
00020 {
00021 uint8* bufPtr;
00022 uint32 len;
00023
00024
00025 bufPtr = buf_ + sizeof(Header);
00026
00027
00028
00029 assert(((uint32) (bufPtr - buf_)) <= bufSize_);
00030
00031
00032 len = consumerName.length();
00033 assert(((uint32) (bufPtr + len + sizeof(uint32) - buf_)) <= bufSize_);
00034 convert(len, bufPtr);
00035 bufPtr += sizeof(uint32);
00036 consumerName.copy((char *) bufPtr, len);
00037 bufPtr += len;
00038
00039
00040 len = requestParamSet.length();
00041 assert(((uint32) (bufPtr + len + sizeof(uint32) - buf_)) <= bufSize_);
00042 convert(len, bufPtr);
00043 bufPtr += sizeof(uint32);
00044 requestParamSet.copy((char *) bufPtr, len);
00045 bufPtr += len;
00046
00047
00048
00049
00050 new (buf_) Header(Header::CONS_REG_REQUEST, (bufPtr - buf_));
00051 }
00052
00056 uint32 ConsRegRequestBuilder::size() const
00057 {
00058 HeaderView hview(buf_);
00059 return hview.size();
00060 }
00061
00065 ConsRegRequestView::ConsRegRequestView(void* buf):
00066 buf_((uint8*)buf),head_(buf)
00067 {
00068 uint8* bufPtr;
00069 uint32 len;
00070
00071
00072 if (this->code() != Header::CONS_REG_REQUEST)
00073 {
00074 throw cms::Exception("MessageDecoding","ConsRegRequestView")
00075 << "Invalid consumer registration request message code ("
00076 << this->code() << "). Should be " << Header::CONS_REG_REQUEST << "\n";
00077 }
00078
00079
00080 bufPtr = buf_ + sizeof(Header);
00081
00082
00083 len = convert32(bufPtr);
00084 bufPtr += sizeof(uint32);
00085 if (len <= 256)
00086 {
00087 consumerName_.append((char *) bufPtr, len);
00088 }
00089 bufPtr += len;
00090
00091
00092
00093 if (bufPtr < (buf_ + this->size()))
00094 {
00095 len = convert32(bufPtr);
00096 bufPtr += sizeof(uint32);
00097
00098
00099 if (len <= 65000)
00100 {
00101 requestParameterSet_.append((char *) bufPtr, len);
00102 }
00103 bufPtr += len;
00104 }
00105 }
00106
00110 ConsRegResponseBuilder::ConsRegResponseBuilder(void* buf, uint32 bufSize,
00111 uint32 status,
00112 uint32 consumerId):
00113 buf_((uint8*)buf),bufSize_(bufSize)
00114 {
00115 uint8* bufPtr;
00116
00117
00118 bufPtr = buf_ + sizeof(Header);
00119 assert(((uint32) (bufPtr - buf_)) <= bufSize_);
00120
00121
00122 assert(((uint32) (bufPtr + sizeof(uint32) - buf_)) <= bufSize_);
00123 convert (status, bufPtr);
00124 bufPtr += sizeof(uint32);
00125
00126
00127 assert(((uint32) (bufPtr + sizeof(uint32) - buf_)) <= bufSize_);
00128 convert (consumerId, bufPtr);
00129 bufPtr += sizeof(uint32);
00130
00131
00132 new (buf_) Header(Header::CONS_REG_RESPONSE, (bufPtr - buf_));
00133 }
00134
00138 uint32 ConsRegResponseBuilder::size() const
00139 {
00140 HeaderView hview(buf_);
00141 return hview.size();
00142 }
00143
00148 void ConsRegResponseBuilder::
00149 setStreamSelectionTable(std::map<std::string, Strings> const& selTable)
00150 {
00151
00152 uint8* bufPtr = buf_ + size();
00153
00154
00155 convert (static_cast<uint32>(selTable.size()), bufPtr);
00156 bufPtr += sizeof(uint32);
00157 assert(((uint32) (bufPtr - buf_)) <= bufSize_);
00158
00159
00160 std::map<std::string, Strings>::const_iterator mapIter;
00161 for (mapIter = selTable.begin(); mapIter != selTable.end(); mapIter++)
00162 {
00163
00164 Strings workList = mapIter->second;
00165 workList.push_back(mapIter->first);
00166
00167
00168 bufPtr = MsgTools::fillNames(workList, bufPtr);
00169 assert(((uint32) (bufPtr - buf_)) <= bufSize_);
00170 }
00171
00172
00173 new (buf_) Header(Header::CONS_REG_RESPONSE, (bufPtr - buf_));
00174 }
00175
00179 ConsRegResponseView::ConsRegResponseView(void* buf):
00180 buf_((uint8*)buf),head_(buf)
00181 {
00182 uint8* bufPtr;
00183
00184
00185 if (this->code() != Header::CONS_REG_RESPONSE)
00186 {
00187 throw cms::Exception("MessageDecoding","ConsRegResponseView")
00188 << "Invalid consumer registration response message code ("
00189 << this->code() << "). Should be " << Header::CONS_REG_RESPONSE << "\n";
00190 }
00191
00192
00193 bufPtr = buf_ + sizeof(Header);
00194
00195
00196 status_ = convert32(bufPtr);
00197 bufPtr += sizeof(uint32);
00198
00199
00200 consumerId_ = convert32(bufPtr);
00201 bufPtr += sizeof(uint32);
00202 }
00203
00208 std::map<std::string, Strings> ConsRegResponseView::getStreamSelectionTable()
00209 {
00210 std::map<std::string, Strings> selTable;
00211
00212
00213 if (size() >= (3 * sizeof(uint32)))
00214 {
00215
00216 uint8* bufPtr = buf_ + sizeof(Header);
00217 bufPtr += (2 * sizeof(uint32));
00218
00219
00220 uint32 streamCount = convert32(bufPtr);
00221 bufPtr += sizeof(uint32);
00222
00223
00224 for (uint32 idx = 0; idx < streamCount; idx++)
00225 {
00226
00227 Strings workList;
00228
00229 bufPtr += sizeof(uint32);
00230 uint32 listLen = convert32(bufPtr);
00231 bufPtr += sizeof(uint32);
00232 MsgTools::getNames(bufPtr, listLen, workList);
00233
00234
00235 std::string streamLabel = workList.back();
00236 workList.pop_back();
00237 selTable[streamLabel] = workList;
00238
00239
00240 bufPtr += listLen;
00241 }
00242 }
00243
00244 return selTable;
00245 }