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