First public contribution.
1 // Copyright (c) 1997-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test\concur\cfafshmem.cpp
15 // Definition of the THMem class member functions.
19 #include "cfafshmem.h"
22 THMem::THMem(void * aNewMemPtr) : iMemPtr(aNewMemPtr),
24 //threadHandle(NO_THREAD),
25 iBaseOffset(KNoOffset)
27 * Constructor. Initialises the members of THMem.
29 * @param aNewMemPtr Pointer to the memory that this THMem will
39 THMem::THMem(const void * aNewMemPtr,const RMessagePtr2& aMessage,int aNewOffset)
40 : iMemPtr((void*)aNewMemPtr), iBaseOffset(aNewOffset)
42 * Constructor. Initialises the members of THMem.
44 * @param aNewMemPtr Pointer to the memory that this THMem will
52 iMessage=(RMessagePtr2*)&aMessage;
57 TInt THMem::Read(void *aBuf, TUint32 aLength, TUint aOffset) const
59 * Reads a chunk of memory from the THMem.
61 * @param aBuf goal buffer bointer
62 * @param aLength how many bytes that will be read from
64 * @param aOffset offset into the THMem where the function
66 * @return Error code - KErrNone on success
72 memcpy(aBuf, ((TUint8*)iMemPtr + aOffset), (TInt)aLength);
73 // Always return success
76 else if ((iMessage == NULL) || (iMessage->Handle() == KLocalMessageHandle))
78 TUint8* ptr = (TUint8*) ((TDes8*) iMemPtr)->Ptr();
79 memcpy(aBuf, ptr + iBaseOffset + aOffset, (TInt)aLength);
80 // Always return success
85 #if defined(__SYMBIAN32__)
86 // Create EPOC memory representation
87 TPtr8 mem((TUint8*)aBuf,aLength);
89 // Create EPOC memory representation
90 TRAPD(res,iMessage->ReadL(0,mem, iBaseOffset + aOffset));
103 TInt THMem::Write(const void *aBuf, TUint32 aLength, TUint32 aOffset)
105 * Writes a chunk of memory to the THMem.
107 * @param aBuf source buffer bointer
108 * @param aLength how many bytes that will be written to
110 * @param aOffset offset into the THMem where the function
112 * @return Error code - KErrNone on success
116 if (iMessage == NULL)
118 memcpy(((TUint8*)iMemPtr + aOffset), aBuf, (TInt)aLength);
119 // Always return success
122 else if ((iMessage == NULL) || (iMessage->Handle() == KLocalMessageHandle))
124 TUint8* ptr = (TUint8*) ((TDes8*) iMemPtr)->Ptr();
125 memcpy(ptr + iBaseOffset + aOffset, aBuf, (TInt)aLength);
130 #if defined(__SYMBIAN32__)
131 // Create EPOC memory representation
132 TPtrC8 mem((TUint8*)aBuf,aLength);
134 // Use message to write back to client thread
135 TRAPD( res,iMessage->WriteL(0,mem, iBaseOffset + aOffset) );