|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "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 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef DQUEUE_H |
|
21 #define DQUEUE_H |
|
22 |
|
23 #include <e32def.h> // For TUint32 |
|
24 #include <e32cmn.h> // For TDesC8 |
|
25 #include <klib.h> // For DBase |
|
26 |
|
27 #include "iadinternaldefinitions.h" // For EIAD.... |
|
28 |
|
29 class NFastMutex; |
|
30 |
|
31 // Implemented as ring buffer, syncronization protection by NFastMutex. |
|
32 NONSHARABLE_CLASS( DQueue ) : public DBase |
|
33 { |
|
34 |
|
35 public: |
|
36 |
|
37 IMPORT_C DQueue( const TInt aSize ); |
|
38 |
|
39 IMPORT_C ~DQueue(); |
|
40 |
|
41 /* |
|
42 * In case of queue overflow throw kern::fault, REQ: isaaccessdriver should not lose ISI nor data messages. |
|
43 * Adds the message in the end of the ringbuffer queue. |
|
44 * @param const TDesC8& aMessage, message to be added. |
|
45 */ |
|
46 IMPORT_C void Add( const TDesC8& aMessage ); |
|
47 |
|
48 /* |
|
49 *Returns the first pointer ( iOutputIndex ) from the ring buffer. |
|
50 */ |
|
51 IMPORT_C TUint16 Count(); |
|
52 |
|
53 /* |
|
54 *Returns the first pointer ( iOutputIndex ) from the ring buffer. |
|
55 */ |
|
56 IMPORT_C TDes8& Get(); |
|
57 |
|
58 /* |
|
59 * Rolls bakc to message given at parameter. Message must be the last message get from the queue. |
|
60 */ |
|
61 IMPORT_C void RollBack( const TDesC8& aMsgToRoll ); |
|
62 |
|
63 private: |
|
64 |
|
65 // Index where to add next message pointer. |
|
66 TUint16 iInputIndex; |
|
67 // Index where to get next message pointer. |
|
68 TUint16 iOutputIndex; |
|
69 // Count of items in the array. |
|
70 TUint16 iCount; |
|
71 // Size of the ring buffer. |
|
72 TUint16 iSize; |
|
73 NFastMutex* iQueueMutex; |
|
74 // The memory allocated for the buffer. |
|
75 TDes8** iRingBuffer; |
|
76 |
|
77 }; |
|
78 |
|
79 NONSHARABLE_CLASS( TIADReq ) |
|
80 { |
|
81 public: |
|
82 |
|
83 TIADReq();// not allowed and not needed |
|
84 |
|
85 IMPORT_C TIADReq( TIADAsyncRequest aReq, TInt aStat ); |
|
86 // not owned just hold a pointer. |
|
87 TIADAsyncRequest iRequest; |
|
88 TInt iCompleteStatus; |
|
89 |
|
90 }; |
|
91 |
|
92 // Implemented as ring buffer, syncronization protection by NFastMutex. |
|
93 NONSHARABLE_CLASS( DReqQueue ) : public DBase |
|
94 { |
|
95 |
|
96 public: |
|
97 |
|
98 IMPORT_C DReqQueue(); |
|
99 |
|
100 IMPORT_C ~DReqQueue(); |
|
101 |
|
102 /* |
|
103 * In case of queue overflow throw kern::fault, REQ: isaaccessdriver should not lose ISI nor data messages. |
|
104 * Adds the message in the end of the ringbuffer queue. |
|
105 * @param const TDesC8& aMessage, message to be added. |
|
106 */ |
|
107 IMPORT_C TBool Add( TIADReq aReq ); |
|
108 |
|
109 /* |
|
110 *Returns the first pointer ( iOutputIndex ) from the ring buffer. |
|
111 */ |
|
112 IMPORT_C TBool Empty(); |
|
113 |
|
114 /* |
|
115 *Returns the first pointer ( iOutputIndex ) from the ring buffer. |
|
116 */ |
|
117 IMPORT_C TIADReq Get(); |
|
118 |
|
119 /* |
|
120 * Set req active / deactive. Default deactive. |
|
121 */ |
|
122 IMPORT_C void SetReq( TIADAsyncRequest aReqToSet, TRequestStatus* aStatus = NULL ); |
|
123 |
|
124 /* |
|
125 * Get req. If NULL, request not pending. |
|
126 */ |
|
127 IMPORT_C TRequestStatus* GetReq( TIADAsyncRequest aReqToGet ); |
|
128 |
|
129 |
|
130 private: |
|
131 |
|
132 // Index where to add next message pointer. |
|
133 TUint16 iInputIndex; |
|
134 // Index where to get next message pointer. |
|
135 TUint16 iOutputIndex; |
|
136 // Count of items in the array. |
|
137 TUint16 iCount; |
|
138 // Size of the ring buffer. |
|
139 TUint16 iSize; |
|
140 NFastMutex* iQueueMutex; |
|
141 // Ring buffer must be as big as we have request. TODO: is there a danger to get more request..? |
|
142 TIADReq iReqRingBuffer[ EIADAsyncLast ]; |
|
143 // Active / Deactive requests are kept in list to make finding easier. |
|
144 TRequestStatus* iReqList[ EIADAsyncLast ]; |
|
145 |
|
146 }; |
|
147 |
|
148 |
|
149 #endif /* DQUEUE_H */ |