diff options
author | Jacek Antonelli | 2008-08-15 23:44:54 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:54 -0500 |
commit | b2afb8800bb033a04bb3ecdf0363068d56648ef1 (patch) | |
tree | 3568129b5bbddb47cd39d622b4137a8fbff4abaf /linden/indra/llmessage/llbuffer.h | |
parent | Second Life viewer sources 1.14.0.1 (diff) | |
download | meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.zip meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.tar.gz meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.tar.bz2 meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.tar.xz |
Second Life viewer sources 1.15.0.2
Diffstat (limited to 'linden/indra/llmessage/llbuffer.h')
-rw-r--r-- | linden/indra/llmessage/llbuffer.h | 91 |
1 files changed, 84 insertions, 7 deletions
diff --git a/linden/indra/llmessage/llbuffer.h b/linden/indra/llmessage/llbuffer.h index cd76c90..badbc9f 100644 --- a/linden/indra/llmessage/llbuffer.h +++ b/linden/indra/llmessage/llbuffer.h | |||
@@ -6,6 +6,7 @@ | |||
6 | * | 6 | * |
7 | * Copyright (c) 2005-2007, Linden Research, Inc. | 7 | * Copyright (c) 2005-2007, Linden Research, Inc. |
8 | * | 8 | * |
9 | * Second Life Viewer Source Code | ||
9 | * The source code in this file ("Source Code") is provided by Linden Lab | 10 | * The source code in this file ("Source Code") is provided by Linden Lab |
10 | * to you under the terms of the GNU General Public License, version 2.0 | 11 | * to you under the terms of the GNU General Public License, version 2.0 |
11 | * ("GPL"), unless you have obtained a separate licensing agreement | 12 | * ("GPL"), unless you have obtained a separate licensing agreement |
@@ -32,7 +33,7 @@ | |||
32 | 33 | ||
33 | /** | 34 | /** |
34 | * Declaration of classes used for minimizing calls to new[], | 35 | * Declaration of classes used for minimizing calls to new[], |
35 | * memcpy(), and delete[]. Typically, you would create an LLHeapArray, | 36 | * memcpy(), and delete[]. Typically, you would create an LLBufferArray, |
36 | * feed it data, modify and add segments as you process it, and feed | 37 | * feed it data, modify and add segments as you process it, and feed |
37 | * it to a sink. | 38 | * it to a sink. |
38 | */ | 39 | */ |
@@ -108,6 +109,16 @@ public: | |||
108 | */ | 109 | */ |
109 | S32 size() const; | 110 | S32 size() const; |
110 | 111 | ||
112 | /** | ||
113 | * @brief Check if two segments are the same. | ||
114 | * | ||
115 | * Two segments are considered equal if they are on the same | ||
116 | * channel and cover the exact same address range. | ||
117 | * @param rhs the segment to compare with this segment. | ||
118 | * @return Returns true if they are equal. | ||
119 | */ | ||
120 | bool operator==(const LLSegment& rhs) const; | ||
121 | |||
111 | protected: | 122 | protected: |
112 | S32 mChannel; | 123 | S32 mChannel; |
113 | U8* mData; | 124 | U8* mData; |
@@ -145,6 +156,35 @@ public: | |||
145 | * @return Returns true if a segment was found. | 156 | * @return Returns true if a segment was found. |
146 | */ | 157 | */ |
147 | virtual bool createSegment(S32 channel, S32 size, LLSegment& segment) = 0; | 158 | virtual bool createSegment(S32 channel, S32 size, LLSegment& segment) = 0; |
159 | |||
160 | /** | ||
161 | * @brief Reclaim a segment from this buffer. | ||
162 | * | ||
163 | * This method is called on a buffer object when a caller is done | ||
164 | * with a contiguous segment of memory inside this buffer. Since | ||
165 | * segments can be cut arbitrarily outside of the control of the | ||
166 | * buffer, this segment may not match any segment returned from | ||
167 | * <code>createSegment()</code>. | ||
168 | * @param segment The contiguous buffer segment to reclaim. | ||
169 | * @return Returns true if the call was successful. | ||
170 | */ | ||
171 | virtual bool reclaimSegment(const LLSegment& segment) = 0; | ||
172 | |||
173 | /** | ||
174 | * @brief Test if a segment is inside this buffer. | ||
175 | * | ||
176 | * @param segment The contiguous buffer segment to test. | ||
177 | * @return Returns true if the segment is in the bufffer. | ||
178 | */ | ||
179 | virtual bool containsSegment(const LLSegment& segment) const = 0; | ||
180 | |||
181 | /** | ||
182 | * @brief Return the current number of bytes allocated. | ||
183 | * | ||
184 | * This was implemented as a debugging tool, and it is not | ||
185 | * necessarily a good idea to use it for anything else. | ||
186 | */ | ||
187 | virtual S32 capacity() const = 0; | ||
148 | }; | 188 | }; |
149 | 189 | ||
150 | /** | 190 | /** |
@@ -186,9 +226,11 @@ public: | |||
186 | /** | 226 | /** |
187 | * @brief Get the number of bytes left in the buffer. | 227 | * @brief Get the number of bytes left in the buffer. |
188 | * | 228 | * |
229 | * Note that this is not a virtual function, and only available in | ||
230 | * the LLHeapBuffer as a debugging aid. | ||
189 | * @return Returns the number of bytes left. | 231 | * @return Returns the number of bytes left. |
190 | */ | 232 | */ |
191 | //virtual S32 bytesLeft() const; | 233 | S32 bytesLeft() const; |
192 | 234 | ||
193 | /** | 235 | /** |
194 | * @brief Generate a segment for this buffer. | 236 | * @brief Generate a segment for this buffer. |
@@ -205,10 +247,40 @@ public: | |||
205 | */ | 247 | */ |
206 | virtual bool createSegment(S32 channel, S32 size, LLSegment& segment); | 248 | virtual bool createSegment(S32 channel, S32 size, LLSegment& segment); |
207 | 249 | ||
250 | /** | ||
251 | * @brief reclaim a segment from this buffer. | ||
252 | * | ||
253 | * This method is called on a buffer object when a caller is done | ||
254 | * with a contiguous segment of memory inside this buffer. Since | ||
255 | * segments can be cut arbitrarily outside of the control of the | ||
256 | * buffer, this segment may not match any segment returned from | ||
257 | * <code>createSegment()</code>. | ||
258 | * This call will fail if the segment passed in is note completely | ||
259 | * inside the buffer, eg, if the segment starts before this buffer | ||
260 | * in memory or ends after it. | ||
261 | * @param segment The contiguous buffer segment to reclaim. | ||
262 | * @return Returns true if the call was successful. | ||
263 | */ | ||
264 | virtual bool reclaimSegment(const LLSegment& segment); | ||
265 | |||
266 | /** | ||
267 | * @brief Test if a segment is inside this buffer. | ||
268 | * | ||
269 | * @param segment The contiguous buffer segment to test. | ||
270 | * @return Returns true if the segment is in the bufffer. | ||
271 | */ | ||
272 | virtual bool containsSegment(const LLSegment& segment) const; | ||
273 | |||
274 | /** | ||
275 | * @brief Return the current number of bytes allocated. | ||
276 | */ | ||
277 | virtual S32 capacity() const { return mSize; } | ||
278 | |||
208 | protected: | 279 | protected: |
209 | U8* mBuffer; | 280 | U8* mBuffer; |
210 | S32 mSize; | 281 | S32 mSize; |
211 | U8* mNextFree; | 282 | U8* mNextFree; |
283 | S32 mReclaimedBytes; | ||
212 | 284 | ||
213 | private: | 285 | private: |
214 | /** | 286 | /** |
@@ -223,13 +295,14 @@ private: | |||
223 | * @brief Class to represent scattered memory buffers and in-order segments | 295 | * @brief Class to represent scattered memory buffers and in-order segments |
224 | * of that buffered data. | 296 | * of that buffered data. |
225 | * | 297 | * |
226 | * NOTE: This class needs to have an iovec interface | 298 | * *NOTE: This class needs to have an iovec interface |
227 | */ | 299 | */ |
228 | class LLBufferArray | 300 | class LLBufferArray |
229 | { | 301 | { |
230 | public: | 302 | public: |
231 | typedef std::vector<LLBuffer*> buffer_list_t; | 303 | typedef std::vector<LLBuffer*> buffer_list_t; |
232 | typedef buffer_list_t::iterator buffer_iterator_t; | 304 | typedef buffer_list_t::iterator buffer_iterator_t; |
305 | typedef buffer_list_t::const_iterator const_buffer_iterator_t; | ||
233 | typedef std::list<LLSegment> segment_list_t; | 306 | typedef std::list<LLSegment> segment_list_t; |
234 | typedef segment_list_t::const_iterator const_segment_iterator_t; | 307 | typedef segment_list_t::const_iterator const_segment_iterator_t; |
235 | typedef segment_list_t::iterator segment_iterator_t; | 308 | typedef segment_list_t::iterator segment_iterator_t; |
@@ -260,11 +333,16 @@ public: | |||
260 | */ | 333 | */ |
261 | LLChannelDescriptors nextChannel(); | 334 | LLChannelDescriptors nextChannel(); |
262 | //@} | 335 | //@} |
263 | 336 | ||
264 | /* @name Data methods | 337 | /* @name Data methods |
265 | */ | 338 | */ |
266 | //@{ | 339 | //@{ |
267 | 340 | ||
341 | /** | ||
342 | * @brief Return the sum of all allocated bytes. | ||
343 | */ | ||
344 | S32 capacity() const; | ||
345 | |||
268 | // These methods will be useful once there is any kind of buffer | 346 | // These methods will be useful once there is any kind of buffer |
269 | // besides a heap buffer. | 347 | // besides a heap buffer. |
270 | //bool append(EBufferChannel channel, LLBuffer* data); | 348 | //bool append(EBufferChannel channel, LLBuffer* data); |
@@ -294,7 +372,6 @@ public: | |||
294 | * new segment is created and put in the front of the array. This | 372 | * new segment is created and put in the front of the array. This |
295 | * object will internally allocate new buffers if necessary. | 373 | * object will internally allocate new buffers if necessary. |
296 | * @param channel The channel for this data | 374 | * @param channel The channel for this data |
297 | |||
298 | * @param src The start of memory for the data to be copied | 375 | * @param src The start of memory for the data to be copied |
299 | * @param len The number of bytes of data to copy | 376 | * @param len The number of bytes of data to copy |
300 | * @return Returns true if the method worked. | 377 | * @return Returns true if the method worked. |
@@ -378,7 +455,7 @@ public: | |||
378 | bool takeContents(LLBufferArray& source); | 455 | bool takeContents(LLBufferArray& source); |
379 | //@} | 456 | //@} |
380 | 457 | ||
381 | /* @name Segment methods | 458 | /* @name Segment methods |
382 | */ | 459 | */ |
383 | //@{ | 460 | //@{ |
384 | /** | 461 | /** |
@@ -468,7 +545,7 @@ public: | |||
468 | * endSegment() on failure. | 545 | * endSegment() on failure. |
469 | */ | 546 | */ |
470 | segment_iterator_t makeSegment(S32 channel, S32 length); | 547 | segment_iterator_t makeSegment(S32 channel, S32 length); |
471 | 548 | ||
472 | /** | 549 | /** |
473 | * @brief Erase the segment if it is in the buffer array. | 550 | * @brief Erase the segment if it is in the buffer array. |
474 | * | 551 | * |