1 /* |
|
2 * Copyright (c) 2005 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: CMMCScBkupIndexDataOwners implementation |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 #include "CMMCScBkupIndexDataOwners.h" |
|
20 |
|
21 // User includes |
|
22 #include "MMMCScBkupArchiveDataInterface.h" |
|
23 |
|
24 // Constants |
|
25 const TInt KMMCScBkupDataOwnerIndexGranularity = 50; |
|
26 |
|
27 |
|
28 /** |
|
29 * Registration Data |
|
30 * ================= |
|
31 * |
|
32 * This is the format of the data written by the |
|
33 * CMMCScBkupStateGetDataOwners object |
|
34 * |
|
35 * |
|
36 * REG DATA for DO 0 |
|
37 * { |
|
38 * RD for DO 0, 1st drive |
|
39 * RD for DO 0, 2nd drive |
|
40 * RD for DO 0, 'n'th drive |
|
41 * }, |
|
42 * REG DATA for DO 1 |
|
43 * { |
|
44 * RD for DO 0, 1st drive |
|
45 * RD for DO 0, 2nd drive |
|
46 * RD for DO 0, 'n'th drive |
|
47 * }, |
|
48 * REG DATA for DO n |
|
49 * { |
|
50 * RD for DO 0, 1st drive |
|
51 * RD for DO 0, 2nd drive |
|
52 * RD for DO 0, 'n'th drive |
|
53 * } |
|
54 * |
|
55 * Registration Data Index |
|
56 * ======================= |
|
57 * |
|
58 * This is the format of the data written by this method. |
|
59 * The format allows the possibility of a future partial |
|
60 * restore (hopefully). |
|
61 * |
|
62 * |
|
63 * 4 bytes = count of data owners |
|
64 * |
|
65 * FOR EACH DATA OWNER |
|
66 * { |
|
67 * 4 bytes = secure id of data owner's process |
|
68 * 4 bytes = the number of different registration data files |
|
69 * for this particular data owner (one for each drive that |
|
70 * was backed up) |
|
71 * ENTRY |
|
72 * { |
|
73 * 1 byte = Associated TDriveNumber of the registration data |
|
74 * n bytes = raw drive data |
|
75 * } |
|
76 * } |
|
77 * |
|
78 * |
|
79 **/ |
|
80 |
|
81 |
|
82 |
|
83 // ========================= MEMBER FUNCTIONS ================================ |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // CMMCScBkupIndexDataOwners::CMMCScBkupIndexDataOwners() |
|
87 // |
|
88 // C++ constructor. |
|
89 // --------------------------------------------------------------------------- |
|
90 CMMCScBkupIndexDataOwners::CMMCScBkupIndexDataOwners() |
|
91 : CMMCScBkupIndexBase( EMMCScBkupOwnerDataTypeDataOwner ), iEntries( KMMCScBkupDataOwnerIndexGranularity ) |
|
92 { |
|
93 } |
|
94 |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 // CMMCScBkupIndexDataOwners::~CMMCScBkupIndexDataOwners() |
|
98 // |
|
99 // Destructor. |
|
100 // --------------------------------------------------------------------------- |
|
101 CMMCScBkupIndexDataOwners::~CMMCScBkupIndexDataOwners() |
|
102 { |
|
103 iEntries.Close(); |
|
104 } |
|
105 |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // CMMCScBkupIndexDataOwners::NewLC() |
|
109 // |
|
110 // |
|
111 // --------------------------------------------------------------------------- |
|
112 CMMCScBkupIndexDataOwners* CMMCScBkupIndexDataOwners::NewLC() |
|
113 { |
|
114 CMMCScBkupIndexDataOwners* self = new(ELeave) CMMCScBkupIndexDataOwners(); |
|
115 CleanupStack::PushL(self); |
|
116 return self; |
|
117 } |
|
118 |
|
119 |
|
120 // --------------------------------------------------------------------------- |
|
121 // CMMCScBkupIndexDataOwners::AddIndexRecordL() |
|
122 // |
|
123 // |
|
124 // --------------------------------------------------------------------------- |
|
125 void CMMCScBkupIndexDataOwners::AddIndexRecordL( const TMMCScBkupArchiveVector& aInfo ) |
|
126 { |
|
127 iEntries.AppendL( aInfo ); |
|
128 } |
|
129 |
|
130 |
|
131 // --------------------------------------------------------------------------- |
|
132 // CMMCScBkupIndexDataOwners::StoreL() |
|
133 // |
|
134 // |
|
135 // --------------------------------------------------------------------------- |
|
136 void CMMCScBkupIndexDataOwners::StoreL(MMMCScBkupDriver& aDriver) |
|
137 { |
|
138 MMMCScBkupArchiveDataInterface& archiveDataInterface = aDriver.DrvADI(); |
|
139 RWriteStream& stream = archiveDataInterface.ADIWriteStreamUncompressedLC(); |
|
140 // |
|
141 stream.WriteInt32L( EStreamFormatVersion1 ); |
|
142 stream.WriteInt32L( 0 ); // spare1 |
|
143 stream.WriteInt32L( 0 ); // spare2 |
|
144 stream.WriteInt32L( 0 ); // spare3 |
|
145 // |
|
146 const TInt count = iEntries.Count(); |
|
147 stream.WriteInt32L(count); |
|
148 // |
|
149 for(TInt i=0; i<count; i++) |
|
150 { |
|
151 const TMMCScBkupArchiveVector& entry = iEntries[i]; |
|
152 stream << entry; |
|
153 // |
|
154 stream.WriteInt32L( 0 ); // spare1 |
|
155 stream.WriteInt32L( 0 ); // spare2 |
|
156 } |
|
157 // |
|
158 stream.CommitL(); |
|
159 CleanupStack::PopAndDestroy(); // stream |
|
160 |
|
161 // Update our base class info with the offset to the index |
|
162 const TMMCScBkupArchiveVector& writeInfo = archiveDataInterface.ADICurrentArchiveVectorInfo(); |
|
163 SetVector( writeInfo ); |
|
164 } |
|
165 |
|
166 |
|
167 // --------------------------------------------------------------------------- |
|
168 // CMMCScBkupIndexDataOwners::RestoreL() |
|
169 // |
|
170 // |
|
171 // --------------------------------------------------------------------------- |
|
172 void CMMCScBkupIndexDataOwners::RestoreL(MMMCScBkupDriver& aDriver) |
|
173 { |
|
174 MMMCScBkupArchiveDataInterface& archiveDataInterface = aDriver.DrvADI(); |
|
175 RReadStream& stream = archiveDataInterface.ADIReadStreamUncompressedLC( Vector().Offset() ); |
|
176 // |
|
177 stream.ReadInt32L(); // EStreamFormatVersion1 |
|
178 stream.ReadInt32L(); // spare1 |
|
179 stream.ReadInt32L(); // spare2 |
|
180 stream.ReadInt32L(); // spare3 |
|
181 // |
|
182 const TInt count = stream.ReadInt32L(); |
|
183 // |
|
184 for(TInt i=0; i<count; i++) |
|
185 { |
|
186 TMMCScBkupArchiveVector entry; |
|
187 stream >> entry; |
|
188 // |
|
189 stream.ReadInt32L(); // spare1 |
|
190 stream.ReadInt32L(); // spare2 |
|
191 // |
|
192 iEntries.AppendL( entry ); |
|
193 } |
|
194 // |
|
195 CleanupStack::PopAndDestroy(); // stream |
|
196 // |
|
197 const TMMCScBkupArchiveVector& readInfo = archiveDataInterface.ADICurrentArchiveVectorInfo(); |
|
198 if ( readInfo.Length() > Vector().Length() ) |
|
199 { |
|
200 // We've read too much! |
|
201 User::Leave( KErrCorrupt ); |
|
202 } |
|
203 } |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|