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 "MemSpyDriverStreamReaderImp.h" |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 CMemSpyMemStreamReader::CMemSpyMemStreamReader( const TDesC8& aData ) |
|
24 { |
|
25 iCurrent = aData.Ptr(); |
|
26 iMax = iCurrent + aData.Length(); |
|
27 } |
|
28 |
|
29 |
|
30 void CMemSpyMemStreamReader::ConstructL() |
|
31 { |
|
32 } |
|
33 |
|
34 |
|
35 TInt32 CMemSpyMemStreamReader::ReadInt32L() |
|
36 { |
|
37 TInt32 ret = 0; |
|
38 // |
|
39 const TInt size = sizeof( TInt32 ); |
|
40 IsAvailableL( size ); |
|
41 Mem::Copy( (TAny*) &ret, iCurrent, size ); |
|
42 IncrementPos( size ); |
|
43 // |
|
44 return ret; |
|
45 } |
|
46 |
|
47 |
|
48 TUint32 CMemSpyMemStreamReader::ReadUint32L() |
|
49 { |
|
50 TUint32 ret = 0; |
|
51 // |
|
52 const TInt size = sizeof( TUint32 ); |
|
53 IsAvailableL( size ); |
|
54 Mem::Copy( (TAny*) &ret, iCurrent, size ); |
|
55 IncrementPos( size ); |
|
56 // |
|
57 return ret; |
|
58 } |
|
59 |
|
60 |
|
61 void CMemSpyMemStreamReader::ReadL( TDes8& aDes ) |
|
62 { |
|
63 const TInt length = ReadInt32L(); |
|
64 |
|
65 // Need to check the remaining text is actually present... |
|
66 IsAvailableL( length ); |
|
67 |
|
68 // Now read into client descriptor |
|
69 aDes.SetLength( length ); |
|
70 if ( length > 0 ) |
|
71 { |
|
72 TUint8* dest = const_cast< TUint8* >( aDes.Ptr() ); |
|
73 Mem::Copy( dest, iCurrent, length ); |
|
74 } |
|
75 // |
|
76 IncrementPos( length ); |
|
77 } |
|
78 |
|
79 |
|
80 void CMemSpyMemStreamReader::ReadL( TDes16& aDes ) |
|
81 { |
|
82 // The kernel driver only ever writes narrow descriptors. |
|
83 // However, we can expand them to be UCS2 |
|
84 const TInt length = ReadInt32L(); |
|
85 |
|
86 // Need to check the remaining text is actually present... |
|
87 IsAvailableL( length ); |
|
88 |
|
89 // Set final length in descriptor |
|
90 aDes.SetLength( length ); |
|
91 |
|
92 // Read each char |
|
93 TUint16* dest = const_cast< TUint16* >( aDes.Ptr() ); |
|
94 for( TInt i=0; i<length; i++ ) |
|
95 { |
|
96 *dest++ = *iCurrent++; |
|
97 } |
|
98 } |
|
99 |
|
100 |
|
101 void CMemSpyMemStreamReader::IsAvailableL( TInt aRequired ) const |
|
102 { |
|
103 const TUint8* endPos = iCurrent + aRequired; |
|
104 if ( endPos > iMax ) |
|
105 { |
|
106 User::Leave( KErrOverflow ); |
|
107 } |
|
108 } |
|
109 |
|
110 |
|
111 void CMemSpyMemStreamReader::IncrementPos( TInt aAmount ) |
|
112 { |
|
113 iCurrent += aAmount; |
|
114 } |
|
115 |
|
116 |
|
117 |
|
118 |
|