author | sl@SLION-WIN7.fritz.box |
Fri, 15 Jun 2012 03:10:57 +0200 | |
changeset 0 | bde4ae8d615e |
permissions | -rw-r--r-- |
sl@0 | 1 |
// Copyright (c) 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 the License "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 |
#include <kernel/kernel.h> |
sl@0 | 17 |
#include "d_buffer_manager.h" |
sl@0 | 18 |
|
sl@0 | 19 |
using namespace Debug; |
sl@0 | 20 |
|
sl@0 | 21 |
// Global buffer manager |
sl@0 | 22 |
DBufferManager TheDBufferManager; |
sl@0 | 23 |
|
sl@0 | 24 |
DBufferManager::DBufferManager() |
sl@0 | 25 |
{ |
sl@0 | 26 |
} |
sl@0 | 27 |
|
sl@0 | 28 |
DBufferManager::~DBufferManager() |
sl@0 | 29 |
{ |
sl@0 | 30 |
for(TInt i=0; i<iBuffers.Count(); i++) |
sl@0 | 31 |
{ |
sl@0 | 32 |
if(iBuffers[i].iSize>0 && iBuffers[i].iValue) |
sl@0 | 33 |
{ |
sl@0 | 34 |
Kern::Free((TAny*)iBuffers[i].iValue); |
sl@0 | 35 |
} |
sl@0 | 36 |
} |
sl@0 | 37 |
|
sl@0 | 38 |
iBuffers.Close(); |
sl@0 | 39 |
} |
sl@0 | 40 |
|
sl@0 | 41 |
/** |
sl@0 | 42 |
* Creates a buffer and adds it to the buffer manager |
sl@0 | 43 |
* @param aBufferDetails Contains the size and tag ID of the buffer to be created and the location |
sl@0 | 44 |
* in which the resulting buffer is created |
sl@0 | 45 |
* @return One of the System wide error codes |
sl@0 | 46 |
*/ |
sl@0 | 47 |
TInt DBufferManager::CreateBuffer(TTag& aBufferDetails) |
sl@0 | 48 |
{ |
sl@0 | 49 |
if(aBufferDetails.iType != ETagTypePointer) |
sl@0 | 50 |
{ |
sl@0 | 51 |
return KErrArgument; |
sl@0 | 52 |
} |
sl@0 | 53 |
if(aBufferDetails.iSize == 0) |
sl@0 | 54 |
{ |
sl@0 | 55 |
return KErrArgument; |
sl@0 | 56 |
} |
sl@0 | 57 |
|
sl@0 | 58 |
for(TInt i=0; i<iBuffers.Count(); i++) |
sl@0 | 59 |
{ |
sl@0 | 60 |
if(iBuffers[i].iTagId == aBufferDetails.iTagId) |
sl@0 | 61 |
{ |
sl@0 | 62 |
return KErrAlreadyExists; |
sl@0 | 63 |
} |
sl@0 | 64 |
} |
sl@0 | 65 |
|
sl@0 | 66 |
TAny* buffer = Kern::AllocZ(aBufferDetails.iSize); |
sl@0 | 67 |
if(!buffer) |
sl@0 | 68 |
{ |
sl@0 | 69 |
return KErrNoMemory; |
sl@0 | 70 |
} |
sl@0 | 71 |
|
sl@0 | 72 |
aBufferDetails.iValue = (TUint32)buffer; |
sl@0 | 73 |
if(KErrNone != iBuffers.Append(aBufferDetails)) |
sl@0 | 74 |
{ |
sl@0 | 75 |
Kern::Free(buffer); |
sl@0 | 76 |
return KErrNoMemory; |
sl@0 | 77 |
} |
sl@0 | 78 |
|
sl@0 | 79 |
return KErrNone; |
sl@0 | 80 |
} |
sl@0 | 81 |
|
sl@0 | 82 |
/** |
sl@0 | 83 |
* Retrieves buffer details for a given tag |
sl@0 | 84 |
* @param aTag The tag for which to get buffer details |
sl@0 | 85 |
* @return One of the System wide error codes |
sl@0 | 86 |
*/ |
sl@0 | 87 |
TInt DBufferManager::GetBufferDetails(const TBufferType aBufferType, TTag& aTag) const |
sl@0 | 88 |
{ |
sl@0 | 89 |
for(TInt i=0; i<iBuffers.Count(); i++) |
sl@0 | 90 |
{ |
sl@0 | 91 |
if(iBuffers[i].iTagId == aBufferType) |
sl@0 | 92 |
{ |
sl@0 | 93 |
aTag = iBuffers[i]; |
sl@0 | 94 |
return KErrNone; |
sl@0 | 95 |
} |
sl@0 | 96 |
} |
sl@0 | 97 |
|
sl@0 | 98 |
aTag.iTagId = aBufferType; |
sl@0 | 99 |
aTag.iType = ETagTypePointer; |
sl@0 | 100 |
aTag.iSize = 0; |
sl@0 | 101 |
aTag.iValue = NULL; |
sl@0 | 102 |
|
sl@0 | 103 |
return KErrNotFound; |
sl@0 | 104 |
} |
sl@0 | 105 |