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: CMMCScBkupTransferRequestBase implementation |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 #include "CMMCScBkupTransferRequest.h" |
|
20 |
|
21 // User includes |
|
22 #include "MMCScBkupLogger.h" |
|
23 #include "MMMCScBkupDriver.h" |
|
24 #include "CMMCScBkupArchive.h" |
|
25 #include "CMMCScBkupDataOwnerInfo.h" |
|
26 #include "MMMCScBkupArchiveDataInterface.h" |
|
27 |
|
28 |
|
29 |
|
30 // ========================= MEMBER FUNCTIONS ================================ |
|
31 |
|
32 // --------------------------------------------------------------------------- |
|
33 // CMMCScBkupTransferRequestBase::CMMCScBkupTransferRequestBase() |
|
34 // |
|
35 // C++ constructor. |
|
36 // --------------------------------------------------------------------------- |
|
37 CMMCScBkupTransferRequestBase::CMMCScBkupTransferRequestBase( MMMCScBkupDriver& aDriver, TMMCScBkupOwnerDataType aElementType, TBool aUpdateOperationalSizes, TInt aPriority ) |
|
38 : CActive( aPriority ), iDriver( aDriver ), iElementType( aElementType ), iUpdateOperationalSizes( aUpdateOperationalSizes ) |
|
39 { |
|
40 CActiveScheduler::Add( this ); |
|
41 } |
|
42 |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // CMMCScBkupTransferRequestBase::~CMMCScBkupTransferRequestBase() |
|
46 // |
|
47 // C++ destructor. |
|
48 // --------------------------------------------------------------------------- |
|
49 CMMCScBkupTransferRequestBase::~CMMCScBkupTransferRequestBase() |
|
50 { |
|
51 Cancel(); |
|
52 } |
|
53 |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // CMMCScBkupTransferRequestBase::RequestL() |
|
57 // |
|
58 // |
|
59 // --------------------------------------------------------------------------- |
|
60 void CMMCScBkupTransferRequestBase::RequestL( CMMCScBkupDataOwnerInfo& aOwner, TRequestStatus& aObserver ) |
|
61 { |
|
62 __ASSERT_ALWAYS( !IsActive(), User::Invariant() ); |
|
63 // |
|
64 iDataOwner = &aOwner; |
|
65 SetObserver( aObserver ); |
|
66 } |
|
67 |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // CMMCScBkupTransferRequestBase::SingleDriveTransferCompleteL() |
|
71 // |
|
72 // |
|
73 // --------------------------------------------------------------------------- |
|
74 void CMMCScBkupTransferRequestBase::SingleDriveTransferCompleteL() |
|
75 { |
|
76 if ( iUpdateOperationalSizes ) |
|
77 { |
|
78 const TDriveNumber drive = CurrentDrive(); |
|
79 const TInt amount = AmountOfDataTransferred(); |
|
80 __LOG3("CMMCScBkupTransferRequestBase::SingleDriveTransferCompleteL() - drive: %c:, amount: %8d, elementType: %S", drive + 'A', amount, &MMCScBkupLogger::DataType( ElementType() ) ); |
|
81 // |
|
82 ASSERT( drive >= EDriveA && drive <= EDriveZ ); |
|
83 } |
|
84 |
|
85 ResetDataTransferCounter(); |
|
86 } |
|
87 |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // CMMCScBkupTransferRequestBase::TransferCompleteL() |
|
91 // |
|
92 // |
|
93 // --------------------------------------------------------------------------- |
|
94 void CMMCScBkupTransferRequestBase::TransferCompleteL() |
|
95 { |
|
96 DataOwner().SetCompletionStatus( iElementType, ETrue ); |
|
97 } |
|
98 |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // CMMCScBkupTransferRequestBase::CompleteSelf() |
|
102 // |
|
103 // |
|
104 // --------------------------------------------------------------------------- |
|
105 void CMMCScBkupTransferRequestBase::CompleteSelf( TInt aCompletionCode ) |
|
106 { |
|
107 SetActive(); |
|
108 TRequestStatus* status = &iStatus; |
|
109 User::RequestComplete(status, aCompletionCode); |
|
110 } |
|
111 |
|
112 |
|
113 // --------------------------------------------------------------------------- |
|
114 // CMMCScBkupTransferRequestBase::SetObserver() |
|
115 // |
|
116 // |
|
117 // --------------------------------------------------------------------------- |
|
118 void CMMCScBkupTransferRequestBase::SetObserver( TRequestStatus& aObserver ) |
|
119 { |
|
120 __ASSERT_DEBUG( iObserver == NULL, User::Invariant() ); |
|
121 iObserver = &aObserver; |
|
122 aObserver = KRequestPending; |
|
123 } |
|
124 |
|
125 |
|
126 // --------------------------------------------------------------------------- |
|
127 // CMMCScBkupTransferRequestBase::CompleteObserverRequest() |
|
128 // |
|
129 // |
|
130 // --------------------------------------------------------------------------- |
|
131 void CMMCScBkupTransferRequestBase::CompleteObserverRequest( TInt aCompletionCode ) |
|
132 { |
|
133 __LOG1("CMMCScBkupTransferRequestBase::CompleteObserverRequest() - aCompletionCode: %d", aCompletionCode); |
|
134 __ASSERT_ALWAYS(iObserver != NULL, User::Invariant()); |
|
135 User::RequestComplete(iObserver, aCompletionCode); |
|
136 } |
|
137 |
|
138 |
|
139 // --------------------------------------------------------------------------- |
|
140 // CMMCScBkupTransferRequestBase::RunL() |
|
141 // |
|
142 // |
|
143 // --------------------------------------------------------------------------- |
|
144 void CMMCScBkupTransferRequestBase::RunL() |
|
145 { |
|
146 __LOG2("CMMCScBkupTransferRequestBase::RunL() - START - iStatus: %d, iState: %d", iStatus.Int(), iState); |
|
147 |
|
148 User::LeaveIfError( iStatus.Int() ); |
|
149 // |
|
150 switch( State() ) |
|
151 { |
|
152 case ETransferData: |
|
153 __LOG("CMMCScBkupTransferRequestBase::RunL() - ETransferData"); |
|
154 PrepareDataTransferL(); |
|
155 break; |
|
156 |
|
157 case EProcessData: |
|
158 __LOG("CMMCScBkupTransferRequestBase::RunL() - EProcessData"); |
|
159 ProcessDataChunkL(); |
|
160 break; |
|
161 |
|
162 case EFinished: |
|
163 // Inform any interested derived classes |
|
164 __LOG("CMMCScBkupTransferRequestBase::RunL() - EFinished - transfer complete...."); |
|
165 TransferCompleteL(); |
|
166 |
|
167 // Notify observer |
|
168 __LOG("CMMCScBkupTransferRequestBase::RunL() - EFinished - complete observer..."); |
|
169 CompleteObserverRequest( KErrNone ); |
|
170 break; |
|
171 |
|
172 default: |
|
173 case EIdle: |
|
174 __LOG("CMMCScBkupTransferRequestBase::RunL() - EIdle - User::Invariant()"); |
|
175 ASSERT( EFalse ); |
|
176 break; |
|
177 } |
|
178 |
|
179 __LOG2("CMMCScBkupTransferRequestBase::RunL() - END - iStatus: %d, iState: %d", iStatus.Int(), iState); |
|
180 } |
|
181 |
|
182 |
|
183 // --------------------------------------------------------------------------- |
|
184 // CMMCScBkupTransferRequestBase::DoCancel() |
|
185 // |
|
186 // |
|
187 // --------------------------------------------------------------------------- |
|
188 void CMMCScBkupTransferRequestBase::DoCancel() |
|
189 { |
|
190 CompleteObserverRequest( KErrCancel ); |
|
191 } |
|
192 |
|
193 |
|
194 // --------------------------------------------------------------------------- |
|
195 // CMMCScBkupTransferRequestBase::RunError() |
|
196 // |
|
197 // |
|
198 // --------------------------------------------------------------------------- |
|
199 TInt CMMCScBkupTransferRequestBase::RunError( TInt aError ) |
|
200 { |
|
201 if ( aError != KErrNone ) |
|
202 { |
|
203 __LOGFILE1("CMMCScBkupTransferRequestBase::RunError() - **** - ERROR (%d) -> complete observer with error code", aError); |
|
204 } |
|
205 // |
|
206 CompleteObserverRequest( aError ); |
|
207 return KErrNone; |
|
208 } |
|
209 |
|
210 |
|
211 // --------------------------------------------------------------------------- |
|
212 // CMMCScBkupTransferRequestBase::ProcessDataChunkL() |
|
213 // |
|
214 // |
|
215 // --------------------------------------------------------------------------- |
|
216 void CMMCScBkupTransferRequestBase::ProcessDataChunkL() |
|
217 { |
|
218 __LOG("CMMCScBkupTransferRequestBase::ProcessDataChunkL() - START"); |
|
219 |
|
220 // Now call virtual function to do the processing |
|
221 const TBool requiresMoreChunkProcessing = ProcessChunkOfDataL(); |
|
222 __LOG1("CMMCScBkupTransferRequestBase::ProcessDataChunkL() - requiresMoreChunkProcessing: %d", requiresMoreChunkProcessing); |
|
223 // |
|
224 TState nextState = EProcessData; |
|
225 if ( !requiresMoreChunkProcessing ) |
|
226 { |
|
227 __LOG("CMMCScBkupTransferRequestBase::ProcessDataChunkL() - didnt require more processing... "); |
|
228 SingleDriveTransferCompleteL(); |
|
229 // |
|
230 nextState = ETransferData; |
|
231 __LOG("CMMCScBkupTransferRequestBase::ProcessDataChunkL() - nextState is: ETransferData"); |
|
232 } |
|
233 else |
|
234 { |
|
235 __LOG("CMMCScBkupTransferRequestBase::ProcessDataChunkL() - nextState is: EProcessData"); |
|
236 } |
|
237 |
|
238 // Must check IsActive(), since CMMCScBkupReadDataTransferRequestBase::ProcessChunkOfDataL() |
|
239 // changes state and set's active within the ProcessChunkOfDataL callback |
|
240 if ( !IsActive() ) |
|
241 { |
|
242 __LOG("CMMCScBkupTransferRequestBase::ProcessDataChunkL() - not active - completing self and changing state!"); |
|
243 SetState( nextState ); |
|
244 CompleteSelf(); |
|
245 } |
|
246 else |
|
247 { |
|
248 __LOG1("CMMCScBkupTransferRequestBase::ProcessDataChunkL() - already active - state is: %d", State()); |
|
249 } |
|
250 |
|
251 __LOG("CMMCScBkupTransferRequestBase::ProcessDataChunkL() - END"); |
|
252 } |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|