|
1 /* |
|
2 * Copyright (c) 2004-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 the License "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 * Note: This file may contain code to generate corrupt files for test purposes. |
|
16 * Such code is excluded from production builds by use of compiler defines; |
|
17 * it is recommended that such code should be removed if this code is ever published publicly. |
|
18 * manages type and length for SIS structures |
|
19 * |
|
20 */ |
|
21 |
|
22 |
|
23 /** |
|
24 @file |
|
25 @internalComponent |
|
26 @released |
|
27 */ |
|
28 |
|
29 #ifndef __HEADER_H__ |
|
30 #define __HEADER_H__ |
|
31 |
|
32 |
|
33 #include <assert.h> |
|
34 |
|
35 #include "fieldroot.h" |
|
36 #include "numeric.h" |
|
37 |
|
38 |
|
39 class CSISHeader : public CSISFieldRoot |
|
40 |
|
41 { |
|
42 private: |
|
43 void BigToSmalls (CSISUInt32& aSmall, CSISUInt32& aBig) const; |
|
44 static void RawBigToSmalls (const TUint64& aSize, CSISUInt32& aSmall, CSISUInt32& aBig); |
|
45 |
|
46 protected: |
|
47 bool IsBigHeader () const; |
|
48 |
|
49 public: |
|
50 CSISHeader (); |
|
51 CSISHeader (const TFieldType aType); |
|
52 CSISHeader (const TFieldType aType, const TFieldSize aSize); |
|
53 |
|
54 public: |
|
55 /** |
|
56 * Internalize the class |
|
57 * @param aFile File stream from where data needs to be read. |
|
58 * @param aContainerSize size of the content to be read. |
|
59 * @param aArrayType Type of the array |
|
60 */ |
|
61 virtual void Read (TSISStream& aFile, const TFieldSize& aContainerSize, const CSISFieldRoot::TFieldType aArrayType = CSISFieldRoot::ESISUndefined); |
|
62 /** |
|
63 * Skip the file reading for this field. Read pointer will be moved to the |
|
64 * next field to be read. |
|
65 * @param aFile stream for which the data read should be skipped. |
|
66 * @param aContainerSize size of the data to be skipped. |
|
67 */ |
|
68 virtual void Skip (TSISStream& aFile, const TFieldSize& aContainerSize) const; |
|
69 /** |
|
70 * Externalize the class |
|
71 * @param aFile File stream to which the data needs to be written. |
|
72 * @param aIsArrayElement whether the structure is part of an array or not. |
|
73 */ |
|
74 virtual void Write (TSISStream& aFile, const bool aIsArrayElement) const; |
|
75 /** |
|
76 * Retrieves the size of the structure excluding the header. |
|
77 * @param aInsideArray - whether the structure is part of an array or not. |
|
78 * @return byte count. |
|
79 */ |
|
80 virtual TFieldSize ByteCount (const bool aInsideArray) const; |
|
81 /** |
|
82 * Dump the entire content in hex format into the stream |
|
83 */ |
|
84 virtual void Dump (std::ostream& aStream, const int aLevel) const; |
|
85 /** |
|
86 * Calculates CRC of the content |
|
87 * @param aCRC CRC value of the content |
|
88 * @param aIsArrayElement whether the structure is part of an array or not. |
|
89 */ |
|
90 virtual void CalculateCrc (TCRC& aCRC, const bool aIsArrayElement) const; |
|
91 |
|
92 /** |
|
93 * It checks the field type and returns whether the field type is a |
|
94 * known type or not. |
|
95 */ |
|
96 bool IsKnownType () const; |
|
97 /** |
|
98 * @return Data field type |
|
99 */ |
|
100 CSISFieldRoot::TFieldType DataType () const; |
|
101 /** |
|
102 * @param data type |
|
103 */ |
|
104 CSISFieldRoot::TFieldSize DataSize () const; |
|
105 /** |
|
106 * Reads the header and skips the data from the stream |
|
107 * @param aSize size of the field is returned in this variable |
|
108 * @param aFile File stream. |
|
109 * @param aContainerSize size of the content. |
|
110 * @param aArrayType Type of the array |
|
111 */ |
|
112 static TUint32 RawRead (TUint64& aSize, |
|
113 TSISStream& aFile, |
|
114 const TFieldSize& aContainerSize, |
|
115 const CSISFieldRoot::TFieldType aArrayType = CSISFieldRoot::ESISUndefined); |
|
116 /** |
|
117 * writes the header into the stream |
|
118 * @param aType field type. |
|
119 * @param aSize size of the field. |
|
120 * @param aFile File stream to which the data needs to be written. |
|
121 * @param aIsArrayElement whether the structure is part of an array or not. |
|
122 */ |
|
123 static void RawWrite (const TUint32 aType, const TUint64& aSize, TSISStream& aFile, const bool aIsArrayElement); |
|
124 /** |
|
125 * @return Number of bytes required to store the length of the field |
|
126 */ |
|
127 static TFieldSize RawByteCount (const TUint64& aSize, const bool aInsideArray); |
|
128 /** |
|
129 * Calculates CRC of the header |
|
130 * @param aType field type. |
|
131 * @param aSize size of the field. |
|
132 * @param aCRC CRC value |
|
133 * @param aIsArrayElement whether the structure is part of an array or not. |
|
134 */ |
|
135 static void RawCalculateCrc (const TUint32 aType, const TUint64& aSize, TCRC& aCRC, const bool aIsArrayElement); |
|
136 /** |
|
137 * Checks whether the field length is big number (requires 8 bytes) or not (4 bytes) |
|
138 */ |
|
139 static bool IsBigHeader (const TUint64& aSize); |
|
140 |
|
141 /** |
|
142 * Checks whether the next type is an expected type or not. |
|
143 */ |
|
144 static bool IsNextAsExpected ( TSISStream& aFile, CSISHeader& aHeader, |
|
145 const CSISFieldRoot::TFieldType aExpectedType, |
|
146 const CSISFieldRoot::TFieldType aArrayType, |
|
147 const bool aPeek); |
|
148 |
|
149 private: |
|
150 CSISFieldRoot::TFieldType iDataType; |
|
151 CSISFieldRoot::TFieldSize iDataSize; |
|
152 |
|
153 }; |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 inline CSISHeader::CSISHeader () : |
|
159 iDataType (CSISFieldRoot::ESISUndefined), |
|
160 iDataSize (0) |
|
161 { |
|
162 } |
|
163 |
|
164 |
|
165 inline CSISHeader::CSISHeader (const TFieldType aType) : |
|
166 iDataType (aType), |
|
167 iDataSize (0) |
|
168 { |
|
169 } |
|
170 |
|
171 |
|
172 inline CSISHeader::CSISHeader (const TFieldType aType, const TFieldSize aSize) : |
|
173 iDataType (aType), |
|
174 iDataSize (aSize) |
|
175 { |
|
176 } |
|
177 |
|
178 |
|
179 inline bool CSISHeader::IsKnownType () const |
|
180 { |
|
181 return (iDataType > CSISFieldRoot::ESISUndefined) && |
|
182 (iDataType < CSISFieldRoot::ESISUnknown); |
|
183 } |
|
184 |
|
185 |
|
186 inline CSISFieldRoot::TFieldType CSISHeader::DataType () const |
|
187 { |
|
188 return iDataType; |
|
189 } |
|
190 |
|
191 |
|
192 inline CSISFieldRoot::TFieldSize CSISHeader::DataSize () const |
|
193 { |
|
194 return iDataSize; |
|
195 } |
|
196 |
|
197 inline void CSISHeader::Skip (TSISStream& aFile, const TFieldSize& aContainerSize) const |
|
198 { |
|
199 assert (false); // if you skip the header, you skip the data which tells you how much to skip |
|
200 } |
|
201 |
|
202 #endif // __HEADER_H__ |