sl@0: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // f32test\concur\cfafshmem.cpp sl@0: // Definition of the THMem class member functions. sl@0: // sl@0: // sl@0: sl@0: #include "cfafshmem.h" sl@0: sl@0: sl@0: THMem::THMem(void * aNewMemPtr) : iMemPtr(aNewMemPtr), sl@0: //iNoMess(ETrue), sl@0: //threadHandle(NO_THREAD), sl@0: iBaseOffset(KNoOffset) sl@0: /** sl@0: * Constructor. Initialises the members of THMem. sl@0: * sl@0: * @param aNewMemPtr Pointer to the memory that this THMem will sl@0: * represent sl@0: * @internalComponent sl@0: */ sl@0: sl@0: { sl@0: iMessage=NULL; sl@0: } sl@0: sl@0: sl@0: THMem::THMem(const void * aNewMemPtr,const RMessagePtr2& aMessage,int aNewOffset) sl@0: : iMemPtr((void*)aNewMemPtr), iBaseOffset(aNewOffset) sl@0: /** sl@0: * Constructor. Initialises the members of THMem. sl@0: * sl@0: * @param aNewMemPtr Pointer to the memory that this THMem will sl@0: * represent sl@0: * @param aMessage sl@0: * @param aNewOffset sl@0: * @internalComponent sl@0: */ sl@0: sl@0: { sl@0: iMessage=(RMessagePtr2*)&aMessage; sl@0: } sl@0: sl@0: sl@0: sl@0: TInt THMem::Read(void *aBuf, TUint32 aLength, TUint aOffset) const sl@0: /** sl@0: * Reads a chunk of memory from the THMem. sl@0: * sl@0: * @param aBuf goal buffer bointer sl@0: * @param aLength how many bytes that will be read from sl@0: * the THMem sl@0: * @param aOffset offset into the THMem where the function sl@0: * will start reading sl@0: * @return Error code - KErrNone on success sl@0: * @internalComponent sl@0: */ sl@0: { sl@0: if(iMessage==NULL) sl@0: { sl@0: memcpy(aBuf, ((TUint8*)iMemPtr + aOffset), (TInt)aLength); sl@0: // Always return success sl@0: return KErrNone; sl@0: } sl@0: else if ((iMessage == NULL) || (iMessage->Handle() == KLocalMessageHandle)) sl@0: { sl@0: TUint8* ptr = (TUint8*) ((TDes8*) iMemPtr)->Ptr(); sl@0: memcpy(aBuf, ptr + iBaseOffset + aOffset, (TInt)aLength); sl@0: // Always return success sl@0: return KErrNone; sl@0: } sl@0: else sl@0: { sl@0: #if defined(__SYMBIAN32__) sl@0: // Create EPOC memory representation sl@0: TPtr8 mem((TUint8*)aBuf,aLength); sl@0: sl@0: // Create EPOC memory representation sl@0: TRAPD(res,iMessage->ReadL(0,mem, iBaseOffset + aOffset)); sl@0: sl@0: // Return error code sl@0: return (TInt)res; sl@0: #else sl@0: LFFS_ASSERT(0); sl@0: return E_GENERAL; sl@0: #endif sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: TInt THMem::Write(const void *aBuf, TUint32 aLength, TUint32 aOffset) sl@0: /** sl@0: * Writes a chunk of memory to the THMem. sl@0: * sl@0: * @param aBuf source buffer bointer sl@0: * @param aLength how many bytes that will be written to sl@0: * the THMem sl@0: * @param aOffset offset into the THMem where the function sl@0: * will start writing sl@0: * @return Error code - KErrNone on success sl@0: * @internalComponent sl@0: */ sl@0: { sl@0: if (iMessage == NULL) sl@0: { sl@0: memcpy(((TUint8*)iMemPtr + aOffset), aBuf, (TInt)aLength); sl@0: // Always return success sl@0: return KErrNone; sl@0: } sl@0: else if ((iMessage == NULL) || (iMessage->Handle() == KLocalMessageHandle)) sl@0: { sl@0: TUint8* ptr = (TUint8*) ((TDes8*) iMemPtr)->Ptr(); sl@0: memcpy(ptr + iBaseOffset + aOffset, aBuf, (TInt)aLength); sl@0: return KErrNone; sl@0: } sl@0: else sl@0: { sl@0: #if defined(__SYMBIAN32__) sl@0: // Create EPOC memory representation sl@0: TPtrC8 mem((TUint8*)aBuf,aLength); sl@0: sl@0: // Use message to write back to client thread sl@0: TRAPD( res,iMessage->WriteL(0,mem, iBaseOffset + aOffset) ); sl@0: sl@0: // Return error code sl@0: return (TInt)res; sl@0: #else sl@0: LFFS_ASSERT(0); sl@0: return E_GENERAL; sl@0: #endif sl@0: } sl@0: } sl@0: sl@0: sl@0: