|
|
| 34 |
|
34 |
|
| 35 |
NS_LOG_COMPONENT_DEFINE ("PacketTagList"); |
35 |
NS_LOG_COMPONENT_DEFINE ("PacketTagList"); |
| 36 |
|
36 |
|
|
|
37 |
PacketTagList::TagData::TagData (size_t dataSize) |
| 38 |
: size (dataSize) |
| 39 |
{ |
| 40 |
NS_ASSERT_MSG (dataSize < std::numeric_limits<decltype(size)>::max (), |
| 41 |
"Requested TagData size " << dataSize |
| 42 |
<< " exceeds maximum " |
| 43 |
<< std::numeric_limits<decltype(size)>::max () ); |
| 44 |
data = (uint8_t *) std::malloc (size); |
| 45 |
} |
| 46 |
|
| 47 |
PacketTagList::TagData::~TagData (void) |
| 48 |
{ |
| 49 |
free (data); |
| 50 |
} |
| 51 |
|
| 37 |
bool |
52 |
bool |
| 38 |
PacketTagList::COWTraverse (Tag & tag, PacketTagList::COWWriter Writer) |
53 |
PacketTagList::COWTraverse (Tag & tag, PacketTagList::COWWriter Writer) |
| 39 |
{ |
54 |
{ |
|
|
| 133 |
NS_ASSERT (cur != 0); |
148 |
NS_ASSERT (cur != 0); |
| 134 |
NS_ASSERT (cur->count > 1); |
149 |
NS_ASSERT (cur->count > 1); |
| 135 |
cur->count--; // unmerge cur |
150 |
cur->count--; // unmerge cur |
| 136 |
struct TagData * copy = new struct TagData (); |
151 |
struct TagData * copy = new struct TagData (cur->size); |
| 137 |
copy->tid = cur->tid; |
152 |
copy->tid = cur->tid; |
| 138 |
copy->count = 1; |
153 |
copy->count = 1; |
| 139 |
memcpy (copy->data, cur->data, TagData::MAX_SIZE); |
154 |
memcpy (copy->data, cur->data, copy->size); |
| 140 |
copy->next = cur->next; // merge into tail |
155 |
copy->next = cur->next; // merge into tail |
| 141 |
copy->next->count++; // mark new merge |
156 |
copy->next->count++; // mark new merge |
| 142 |
*prevNext = copy; // point prior list at copy |
157 |
*prevNext = copy; // point prior list at copy |
|
|
| 170 |
|
185 |
|
| 171 |
// found tid |
186 |
// found tid |
| 172 |
bool found = true; |
187 |
bool found = true; |
| 173 |
tag.Deserialize (TagBuffer (cur->data, |
188 |
tag.Deserialize (TagBuffer (cur->data, cur->data + cur->size)); |
| 174 |
cur->data + TagData::MAX_SIZE)); |
|
|
| 175 |
*prevNext = cur->next; // link around cur |
189 |
*prevNext = cur->next; // link around cur |
| 176 |
|
190 |
|
| 177 |
if (preMerge) |
191 |
if (preMerge) |
|
|
| 217 |
if (preMerge) |
231 |
if (preMerge) |
| 218 |
{ |
232 |
{ |
| 219 |
// found tid before first merge, so just rewrite |
233 |
// found tid before first merge, so just rewrite |
| 220 |
tag.Serialize (TagBuffer (cur->data, |
234 |
tag.Serialize (TagBuffer (cur->data, cur->data + cur->size)); |
| 221 |
cur->data + tag.GetSerializedSize ())); |
|
|
| 222 |
} |
235 |
} |
| 223 |
else |
236 |
else |
| 224 |
{ |
237 |
{ |
| 225 |
// cur is always a merge at this point |
238 |
// cur is always a merge at this point |
| 226 |
// need to copy, replace, and link past cur |
239 |
// need to copy, replace, and link past cur |
| 227 |
cur->count--; // unmerge cur |
240 |
cur->count--; // unmerge cur |
| 228 |
struct TagData * copy = new struct TagData (); |
241 |
struct TagData * copy = new struct TagData (tag.GetSerializedSize ()); |
| 229 |
copy->tid = tag.GetInstanceTypeId (); |
242 |
copy->tid = tag.GetInstanceTypeId (); |
| 230 |
copy->count = 1; |
243 |
copy->count = 1; |
| 231 |
tag.Serialize (TagBuffer (copy->data, |
244 |
tag.Serialize (TagBuffer (copy->data, copy->data + copy->size)); |
| 232 |
copy->data + tag.GetSerializedSize ())); |
|
|
| 233 |
copy->next = cur->next; // merge into tail |
245 |
copy->next = cur->next; // merge into tail |
| 234 |
if (copy->next != 0) |
246 |
if (copy->next != 0) |
| 235 |
{ |
247 |
{ |
|
|
| 249 |
{ |
261 |
{ |
| 250 |
NS_ASSERT_MSG (cur->tid != tag.GetInstanceTypeId (), "Error: cannot add the same kind of tag twice."); |
262 |
NS_ASSERT_MSG (cur->tid != tag.GetInstanceTypeId (), "Error: cannot add the same kind of tag twice."); |
| 251 |
} |
263 |
} |
| 252 |
struct TagData * head = new struct TagData (); |
264 |
struct TagData * head = new struct TagData (tag.GetSerializedSize ()); |
| 253 |
head->count = 1; |
265 |
head->count = 1; |
| 254 |
head->next = 0; |
266 |
head->next = 0; |
| 255 |
head->tid = tag.GetInstanceTypeId (); |
267 |
head->tid = tag.GetInstanceTypeId (); |
| 256 |
head->next = m_next; |
268 |
head->next = m_next; |
| 257 |
NS_ASSERT (tag.GetSerializedSize () <= TagData::MAX_SIZE); |
269 |
tag.Serialize (TagBuffer (head->data, head->data + head->size)); |
| 258 |
tag.Serialize (TagBuffer (head->data, head->data + tag.GetSerializedSize ())); |
|
|
| 259 |
|
270 |
|
| 260 |
const_cast<PacketTagList *> (this)->m_next = head; |
271 |
const_cast<PacketTagList *> (this)->m_next = head; |
| 261 |
} |
272 |
} |
|
|
| 270 |
if (cur->tid == tid) |
281 |
if (cur->tid == tid) |
| 271 |
{ |
282 |
{ |
| 272 |
/* found tag */ |
283 |
/* found tag */ |
| 273 |
tag.Deserialize (TagBuffer (cur->data, cur->data + TagData::MAX_SIZE)); |
284 |
tag.Deserialize (TagBuffer (cur->data, cur->data + cur->size)); |
| 274 |
return true; |
285 |
return true; |
| 275 |
} |
286 |
} |
| 276 |
} |
287 |
} |