|
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 * Definition of the Swi::Sis::CData |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 @internalComponent |
|
23 */ |
|
24 #include "sisdata.h" |
|
25 #include "sisdataunit.h" |
|
26 |
|
27 namespace Swi |
|
28 { |
|
29 namespace Sis |
|
30 { |
|
31 |
|
32 /*static*/ CData* CData::NewLC(MSisDataProvider& aDataProvider, TInt64& aBytesRead, TReadTypeBehaviour aTypeReadBehaviour) |
|
33 { |
|
34 CData* self = new(ELeave) CData(aDataProvider); |
|
35 CleanupStack::PushL(self); |
|
36 self->ConstructL(aBytesRead, aTypeReadBehaviour); |
|
37 return self; |
|
38 } |
|
39 |
|
40 /*static*/ CData* CData::NewL(MSisDataProvider& aDataProvider, TInt64& aBytesRead, TReadTypeBehaviour aTypeReadBehaviour) |
|
41 { |
|
42 CData* self = NewLC(aDataProvider, aBytesRead, aTypeReadBehaviour); |
|
43 CleanupStack::Pop(self); |
|
44 return self; |
|
45 } |
|
46 |
|
47 CData::CData(MSisDataProvider& aDataProvider) : iDataProvider(aDataProvider) |
|
48 { |
|
49 } |
|
50 |
|
51 CData::~CData() |
|
52 { |
|
53 iDataUnits.ResetAndDestroy(); |
|
54 } |
|
55 |
|
56 void CData::ConstructL(TInt64& aBytesRead, TReadTypeBehaviour aTypeReadBehaviour) |
|
57 { |
|
58 TInt64 arrayBytes = 0; |
|
59 CField::ConstructL(iDataProvider, EFieldTypeData, aBytesRead, aTypeReadBehaviour); |
|
60 |
|
61 // Remember the offset where the data begins |
|
62 User::LeaveIfError(iDataProvider.Seek(ESeekCurrent, iOffset)); |
|
63 ReadMemberArrayL(iDataProvider, iDataUnits, EFieldTypeDataUnit, arrayBytes, EReadType); |
|
64 |
|
65 // Calculate CRC of header and field data by reading the entire header and field |
|
66 TInt64 fieldOffset = iOffset - HeaderSize(); |
|
67 User::LeaveIfError(iDataProvider.Seek(ESeekStart, fieldOffset)); |
|
68 CField::CalculateCrcL(iDataProvider, HeaderSize() + Length() + PaddingSize(), iCrc ); |
|
69 aBytesRead += Length() + PaddingSize(); |
|
70 } |
|
71 |
|
72 void CData::ReadDataL(RFile& aFile, TInt aFileIndex, TInt aDataUnit) |
|
73 { |
|
74 if ((aFileIndex < 0) || ((aDataUnit < 0) || (aDataUnit >= iDataUnits.Count()))) |
|
75 { |
|
76 User::Leave(KErrCorrupt); |
|
77 } |
|
78 iDataUnits[aDataUnit]->ExtractDataFileL(aFile, aFileIndex); |
|
79 } |
|
80 |
|
81 void CData::ReadDataL(RFile& aFile, TInt aFileIndex, TInt aDataUnit, TInt64 aLength) |
|
82 { |
|
83 if ((aFileIndex < 0) || ((aDataUnit < 0) || (aDataUnit >= iDataUnits.Count()))) |
|
84 { |
|
85 User::Leave(KErrCorrupt); |
|
86 } |
|
87 iDataUnits[aDataUnit]->ExtractDataFileL(aFile, aFileIndex, aLength); |
|
88 } |
|
89 |
|
90 void CData::AppendStubDataFieldL(RWriteStream& aWriteStream) |
|
91 { |
|
92 // The data field has the following structure |
|
93 |
|
94 // Object Object Size (bytes) Value |
|
95 // FieldType 4 EFieldTypeData |
|
96 // FieldLength 4 12 |
|
97 // data 12 The empty Data unit array |
|
98 |
|
99 // The empty data unit array inside the Data field has the following structure |
|
100 |
|
101 // Object Object Size (bytes) Value |
|
102 // FieldType 4 EFieldTypeArray |
|
103 // FieldLength 4 4 |
|
104 // ArrayType 4 EFieldTypeDataUnit |
|
105 |
|
106 |
|
107 // append the EFieldTypeData header to the stream |
|
108 TBuf8<3 * sizeof(TInt32)> header; |
|
109 CField::CreateHeader(EFieldTypeData, TInt64(12), header); |
|
110 aWriteStream.WriteL(header); |
|
111 |
|
112 // append an empty array header to the stream |
|
113 CField::CreateHeader(EFieldTypeArray, TInt64(4), header); |
|
114 aWriteStream.WriteL(header); |
|
115 |
|
116 // append the array type to the stream |
|
117 TInt32 arrayType; |
|
118 TPckg<TInt32> pckg(arrayType); |
|
119 arrayType = static_cast<TInt32>(EFieldTypeDataUnit); |
|
120 aWriteStream.WriteL(pckg); |
|
121 } |
|
122 |
|
123 |
|
124 } //namespace Sis |
|
125 |
|
126 } //namespace Swi |
|
127 |
|
128 |