equal
deleted
inserted
replaced
|
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 "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 * This file contains implementation of SafeQueue template class popAll method. |
|
16 */ |
|
17 |
|
18 #include "safequeue.h" |
|
19 #include "common.h" |
|
20 |
|
21 /* |
|
22 * This method is used to pop all of the elements in queue and return them in single Data object |
|
23 */ |
|
24 template <> |
|
25 (Data*)& SafeQueue<Data*>::popAll(DWORD timeout) |
|
26 throw (TimeoutException) |
|
27 { |
|
28 if (Semaphore::Wait(timeout) == WAIT_TIMEOUT) |
|
29 { |
|
30 throw TimeoutException("queue front timed out"); |
|
31 } |
|
32 Mutex::Lock(); |
|
33 Data*& first = queue<Data*>::front(); |
|
34 queue<Data*>::pop(); |
|
35 //add to the first the rest of queue |
|
36 bool s = true; |
|
37 while ( queue<Data*>::size() > 0 && s) |
|
38 { |
|
39 Data*& a = queue<Data*>::front(); |
|
40 int len = first->GetLength(); |
|
41 first->AppendData( a ); //????? |
|
42 if ( first->GetLength() != len ) |
|
43 { |
|
44 queue<Data*>::pop(); |
|
45 delete a; //???? |
|
46 } |
|
47 else |
|
48 { |
|
49 s = false; |
|
50 } |
|
51 } |
|
52 Mutex::Unlock(); |
|
53 return first; |
|
54 } |