kerneltest/f32test/concur/cfafshmem.cpp
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // f32test\concur\cfafshmem.cpp
       
    15 // Definition of the THMem class member functions.
       
    16 // 
       
    17 //
       
    18 
       
    19 #include "cfafshmem.h"
       
    20 
       
    21 
       
    22 THMem::THMem(void * aNewMemPtr) :	iMemPtr(aNewMemPtr), 
       
    23 	//iNoMess(ETrue),
       
    24 	//threadHandle(NO_THREAD), 
       
    25 	iBaseOffset(KNoOffset)
       
    26 /**
       
    27  *  Constructor. Initialises the members of THMem.
       
    28  *
       
    29  *  @param aNewMemPtr  Pointer to the memory that this THMem will
       
    30  *                     represent
       
    31  *  @internalComponent
       
    32  */
       
    33  
       
    34 	{ 
       
    35 	iMessage=NULL;
       
    36 	}
       
    37 
       
    38 
       
    39 THMem::THMem(const void * aNewMemPtr,const RMessagePtr2& aMessage,int aNewOffset) 
       
    40 	: iMemPtr((void*)aNewMemPtr), iBaseOffset(aNewOffset)
       
    41 /**
       
    42  *  Constructor. Initialises the members of THMem.
       
    43  *
       
    44  *  @param aNewMemPtr  Pointer to the memory that this THMem will
       
    45  *                     represent
       
    46  *  @param aMessage
       
    47  *  @param aNewOffset
       
    48  *  @internalComponent
       
    49  */
       
    50  
       
    51 	{ 
       
    52 	iMessage=(RMessagePtr2*)&aMessage;
       
    53 	}
       
    54 
       
    55 
       
    56 
       
    57 TInt THMem::Read(void *aBuf, TUint32 aLength, TUint aOffset) const
       
    58 /**
       
    59  *  Reads a chunk of memory from the THMem.
       
    60  *
       
    61  *  @param aBuf     goal buffer bointer
       
    62  *  @param aLength  how many bytes that will be read from
       
    63  *                  the THMem
       
    64  *  @param aOffset  offset into the THMem where the function
       
    65  *                  will start reading
       
    66  *  @return Error code              -   KErrNone on success
       
    67  *  @internalComponent
       
    68  */
       
    69 	{
       
    70 	if(iMessage==NULL)
       
    71 		{
       
    72 		memcpy(aBuf, ((TUint8*)iMemPtr + aOffset), (TInt)aLength);
       
    73 		// Always return success
       
    74 		return KErrNone;
       
    75 		}
       
    76 	else if ((iMessage == NULL) || (iMessage->Handle() == KLocalMessageHandle))
       
    77 		{
       
    78 		TUint8* ptr = (TUint8*) ((TDes8*) iMemPtr)->Ptr();
       
    79 		memcpy(aBuf, ptr + iBaseOffset + aOffset, (TInt)aLength);
       
    80 		// Always return success
       
    81 		return KErrNone;
       
    82 		}
       
    83 	else
       
    84 		{
       
    85 #if defined(__SYMBIAN32__)
       
    86 		// Create EPOC memory representation
       
    87 		TPtr8 mem((TUint8*)aBuf,aLength);
       
    88 
       
    89 		// Create EPOC memory representation
       
    90 		TRAPD(res,iMessage->ReadL(0,mem, iBaseOffset + aOffset));
       
    91 
       
    92 		// Return error code
       
    93 		return (TInt)res;
       
    94 #else
       
    95 		LFFS_ASSERT(0);
       
    96 		return E_GENERAL;
       
    97 #endif
       
    98 		}
       
    99 	}
       
   100 
       
   101 
       
   102 
       
   103 TInt THMem::Write(const void *aBuf, TUint32 aLength, TUint32 aOffset)
       
   104 /**
       
   105  *  Writes a chunk of memory to the THMem.
       
   106  *
       
   107  *  @param aBuf     source buffer bointer
       
   108  *  @param aLength  how many bytes that will be written to
       
   109  *                  the THMem
       
   110  *  @param aOffset  offset into the THMem where the function
       
   111  *                  will start writing
       
   112  *  @return Error code              -   KErrNone on success
       
   113  *  @internalComponent
       
   114  */
       
   115 	{
       
   116 	if (iMessage == NULL)
       
   117 		{
       
   118 		memcpy(((TUint8*)iMemPtr + aOffset), aBuf, (TInt)aLength);
       
   119 		// Always return success
       
   120 		return KErrNone;
       
   121 		}
       
   122 	else if ((iMessage == NULL) || (iMessage->Handle() == KLocalMessageHandle))
       
   123 		{
       
   124 		TUint8* ptr = (TUint8*) ((TDes8*) iMemPtr)->Ptr();
       
   125 		memcpy(ptr + iBaseOffset + aOffset, aBuf, (TInt)aLength);
       
   126 		return KErrNone;
       
   127 		}
       
   128 	else
       
   129 		{
       
   130 #if defined(__SYMBIAN32__)
       
   131 		// Create EPOC memory representation
       
   132 		TPtrC8 mem((TUint8*)aBuf,aLength);
       
   133 
       
   134 		// Use message to write back to client thread
       
   135 		TRAPD( res,iMessage->WriteL(0,mem, iBaseOffset + aOffset) );
       
   136 
       
   137 		// Return error code
       
   138 		return (TInt)res;
       
   139 #else
       
   140 		LFFS_ASSERT(0);
       
   141 		return E_GENERAL;
       
   142 #endif
       
   143 		}
       
   144 	}
       
   145 
       
   146 
       
   147