Commit | Line | Data |
---|---|---|
bac41a7b A |
1 | /* |
2 | * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved. | |
3 | * | |
4 | * The contents of this file constitute Original Code as defined in and are | |
5 | * subject to the Apple Public Source License Version 1.2 (the 'License'). | |
6 | * You may not use this file except in compliance with the License. Please obtain | |
7 | * a copy of the License at http://www.apple.com/publicsource and read it before | |
8 | * using this file. | |
9 | * | |
10 | * This Original Code and all software distributed under the License are | |
11 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS | |
12 | * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT | |
13 | * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | |
14 | * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the | |
15 | * specific language governing rights and limitations under the License. | |
16 | */ | |
17 | ||
18 | ||
19 | // | |
20 | // bufferfifo - a Sink that queues data in a FIFO of buffers for retrieval | |
21 | // | |
22 | #ifndef _H_BUFFERFIFO | |
23 | #define _H_BUFFERFIFO | |
24 | ||
25 | #include "streams.h" | |
26 | #include "buffers.h" | |
27 | #include <list> | |
28 | #include <queue> | |
29 | ||
30 | ||
31 | namespace Security { | |
32 | ||
33 | ||
34 | // | |
35 | // A BufferFifo acts as a First-in First-out queue of Buffer objects. | |
36 | // This is usually used as a flexible I/O buffer queue mechanism. | |
37 | // For convenience, a BufferFifo is a Sink, so you can push data | |
38 | // into it directly using the Sink mechanism. | |
39 | // Note that there is currently no mechanism for restricting the | |
40 | // memory footprint of a BufferFifo. | |
41 | // | |
42 | class BufferFifo : public Sink { | |
43 | public: | |
44 | BufferFifo(size_t es = 4096) : bufferLength(es) { } | |
45 | ~BufferFifo(); | |
46 | ||
47 | Buffer *top() const { assert(!mBuffers.empty()); return mBuffers.front(); } | |
48 | Buffer *pop(); | |
49 | void push(Buffer *b) { mBuffers.push(b); } | |
50 | ||
51 | bool isEmpty() const { return mBuffers.empty(); } | |
52 | size_t size() const { return mBuffers.size(); } | |
53 | size_t topLength() const { assert(!isEmpty()); return mBuffers.front()->length(); } | |
54 | ||
55 | // Sink implementation | |
56 | void consume(const void *data, size_t size); | |
c25717e3 | 57 | void clearBuffer(); |
bac41a7b A |
58 | |
59 | private: | |
60 | typedef queue< Buffer *, list<Buffer *> > BufferQueue; | |
61 | BufferQueue mBuffers; | |
62 | const size_t bufferLength; | |
63 | }; | |
64 | ||
65 | ||
66 | ||
67 | } // end namespace Security | |
68 | ||
69 | ||
df0e469f | 70 | #endif /* _H_BUFFERFIFO */ |