hti/PC_Tools/DataGateway/SRC/safequeue.cpp
branchRCL_3
changeset 59 8ad140f3dd41
parent 0 a03f92240627
equal deleted inserted replaced
49:7fdc9a71d314 59:8ad140f3dd41
       
     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  * This method is used to pop all of the elements in queue and return them in single Data object
       
    22  */
       
    23 template <>
       
    24 (Data*)& SafeQueue<Data*>::popAll(DWORD timeout)
       
    25 	throw (TimeoutException)
       
    26 {
       
    27 	if (Semaphore::Wait(timeout) == WAIT_TIMEOUT)
       
    28 	{
       
    29 		throw TimeoutException("queue front timed out");
       
    30 	}
       
    31 	Mutex::Lock();
       
    32 	Data*& first = queue<Data*>::front();
       
    33 	queue<Data*>::pop();
       
    34 	//add to the first the rest of queue
       
    35 	bool s = true;
       
    36 	while ( queue<Data*>::size() > 0 && s)
       
    37 	{
       
    38 		Data*& a = queue<Data*>::front();
       
    39 		int len = first->GetLength();
       
    40 		first->AppendData( a );
       
    41 		//check that size has changed
       
    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 }