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 >= 0)
00095 {
00096 if (len <= 256)
00097 {
00098 consumerName_.append((char *) bufPtr, len);
00099 }
00100 bufPtr += len;
00101 }
00102
00103
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
00116
00117 if (bufPtr < (buf_ + this->size()))
00118 {
00119 len = convert32(bufPtr);
00120 bufPtr += sizeof(uint32);
00121 if (len >= 0)
00122 {
00123
00124
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
00145 bufPtr = buf_ + sizeof(Header);
00146 assert(((uint32) (bufPtr - buf_)) <= bufSize_);
00147
00148
00149 assert(((uint32) (bufPtr + sizeof(uint32) - buf_)) <= bufSize_);
00150 convert (status, bufPtr);
00151 bufPtr += sizeof(uint32);
00152
00153
00154 assert(((uint32) (bufPtr + sizeof(uint32) - buf_)) <= bufSize_);
00155 convert (consumerId, bufPtr);
00156 bufPtr += sizeof(uint32);
00157
00158
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
00179 uint8* bufPtr = buf_ + size();
00180
00181
00182 convert (static_cast<uint32>(selTable.size()), bufPtr);
00183 bufPtr += sizeof(uint32);
00184 assert(((uint32) (bufPtr - buf_)) <= bufSize_);
00185
00186
00187 std::map<std::string, Strings>::const_iterator mapIter;
00188 for (mapIter = selTable.begin(); mapIter != selTable.end(); mapIter++)
00189 {
00190
00191 Strings workList = mapIter->second;
00192 workList.push_back(mapIter->first);
00193
00194
00195 bufPtr = MsgTools::fillNames(workList, bufPtr);
00196 assert(((uint32) (bufPtr - buf_)) <= bufSize_);
00197 }
00198
00199
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
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
00220 bufPtr = buf_ + sizeof(Header);
00221
00222
00223 status_ = convert32(bufPtr);
00224 bufPtr += sizeof(uint32);
00225
00226
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
00240 if (size() >= (3 * sizeof(uint32)))
00241 {
00242
00243 uint8* bufPtr = buf_ + sizeof(Header);
00244 bufPtr += (2 * sizeof(uint32));
00245
00246
00247 uint32 streamCount = convert32(bufPtr);
00248 bufPtr += sizeof(uint32);
00249
00250
00251 for (uint32 idx = 0; idx < streamCount; idx++)
00252 {
00253
00254 Strings workList;
00255
00256 bufPtr += sizeof(uint32);
00257 uint32 listLen = convert32(bufPtr);
00258 bufPtr += sizeof(uint32);
00259 MsgTools::getNames(bufPtr, listLen, workList);
00260
00261
00262 std::string streamLabel = workList.back();
00263 workList.pop_back();
00264 selTable[streamLabel] = workList;
00265
00266
00267 bufPtr += listLen;
00268 }
00269 }
00270
00271 return selTable;
00272 }