sl@0
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#ifndef _MMRCUTIL_H_
|
sl@0
|
17 |
#define _MMRCUTIL_H_
|
sl@0
|
18 |
|
sl@0
|
19 |
#include <e32base.h>
|
sl@0
|
20 |
|
sl@0
|
21 |
template <class T>
|
sl@0
|
22 |
class RMMRCFifoQueue
|
sl@0
|
23 |
{
|
sl@0
|
24 |
public:
|
sl@0
|
25 |
RMMRCFifoQueue( );
|
sl@0
|
26 |
~RMMRCFifoQueue( );
|
sl@0
|
27 |
|
sl@0
|
28 |
void Reset( );
|
sl@0
|
29 |
void ResetAndDestroy();
|
sl@0
|
30 |
TBool IsEmpty( ) const;
|
sl@0
|
31 |
TInt Count() const;
|
sl@0
|
32 |
T* PopAndRemove( );
|
sl@0
|
33 |
T* PopAndRemove( TInt aIndex );
|
sl@0
|
34 |
void PushL( T const* const aElement );
|
sl@0
|
35 |
T* Pop( ) const;
|
sl@0
|
36 |
T* Pop( TInt aIndex ) const;
|
sl@0
|
37 |
T* operator[] ( TInt aIndex ) const;
|
sl@0
|
38 |
|
sl@0
|
39 |
private:
|
sl@0
|
40 |
RMMRCFifoQueue( const RMMRCFifoQueue & aMMRCFifoQueue ); //not implemented
|
sl@0
|
41 |
const RMMRCFifoQueue & operator= ( const RMMRCFifoQueue & aMMRCFifoQueue ); //not implemented
|
sl@0
|
42 |
|
sl@0
|
43 |
private:
|
sl@0
|
44 |
struct TListNode
|
sl@0
|
45 |
{
|
sl@0
|
46 |
T const* iElement;
|
sl@0
|
47 |
TListNode *iNext;
|
sl@0
|
48 |
|
sl@0
|
49 |
TListNode( T const* const aElement )
|
sl@0
|
50 |
: iElement( aElement ), iNext(NULL) { }
|
sl@0
|
51 |
};
|
sl@0
|
52 |
|
sl@0
|
53 |
TListNode *iFirst;
|
sl@0
|
54 |
TListNode *iLast;
|
sl@0
|
55 |
TInt iCount;
|
sl@0
|
56 |
};
|
sl@0
|
57 |
|
sl@0
|
58 |
/**
|
sl@0
|
59 |
Construct the queue.
|
sl@0
|
60 |
*/
|
sl@0
|
61 |
template <class T>
|
sl@0
|
62 |
RMMRCFifoQueue<T>::RMMRCFifoQueue( )
|
sl@0
|
63 |
{
|
sl@0
|
64 |
iFirst = iLast = NULL;
|
sl@0
|
65 |
iCount = 0;
|
sl@0
|
66 |
}
|
sl@0
|
67 |
|
sl@0
|
68 |
/**
|
sl@0
|
69 |
Destructor.
|
sl@0
|
70 |
*/
|
sl@0
|
71 |
template <class T>
|
sl@0
|
72 |
RMMRCFifoQueue<T>::~RMMRCFifoQueue( )
|
sl@0
|
73 |
{
|
sl@0
|
74 |
Reset( );
|
sl@0
|
75 |
}
|
sl@0
|
76 |
|
sl@0
|
77 |
|
sl@0
|
78 |
/**
|
sl@0
|
79 |
Delete each node without deleting the elements.
|
sl@0
|
80 |
*/
|
sl@0
|
81 |
template <class T>
|
sl@0
|
82 |
void RMMRCFifoQueue<T>::Reset( )
|
sl@0
|
83 |
{
|
sl@0
|
84 |
while( !IsEmpty( ) )
|
sl@0
|
85 |
{
|
sl@0
|
86 |
PopAndRemove( );
|
sl@0
|
87 |
}
|
sl@0
|
88 |
}
|
sl@0
|
89 |
|
sl@0
|
90 |
/**
|
sl@0
|
91 |
Delete each node and each element.
|
sl@0
|
92 |
*/
|
sl@0
|
93 |
template <class T>
|
sl@0
|
94 |
void RMMRCFifoQueue<T>::ResetAndDestroy( )
|
sl@0
|
95 |
{
|
sl@0
|
96 |
while( !IsEmpty( ) )
|
sl@0
|
97 |
{
|
sl@0
|
98 |
T* element = PopAndRemove( );
|
sl@0
|
99 |
delete element;
|
sl@0
|
100 |
}
|
sl@0
|
101 |
}
|
sl@0
|
102 |
|
sl@0
|
103 |
/**
|
sl@0
|
104 |
Return the number of elements.
|
sl@0
|
105 |
*/
|
sl@0
|
106 |
template <class T>
|
sl@0
|
107 |
TInt RMMRCFifoQueue<T>::Count( ) const
|
sl@0
|
108 |
{
|
sl@0
|
109 |
return iCount;
|
sl@0
|
110 |
}
|
sl@0
|
111 |
|
sl@0
|
112 |
|
sl@0
|
113 |
/**
|
sl@0
|
114 |
Test if the queue is logically empty.
|
sl@0
|
115 |
Return TTrue if empty, TFalse, otherwise.
|
sl@0
|
116 |
*/
|
sl@0
|
117 |
template <class T>
|
sl@0
|
118 |
TBool RMMRCFifoQueue<T>::IsEmpty( ) const
|
sl@0
|
119 |
{
|
sl@0
|
120 |
return iFirst == NULL;
|
sl@0
|
121 |
}
|
sl@0
|
122 |
|
sl@0
|
123 |
|
sl@0
|
124 |
/**
|
sl@0
|
125 |
Return and remove the least recently inserted item from the queue.
|
sl@0
|
126 |
*/
|
sl@0
|
127 |
template <class T>
|
sl@0
|
128 |
T* RMMRCFifoQueue<T>::PopAndRemove( )
|
sl@0
|
129 |
{
|
sl@0
|
130 |
T* element = NULL;
|
sl@0
|
131 |
if( !IsEmpty( ) )
|
sl@0
|
132 |
{
|
sl@0
|
133 |
TListNode* front = iFirst;
|
sl@0
|
134 |
element = const_cast<T*>(iFirst->iElement);
|
sl@0
|
135 |
iFirst = iFirst->iNext;
|
sl@0
|
136 |
if( NULL == iFirst )
|
sl@0
|
137 |
{
|
sl@0
|
138 |
iLast = NULL;
|
sl@0
|
139 |
}
|
sl@0
|
140 |
iCount--;
|
sl@0
|
141 |
delete front;
|
sl@0
|
142 |
front = NULL;
|
sl@0
|
143 |
}
|
sl@0
|
144 |
return element;
|
sl@0
|
145 |
}
|
sl@0
|
146 |
|
sl@0
|
147 |
/**
|
sl@0
|
148 |
Return and remove the least recently inserted item from the queue.
|
sl@0
|
149 |
*/
|
sl@0
|
150 |
template <class T>
|
sl@0
|
151 |
T* RMMRCFifoQueue<T>::PopAndRemove( TInt aIndex )
|
sl@0
|
152 |
{
|
sl@0
|
153 |
T* element = NULL;
|
sl@0
|
154 |
TListNode* PreviousNode = NULL;
|
sl@0
|
155 |
TListNode* node = iFirst;
|
sl@0
|
156 |
TInt i = 0;
|
sl@0
|
157 |
for( ; i<aIndex && i<iCount && node->iNext ; i++)
|
sl@0
|
158 |
{
|
sl@0
|
159 |
PreviousNode = node;
|
sl@0
|
160 |
node = node->iNext;
|
sl@0
|
161 |
}
|
sl@0
|
162 |
|
sl@0
|
163 |
if(node && i < iCount)
|
sl@0
|
164 |
{
|
sl@0
|
165 |
if(PreviousNode)
|
sl@0
|
166 |
{
|
sl@0
|
167 |
PreviousNode->iNext = node->iNext;
|
sl@0
|
168 |
if( NULL == node->iNext )
|
sl@0
|
169 |
{
|
sl@0
|
170 |
iLast = PreviousNode;
|
sl@0
|
171 |
}
|
sl@0
|
172 |
}
|
sl@0
|
173 |
else
|
sl@0
|
174 |
{
|
sl@0
|
175 |
iFirst = node->iNext;
|
sl@0
|
176 |
if( NULL == iFirst )
|
sl@0
|
177 |
{
|
sl@0
|
178 |
iLast = NULL;
|
sl@0
|
179 |
}
|
sl@0
|
180 |
}
|
sl@0
|
181 |
element = const_cast<T*>(node->iElement);
|
sl@0
|
182 |
iCount--;
|
sl@0
|
183 |
delete node;
|
sl@0
|
184 |
}
|
sl@0
|
185 |
return element;
|
sl@0
|
186 |
}
|
sl@0
|
187 |
|
sl@0
|
188 |
/**
|
sl@0
|
189 |
Insert aElement into the queue.
|
sl@0
|
190 |
*/
|
sl@0
|
191 |
template <class T>
|
sl@0
|
192 |
void RMMRCFifoQueue<T>::PushL( T const* const aElement )
|
sl@0
|
193 |
{
|
sl@0
|
194 |
if( IsEmpty( ) )
|
sl@0
|
195 |
{
|
sl@0
|
196 |
iLast = iFirst = new(ELeave) TListNode( aElement );
|
sl@0
|
197 |
}
|
sl@0
|
198 |
else
|
sl@0
|
199 |
{
|
sl@0
|
200 |
iLast = iLast->iNext = new(ELeave) TListNode( aElement );
|
sl@0
|
201 |
}
|
sl@0
|
202 |
iCount++;
|
sl@0
|
203 |
}
|
sl@0
|
204 |
|
sl@0
|
205 |
/**
|
sl@0
|
206 |
Pop a pointer of the aIndex elements.
|
sl@0
|
207 |
*/
|
sl@0
|
208 |
template <class T>
|
sl@0
|
209 |
T* RMMRCFifoQueue<T>::Pop ( ) const
|
sl@0
|
210 |
{
|
sl@0
|
211 |
T* element = NULL;
|
sl@0
|
212 |
TListNode* node = iFirst;
|
sl@0
|
213 |
|
sl@0
|
214 |
if( node )
|
sl@0
|
215 |
{
|
sl@0
|
216 |
element = const_cast<T*>(node->iElement);
|
sl@0
|
217 |
}
|
sl@0
|
218 |
|
sl@0
|
219 |
return element;
|
sl@0
|
220 |
}
|
sl@0
|
221 |
|
sl@0
|
222 |
/**
|
sl@0
|
223 |
Pop a pointer of the aIndex elements.
|
sl@0
|
224 |
*/
|
sl@0
|
225 |
template <class T>
|
sl@0
|
226 |
T* RMMRCFifoQueue<T>::Pop ( TInt aIndex ) const
|
sl@0
|
227 |
{
|
sl@0
|
228 |
T* element = NULL;
|
sl@0
|
229 |
TListNode* node = iFirst;
|
sl@0
|
230 |
|
sl@0
|
231 |
TInt i = 0;
|
sl@0
|
232 |
for( ; (i < aIndex) && (i < iCount) && (node->iNext != NULL) ; i++)
|
sl@0
|
233 |
{
|
sl@0
|
234 |
node = node->iNext;
|
sl@0
|
235 |
}
|
sl@0
|
236 |
|
sl@0
|
237 |
if( ( NULL != node )
|
sl@0
|
238 |
&& ( i < iCount ) )
|
sl@0
|
239 |
{
|
sl@0
|
240 |
element = const_cast<T*>(node->iElement);
|
sl@0
|
241 |
}
|
sl@0
|
242 |
|
sl@0
|
243 |
return element;
|
sl@0
|
244 |
}
|
sl@0
|
245 |
|
sl@0
|
246 |
/**
|
sl@0
|
247 |
Pop a pointer of the aIndex elements.
|
sl@0
|
248 |
*/
|
sl@0
|
249 |
template <class T>
|
sl@0
|
250 |
T* RMMRCFifoQueue<T>::operator[] ( TInt aIndex ) const
|
sl@0
|
251 |
{
|
sl@0
|
252 |
return Pop(aIndex);
|
sl@0
|
253 |
}
|
sl@0
|
254 |
|
sl@0
|
255 |
|
sl@0
|
256 |
/**
|
sl@0
|
257 |
Class for manage the list of the sessions requesting pause.
|
sl@0
|
258 |
*/
|
sl@0
|
259 |
template <class T>
|
sl@0
|
260 |
class RMMRCFifoOrderQueue : private RMMRCFifoQueue <T>
|
sl@0
|
261 |
{
|
sl@0
|
262 |
|
sl@0
|
263 |
public:
|
sl@0
|
264 |
RMMRCFifoOrderQueue( );
|
sl@0
|
265 |
~RMMRCFifoOrderQueue( );
|
sl@0
|
266 |
void ResetAndDestroy( );
|
sl@0
|
267 |
TInt Count() const;
|
sl@0
|
268 |
void PushL( T const* const aElement );
|
sl@0
|
269 |
T* PopAndRemoveForPause( TInt aIndex );
|
sl@0
|
270 |
T* operator[] ( TInt aIndex ) const;
|
sl@0
|
271 |
|
sl@0
|
272 |
|
sl@0
|
273 |
private:
|
sl@0
|
274 |
RPointerArray< T > iQueue;
|
sl@0
|
275 |
};
|
sl@0
|
276 |
|
sl@0
|
277 |
|
sl@0
|
278 |
/**
|
sl@0
|
279 |
Construct the queue.
|
sl@0
|
280 |
*/
|
sl@0
|
281 |
template <class T>
|
sl@0
|
282 |
RMMRCFifoOrderQueue<T>::RMMRCFifoOrderQueue( )
|
sl@0
|
283 |
{
|
sl@0
|
284 |
}
|
sl@0
|
285 |
|
sl@0
|
286 |
/**
|
sl@0
|
287 |
Destructor.
|
sl@0
|
288 |
*/
|
sl@0
|
289 |
template <class T>
|
sl@0
|
290 |
RMMRCFifoOrderQueue<T>::~RMMRCFifoOrderQueue( )
|
sl@0
|
291 |
{
|
sl@0
|
292 |
iQueue.Reset();
|
sl@0
|
293 |
iQueue.Close();
|
sl@0
|
294 |
}
|
sl@0
|
295 |
|
sl@0
|
296 |
/**
|
sl@0
|
297 |
Return the number of elements.
|
sl@0
|
298 |
*/
|
sl@0
|
299 |
template <class T>
|
sl@0
|
300 |
TInt RMMRCFifoOrderQueue<T>::Count( ) const
|
sl@0
|
301 |
{
|
sl@0
|
302 |
|
sl@0
|
303 |
TInt iNum = iQueue.Count();
|
sl@0
|
304 |
return iNum;
|
sl@0
|
305 |
}
|
sl@0
|
306 |
|
sl@0
|
307 |
/**
|
sl@0
|
308 |
Delete each node and each element.
|
sl@0
|
309 |
*/
|
sl@0
|
310 |
template <class T>
|
sl@0
|
311 |
void RMMRCFifoOrderQueue<T>::ResetAndDestroy( )
|
sl@0
|
312 |
{
|
sl@0
|
313 |
iQueue.ResetAndDestroy();
|
sl@0
|
314 |
}
|
sl@0
|
315 |
|
sl@0
|
316 |
/**
|
sl@0
|
317 |
Insert aElement into the queue and ordered.
|
sl@0
|
318 |
*/
|
sl@0
|
319 |
template <class T>
|
sl@0
|
320 |
void RMMRCFifoOrderQueue<T>::PushL( T const* const aElement )
|
sl@0
|
321 |
{
|
sl@0
|
322 |
TInt numElements = iQueue.Count();
|
sl@0
|
323 |
|
sl@0
|
324 |
if( numElements == 0 )
|
sl@0
|
325 |
{
|
sl@0
|
326 |
iQueue.Append(aElement); //iQueue: We need to check the error here
|
sl@0
|
327 |
return;
|
sl@0
|
328 |
}
|
sl@0
|
329 |
|
sl@0
|
330 |
for(TInt i(0); i<numElements ; ++i)
|
sl@0
|
331 |
{
|
sl@0
|
332 |
if(aElement->HasMultimediaCapability() && !(iQueue[i]->HasMultimediaCapability()))
|
sl@0
|
333 |
{
|
sl@0
|
334 |
iQueue.Insert(aElement, i);
|
sl@0
|
335 |
return;
|
sl@0
|
336 |
}
|
sl@0
|
337 |
else if(aElement->HasMultimediaCapability() == iQueue[i]->HasMultimediaCapability())
|
sl@0
|
338 |
{
|
sl@0
|
339 |
if (aElement->GetPriority() > iQueue[i]->GetPriority())
|
sl@0
|
340 |
{
|
sl@0
|
341 |
iQueue.Insert(aElement,i);
|
sl@0
|
342 |
return;
|
sl@0
|
343 |
}
|
sl@0
|
344 |
}
|
sl@0
|
345 |
}
|
sl@0
|
346 |
iQueue.Insert(aElement,numElements);
|
sl@0
|
347 |
}
|
sl@0
|
348 |
|
sl@0
|
349 |
/**
|
sl@0
|
350 |
Return and remove the inserted item from the queue.
|
sl@0
|
351 |
*/
|
sl@0
|
352 |
template <class T>
|
sl@0
|
353 |
T* RMMRCFifoOrderQueue<T>::PopAndRemoveForPause( TInt aIndex )
|
sl@0
|
354 |
{
|
sl@0
|
355 |
T* aux = NULL;
|
sl@0
|
356 |
aux = iQueue[aIndex];
|
sl@0
|
357 |
iQueue.Remove(aIndex);
|
sl@0
|
358 |
return aux;
|
sl@0
|
359 |
}
|
sl@0
|
360 |
|
sl@0
|
361 |
|
sl@0
|
362 |
/**
|
sl@0
|
363 |
Pop a pointer of the aIndex elements.
|
sl@0
|
364 |
*/
|
sl@0
|
365 |
template <class T>
|
sl@0
|
366 |
T* RMMRCFifoOrderQueue<T>::operator[] ( TInt aIndex ) const
|
sl@0
|
367 |
{
|
sl@0
|
368 |
if(iQueue.Count() != 0)
|
sl@0
|
369 |
{
|
sl@0
|
370 |
return iQueue[aIndex];
|
sl@0
|
371 |
}
|
sl@0
|
372 |
else
|
sl@0
|
373 |
{
|
sl@0
|
374 |
return NULL;
|
sl@0
|
375 |
}
|
sl@0
|
376 |
}
|
sl@0
|
377 |
|
sl@0
|
378 |
#endif /*_MMRCUTIL_H_*/
|