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