os/kernelhwsrv/kernel/eka/drivers/debug/smdebug/d_buffer_manager.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // 
    15 
    16 #include <kernel/kernel.h>
    17 #include "d_buffer_manager.h"
    18 
    19 using namespace Debug;
    20 
    21 // Global buffer manager
    22 DBufferManager TheDBufferManager;
    23 
    24 DBufferManager::DBufferManager()
    25 	{
    26 	}
    27 
    28 DBufferManager::~DBufferManager()
    29 	{
    30 	for(TInt i=0; i<iBuffers.Count(); i++)
    31 		{
    32 		if(iBuffers[i].iSize>0 && iBuffers[i].iValue)
    33 			{
    34 			Kern::Free((TAny*)iBuffers[i].iValue);
    35 			}
    36 		}
    37 	
    38 	iBuffers.Close();
    39 	}
    40 
    41 /**
    42  * Creates a buffer and adds it to the buffer manager
    43  * @param aBufferDetails Contains the size and tag ID of the buffer to be created and the location
    44  *						in which the resulting buffer is created
    45  * @return One of the System wide error codes
    46  */
    47 TInt DBufferManager::CreateBuffer(TTag& aBufferDetails)
    48 	{
    49 	if(aBufferDetails.iType != ETagTypePointer)
    50 		{
    51 		return KErrArgument;
    52 		}
    53 	if(aBufferDetails.iSize == 0)
    54 		{
    55 		return KErrArgument;
    56 		}
    57 
    58 	for(TInt i=0; i<iBuffers.Count(); i++)
    59 		{
    60 		if(iBuffers[i].iTagId == aBufferDetails.iTagId)
    61 			{
    62 			return KErrAlreadyExists;
    63 			}
    64 		}
    65 	
    66 	TAny* buffer = Kern::AllocZ(aBufferDetails.iSize);
    67 	if(!buffer)
    68 		{
    69 		return KErrNoMemory;
    70 		}
    71 	
    72 	aBufferDetails.iValue = (TUint32)buffer;
    73 	if(KErrNone != iBuffers.Append(aBufferDetails))
    74 		{
    75 		Kern::Free(buffer);
    76 		return KErrNoMemory;
    77 		}
    78 	
    79 	return KErrNone;
    80 	}
    81 
    82 /**
    83  * Retrieves buffer details for a given tag
    84  * @param aTag The tag for which to get buffer details
    85  * @return One of the System wide error codes
    86  */
    87 TInt DBufferManager::GetBufferDetails(const TBufferType aBufferType, TTag& aTag) const
    88 	{
    89 	for(TInt i=0; i<iBuffers.Count(); i++)
    90 		{
    91 		if(iBuffers[i].iTagId == aBufferType)
    92 			{
    93 			aTag = iBuffers[i];
    94 			return KErrNone;
    95 			}
    96 		}
    97 	
    98 	aTag.iTagId = aBufferType;
    99 	aTag.iType = ETagTypePointer;
   100 	aTag.iSize = 0;
   101 	aTag.iValue = NULL;
   102 
   103 	return KErrNotFound;
   104 	}
   105