1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kernel/eka/drivers/debug/smdebug/d_buffer_manager.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,105 @@
1.4 +// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <kernel/kernel.h>
1.20 +#include "d_buffer_manager.h"
1.21 +
1.22 +using namespace Debug;
1.23 +
1.24 +// Global buffer manager
1.25 +DBufferManager TheDBufferManager;
1.26 +
1.27 +DBufferManager::DBufferManager()
1.28 + {
1.29 + }
1.30 +
1.31 +DBufferManager::~DBufferManager()
1.32 + {
1.33 + for(TInt i=0; i<iBuffers.Count(); i++)
1.34 + {
1.35 + if(iBuffers[i].iSize>0 && iBuffers[i].iValue)
1.36 + {
1.37 + Kern::Free((TAny*)iBuffers[i].iValue);
1.38 + }
1.39 + }
1.40 +
1.41 + iBuffers.Close();
1.42 + }
1.43 +
1.44 +/**
1.45 + * Creates a buffer and adds it to the buffer manager
1.46 + * @param aBufferDetails Contains the size and tag ID of the buffer to be created and the location
1.47 + * in which the resulting buffer is created
1.48 + * @return One of the System wide error codes
1.49 + */
1.50 +TInt DBufferManager::CreateBuffer(TTag& aBufferDetails)
1.51 + {
1.52 + if(aBufferDetails.iType != ETagTypePointer)
1.53 + {
1.54 + return KErrArgument;
1.55 + }
1.56 + if(aBufferDetails.iSize == 0)
1.57 + {
1.58 + return KErrArgument;
1.59 + }
1.60 +
1.61 + for(TInt i=0; i<iBuffers.Count(); i++)
1.62 + {
1.63 + if(iBuffers[i].iTagId == aBufferDetails.iTagId)
1.64 + {
1.65 + return KErrAlreadyExists;
1.66 + }
1.67 + }
1.68 +
1.69 + TAny* buffer = Kern::AllocZ(aBufferDetails.iSize);
1.70 + if(!buffer)
1.71 + {
1.72 + return KErrNoMemory;
1.73 + }
1.74 +
1.75 + aBufferDetails.iValue = (TUint32)buffer;
1.76 + if(KErrNone != iBuffers.Append(aBufferDetails))
1.77 + {
1.78 + Kern::Free(buffer);
1.79 + return KErrNoMemory;
1.80 + }
1.81 +
1.82 + return KErrNone;
1.83 + }
1.84 +
1.85 +/**
1.86 + * Retrieves buffer details for a given tag
1.87 + * @param aTag The tag for which to get buffer details
1.88 + * @return One of the System wide error codes
1.89 + */
1.90 +TInt DBufferManager::GetBufferDetails(const TBufferType aBufferType, TTag& aTag) const
1.91 + {
1.92 + for(TInt i=0; i<iBuffers.Count(); i++)
1.93 + {
1.94 + if(iBuffers[i].iTagId == aBufferType)
1.95 + {
1.96 + aTag = iBuffers[i];
1.97 + return KErrNone;
1.98 + }
1.99 + }
1.100 +
1.101 + aTag.iTagId = aBufferType;
1.102 + aTag.iType = ETagTypePointer;
1.103 + aTag.iSize = 0;
1.104 + aTag.iValue = NULL;
1.105 +
1.106 + return KErrNotFound;
1.107 + }
1.108 +