|
1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - Initial contribution |
|
11 * |
|
12 * Contributors: |
|
13 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * Data buffering and queuing support definitions, class CActiveQueue. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 #ifndef __ACTIVEQUEUE_H__ |
|
22 #define __ACTIVEQUEUE_H__ |
|
23 |
|
24 |
|
25 // INCLUDES |
|
26 |
|
27 #ifndef __E32BASE_H__ |
|
28 #include <e32base.h> |
|
29 #endif |
|
30 |
|
31 |
|
32 // FORWARD DECLARATIONS |
|
33 |
|
34 class CDataProcessor; |
|
35 class CActiveQueue; |
|
36 |
|
37 |
|
38 //#define BLOCK_GUARD_AREA |
|
39 |
|
40 |
|
41 // CLASS DEFINITIONS |
|
42 |
|
43 // Queue block class |
|
44 class TActiveQueueBlock : public TPtr8 |
|
45 { |
|
46 TActiveQueueBlock(TUint8 *aBuf, TInt aMaxLength) : TPtr8(aBuf, aMaxLength) {}; |
|
47 protected: |
|
48 friend class CActiveQueue; |
|
49 TActiveQueueBlock *iNextBlock; // next block in the allocated block list |
|
50 TActiveQueueBlock *iPrevBlock; // prev. block in the allocated block list |
|
51 TActiveQueueBlock *iNextList; // next block in the data queue / free list |
|
52 }; |
|
53 |
|
54 // The queue class |
|
55 class CActiveQueue : public CBase |
|
56 { |
|
57 public: // constants |
|
58 enum TErrorCode |
|
59 { |
|
60 EInternalAssertionFailure = -1000, |
|
61 ENoWriter = -1001, |
|
62 ENoReader = -1002, |
|
63 EWriteAfterStreamEnd = -1003 |
|
64 }; |
|
65 |
|
66 public: // interface functions |
|
67 // Constructors and destructor |
|
68 CActiveQueue(TUint aNumberOfBlocks, TUint aBlockLength); |
|
69 ~CActiveQueue(); |
|
70 void ConstructL(); |
|
71 |
|
72 // Set/remove reader |
|
73 void SetReader(CDataProcessor *aReader, TAny *aUserPointer); |
|
74 void RemoveReader(); |
|
75 |
|
76 // Set/remove writer |
|
77 void SetWriter(CDataProcessor *aWriter, TAny *aUserPointer); |
|
78 void RemoveWriter(); |
|
79 |
|
80 void ResetStreamEnd(); |
|
81 |
|
82 // Get the number of free blocks available for new data |
|
83 TUint NumFreeBlocks(); |
|
84 |
|
85 // Get the number of blocks with data queued |
|
86 TUint NumDataBlocks(); |
|
87 |
|
88 // Get a free block for writing data into the queue (writer) |
|
89 TPtr8 *GetFreeBlockL(TUint aBlockLength); |
|
90 |
|
91 // Add a data block to the queue (writer) |
|
92 void WriteBlock(TPtr8 *aBlock); |
|
93 |
|
94 // Read a data block from the queue (reader) |
|
95 TPtr8 *ReadBlock(); |
|
96 |
|
97 // Return a read block back to the empty block list (reader) |
|
98 void ReturnBlock(TPtr8 *aBlock); |
|
99 |
|
100 // Notify that the stream has ended (writer) |
|
101 void WriteStreamEnd(); |
|
102 |
|
103 // Check if the writer has notified that the stream has ended (reader) |
|
104 TBool StreamEnded(); |
|
105 |
|
106 // Testing aid: get total number of blocks |
|
107 TUint NumBlocks() { return iNumBlocks; }; |
|
108 |
|
109 |
|
110 private: // Internal methods |
|
111 TActiveQueueBlock *AllocateBlockL(); |
|
112 void FreeBlockL(TActiveQueueBlock *aBlock); |
|
113 |
|
114 private: // Data |
|
115 TUint iNewBlockLength; // length of new blocks that are allocated |
|
116 TUint iInitialBlocks; // initial number of blocks to allocate |
|
117 |
|
118 CDataProcessor *iReader; // the reader |
|
119 TAny *iReaderUserPointer; |
|
120 CDataProcessor *iWriter; // the writer |
|
121 TAny *iWriterUserPointer; |
|
122 |
|
123 TActiveQueueBlock *iBlocks; // the list of all allocated blocks |
|
124 TUint iNumBlocks; // total number of blocks |
|
125 TActiveQueueBlock *iFreeList; // the free block list |
|
126 TUint iNumFreeBlocks; // number of free blocks |
|
127 TActiveQueueBlock *iDataQueueHead; // the data queue head (where blocks are |
|
128 // read from) |
|
129 TActiveQueueBlock *iDataQueueTail; // the data queue tail (where blocks are |
|
130 // written to |
|
131 TUint iNumDataBlocks; // number of data blocks |
|
132 |
|
133 TBool iStreamEnd; // has the stream ended? |
|
134 }; |
|
135 |
|
136 |
|
137 #endif // __ACTIVEQUEUE_H__ |
|
138 |
|
139 // End of File |