|
1 // Copyright (c) 2008-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 // e32\kernel\scmvariantdata.cpp |
|
15 // Core dump server - Variant Data for System Crash |
|
16 // |
|
17 // |
|
18 |
|
19 #include <scmdatatypes.h> |
|
20 |
|
21 namespace Debug |
|
22 { |
|
23 /** |
|
24 * TVariantSpecificData implementation |
|
25 * @internal technology |
|
26 */ |
|
27 |
|
28 /** |
|
29 * TVariantSpecificData constructor |
|
30 */ |
|
31 TVariantSpecificData::TVariantSpecificData() : |
|
32 iId(ESCMVariantData) |
|
33 ,iVersion(EVariantSpecificDataVersion1) |
|
34 ,iSize(0) |
|
35 { |
|
36 } |
|
37 |
|
38 /** |
|
39 * Writes this classes data to the specified byte stream |
|
40 * @param aWriter byte stream to use |
|
41 * @return void |
|
42 */ |
|
43 TInt TVariantSpecificData::Serialize(TByteStreamWriter& aWriter) |
|
44 { |
|
45 TInt startPos = aWriter.CurrentPosition(); |
|
46 |
|
47 if(iId != ESCMVariantData) |
|
48 { |
|
49 CLTRACE("TVariantSpecificData::Serialize Corrupt ID"); |
|
50 return KErrCorrupt; |
|
51 } |
|
52 |
|
53 // ID saved first |
|
54 aWriter.WriteInt(iId); // 4 |
|
55 |
|
56 aWriter.WriteShort((TUint16) iVersion); // 2 |
|
57 |
|
58 if(iVersion == EVariantSpecificDataVersion1) |
|
59 { |
|
60 // write data v1 format |
|
61 aWriter.WriteInt(iSize); // 4 |
|
62 } |
|
63 else |
|
64 { |
|
65 CLTRACE("TVariantSpecificData::Serialize Unsupported version"); |
|
66 return KErrCorrupt; |
|
67 } |
|
68 |
|
69 TInt endPos = aWriter.CurrentPosition(); |
|
70 if( endPos - startPos != GetSize()) |
|
71 { |
|
72 // error between actual size & real size in data |
|
73 CLTRACE("TVariantSpecificData::Serialize serialization size error"); |
|
74 return KErrCorrupt; |
|
75 } |
|
76 |
|
77 return KErrNone; |
|
78 } |
|
79 |
|
80 /** |
|
81 * Reads the classes data from the specified byte stream |
|
82 * @param aReader Byte stream to use |
|
83 * @return void |
|
84 */ |
|
85 TInt TVariantSpecificData::Deserialize(TByteStreamReader& aReader) |
|
86 { |
|
87 TInt startPos = aReader.CurrentPosition(); |
|
88 |
|
89 iId = (SCMStructId)aReader.ReadInt(); // 4 |
|
90 if(iId != ESCMVariantData) |
|
91 { |
|
92 CLTRACE("TVariantSpecificData::Deserialize Corrupt ID read"); |
|
93 return KErrCorrupt; |
|
94 } |
|
95 |
|
96 iVersion = (TVariantSpecificDataVersion)aReader.ReadShort(); // 2 |
|
97 |
|
98 if(iVersion == EVariantSpecificDataVersion1) |
|
99 { |
|
100 // read data v1 format |
|
101 iSize = aReader.ReadInt(); // 4 |
|
102 } |
|
103 else |
|
104 { |
|
105 iId = ESCMLast; //unrecognised header |
|
106 CLTRACE("TVariantSpecificData::Deserialize Unsupported version"); |
|
107 return KErrCorrupt; |
|
108 } |
|
109 |
|
110 TInt endPos = aReader.CurrentPosition(); |
|
111 if( endPos - startPos != GetSize()) |
|
112 { |
|
113 iId = ESCMLast; //unrecognised header |
|
114 |
|
115 // error between actual size & real size in data |
|
116 CLTRACE("TVariantSpecificData::Deserialize serialization size error"); |
|
117 return KErrCorrupt; |
|
118 } |
|
119 return KErrNone; |
|
120 } |
|
121 |
|
122 /** |
|
123 * Returns the externalised size of this class |
|
124 * @return TInt size |
|
125 */ |
|
126 TInt TVariantSpecificData::GetSize() const |
|
127 { |
|
128 if(iVersion == EVariantSpecificDataVersion1) |
|
129 { |
|
130 return 10; |
|
131 } |
|
132 else |
|
133 { |
|
134 CLTRACE("TThreadData::GetSize Unsupported version"); |
|
135 return KErrNotSupported; |
|
136 } |
|
137 } |
|
138 |
|
139 } |