51
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "MemSpyDriverStreamWriter.h"
|
|
19 |
|
|
20 |
// User includes
|
|
21 |
#include "MemSpyDriverUtils.h"
|
|
22 |
#include "MemSpyDriverXferBuffer.h"
|
|
23 |
|
54
|
24 |
#if defined(__GCC32__)
|
|
25 |
#define __RETURN_ADDRESS() __builtin_return_address(0)
|
|
26 |
#elif defined (__ARMCC__)
|
|
27 |
#define __RETURN_ADDRESS() ((TAny*)__return_address())
|
|
28 |
#else
|
|
29 |
#define __RETURN_ADDRESS() 0 // not supported
|
|
30 |
#endif
|
51
|
31 |
|
|
32 |
|
|
33 |
RMemSpyMemStreamWriter::RMemSpyMemStreamWriter()
|
|
34 |
: iBuffer( NULL ), iCurrent( NULL ), iMax( 0 ), iMark( NULL ), iCommitted( 0 )
|
|
35 |
{
|
|
36 |
}
|
|
37 |
|
|
38 |
|
|
39 |
RMemSpyMemStreamWriter::RMemSpyMemStreamWriter( DMemSpyDriverXferBuffer& aBuffer )
|
|
40 |
: iBuffer( &aBuffer ), iMark( NULL ), iCommitted( 0 )
|
|
41 |
{
|
|
42 |
iCurrent = iBuffer->Ptr();
|
|
43 |
iMax = iCurrent + iBuffer->Size();
|
|
44 |
TRACE( Kern::Printf("RMemSpyMemStreamWriter::RMemSpyMemStreamWriter() - current: 0x%08x, max: 0x%08x, size: %d", iCurrent, iMax, iBuffer->Size() ) );
|
|
45 |
}
|
|
46 |
|
|
47 |
|
|
48 |
void RMemSpyMemStreamWriter::Close()
|
|
49 |
{
|
|
50 |
iBuffer = NULL;
|
|
51 |
iMark = NULL;
|
|
52 |
}
|
|
53 |
|
|
54 |
|
|
55 |
TInt RMemSpyMemStreamWriter::WriteAndClose( TDes8* aDestinationPointer )
|
|
56 |
{
|
|
57 |
__ASSERT_ALWAYS( IsOpen(), MemSpyDriverUtils::Fault( __LINE__ ) );
|
|
58 |
//
|
|
59 |
const TInt ret = iBuffer->WriteToClient( aDestinationPointer, iCommitted );
|
|
60 |
Close();
|
|
61 |
//
|
|
62 |
return ret;
|
|
63 |
}
|
|
64 |
|
|
65 |
|
|
66 |
TInt32* RMemSpyMemStreamWriter::WriteInt32( TInt32 aValue )
|
|
67 |
{
|
|
68 |
TInt32* ret = NULL;
|
|
69 |
//
|
|
70 |
__ASSERT_ALWAYS( IsOpen(), MemSpyDriverUtils::Fault( __LINE__ ) );
|
|
71 |
if ( !IsFull() )
|
|
72 |
{
|
|
73 |
ret = (TInt32*) iCurrent;
|
|
74 |
*ret = aValue;
|
|
75 |
IncrementPos( sizeof( TInt32 ) );
|
|
76 |
}
|
|
77 |
else
|
|
78 |
{
|
54
|
79 |
TRACE( Kern::Printf( "RMemSpyMemStreamWriter::WriteInt32() - asked to write: 0x%08x from fn: 0x%08x BUT AM FULL", aValue, __RETURN_ADDRESS() ) );
|
51
|
80 |
}
|
|
81 |
//
|
|
82 |
return ret;
|
|
83 |
}
|
|
84 |
|
|
85 |
|
|
86 |
TUint32* RMemSpyMemStreamWriter::WriteUint32( TUint32 aValue )
|
|
87 |
{
|
|
88 |
TUint32* ret = NULL;
|
|
89 |
//
|
|
90 |
__ASSERT_ALWAYS( IsOpen(), MemSpyDriverUtils::Fault( __LINE__ ) );
|
|
91 |
if ( !IsFull() )
|
|
92 |
{
|
|
93 |
ret = (TUint32*) iCurrent;
|
|
94 |
*ret = aValue;
|
|
95 |
IncrementPos( sizeof( TUint32 ) );
|
|
96 |
}
|
|
97 |
else
|
|
98 |
{
|
54
|
99 |
TRACE( Kern::Printf( "RMemSpyMemStreamWriter::WriteUint32() - asked to write: 0x%08x from fn: 0x%08x BUT AM FULL", aValue, __RETURN_ADDRESS() ) );
|
51
|
100 |
}
|
|
101 |
//
|
|
102 |
return ret;
|
|
103 |
}
|
|
104 |
|
|
105 |
|
|
106 |
TUint8* RMemSpyMemStreamWriter::Current() const
|
|
107 |
{
|
|
108 |
__ASSERT_ALWAYS( IsOpen(), MemSpyDriverUtils::Fault( __LINE__ ) );
|
|
109 |
return iCurrent;
|
|
110 |
}
|
|
111 |
|
|
112 |
|
|
113 |
void RMemSpyMemStreamWriter::Seek( TInt aPosition )
|
|
114 |
{
|
|
115 |
__ASSERT_ALWAYS( IsOpen(), MemSpyDriverUtils::Fault( __LINE__ ) );
|
|
116 |
TUint8* pos = iBuffer->Ptr() + aPosition;
|
|
117 |
__ASSERT_ALWAYS( pos < iMax, MemSpyDriverUtils::Fault( __LINE__ ) );
|
|
118 |
iCurrent = pos;
|
|
119 |
}
|
|
120 |
|
|
121 |
|
|
122 |
TUint32 RMemSpyMemStreamWriter::Remaining() const
|
|
123 |
{
|
|
124 |
__ASSERT_ALWAYS( IsOpen(), MemSpyDriverUtils::Fault( __LINE__ ) );
|
|
125 |
const TUint32 max = reinterpret_cast< TUint32 >( iMax );
|
|
126 |
const TUint32 cur = reinterpret_cast< TUint32 >( iCurrent );
|
|
127 |
TRACE( Kern::Printf("RMemSpyMemStreamWriter::Remaining() - current: 0x%08x, max: 0x%08x, ret: %d", cur, max, ( max - cur ) ) );
|
|
128 |
return ( max - cur );
|
|
129 |
}
|
|
130 |
|
|
131 |
|
|
132 |
void RMemSpyMemStreamWriter::MarkSet()
|
|
133 |
{
|
|
134 |
__ASSERT_ALWAYS( iMark == NULL, MemSpyDriverUtils::Fault( __LINE__ ) );
|
|
135 |
iMark = iCurrent;
|
|
136 |
}
|
|
137 |
|
|
138 |
|
|
139 |
void RMemSpyMemStreamWriter::MarkResume()
|
|
140 |
{
|
|
141 |
__ASSERT_ALWAYS( iMark != NULL, MemSpyDriverUtils::Fault( __LINE__ ) );
|
|
142 |
iCurrent = iMark;
|
|
143 |
iMark = NULL;
|
|
144 |
}
|
|
145 |
|
|
146 |
|
|
147 |
TBool RMemSpyMemStreamWriter::IsFull() const
|
|
148 |
{
|
|
149 |
__ASSERT_ALWAYS( IsOpen(), MemSpyDriverUtils::Fault( __LINE__ ) );
|
|
150 |
const TBool ret = ( iCurrent >= iMax );
|
|
151 |
return ret;
|
|
152 |
}
|
|
153 |
|
|
154 |
|
|
155 |
TBool RMemSpyMemStreamWriter::IsOpen() const
|
|
156 |
{
|
|
157 |
const TBool ret = ( iBuffer && iCurrent && iMax );
|
|
158 |
return ret;
|
|
159 |
}
|
|
160 |
|
|
161 |
|
|
162 |
RMemSpyMemStreamWriter& RMemSpyMemStreamWriter::operator=( const RMemSpyMemStreamWriter& aCopy )
|
|
163 |
{
|
|
164 |
iBuffer = aCopy.iBuffer;
|
|
165 |
iMark = aCopy.iMark;
|
|
166 |
iCommitted = aCopy.iCommitted;
|
|
167 |
iCurrent = aCopy.iCurrent;
|
|
168 |
iMax = aCopy.iMax;
|
|
169 |
//
|
|
170 |
return *this;
|
|
171 |
}
|
|
172 |
|
|
173 |
|
|
174 |
void RMemSpyMemStreamWriter::IncrementPos( TInt aAmount )
|
|
175 |
{
|
|
176 |
__ASSERT_ALWAYS( IsOpen(), MemSpyDriverUtils::Fault( __LINE__ ) );
|
|
177 |
if ( iCurrent + aAmount > iMax )
|
|
178 |
{
|
|
179 |
Kern::Printf("RMemSpyMemStreamWriter::IncrementPos() - OVERFLOW - current: 0x%08x, max: 0x%08x, aAmount: %d", iCurrent, iMax, aAmount );
|
|
180 |
}
|
|
181 |
|
|
182 |
iCurrent += aAmount;
|
|
183 |
iCommitted += aAmount;
|
|
184 |
}
|
|
185 |
|
|
186 |
|
|
187 |
|