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: CMMCScBkupState implementation |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 #include "CMMCScBkupState.h" |
|
20 |
|
21 // User includes |
|
22 #include "MMCScBkupLogger.h" |
|
23 |
|
24 |
|
25 // ========================= MEMBER FUNCTIONS ================================ |
|
26 |
|
27 // --------------------------------------------------------------------------- |
|
28 // CMMCScBkupState::CMMCScBkupState() |
|
29 // |
|
30 // C++ constructor. |
|
31 // --------------------------------------------------------------------------- |
|
32 CMMCScBkupState::CMMCScBkupState( MMMCScBkupDriver& aDriver, TInt aPriority ) |
|
33 : CActive( aPriority ), iDriver( aDriver ) |
|
34 { |
|
35 CActiveScheduler::Add(this); |
|
36 } |
|
37 |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // CMMCScBkupState::~CMMCScBkupState() |
|
41 // |
|
42 // Destructor. |
|
43 // --------------------------------------------------------------------------- |
|
44 CMMCScBkupState::~CMMCScBkupState() |
|
45 { |
|
46 Cancel(); |
|
47 } |
|
48 |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // CMMCScBkupState::RunL() |
|
52 // |
|
53 // |
|
54 // --------------------------------------------------------------------------- |
|
55 void CMMCScBkupState::RunL() |
|
56 { |
|
57 User::LeaveIfError(iStatus.Int()); |
|
58 // |
|
59 PerformAsynchronousStateStepL(); |
|
60 // |
|
61 if (!IsActive()) |
|
62 { |
|
63 // If we've processed all the asynchronous steps, then |
|
64 // perform the last rights on the state. |
|
65 // |
|
66 // If this causes a leave, then we cascade the failure |
|
67 // to the observer - i.e. the error is treated as fatal. |
|
68 TRAPD(err, PerformLastRightsL() ); |
|
69 CompleteObserver( err ); |
|
70 } |
|
71 } |
|
72 |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // CMMCScBkupState::DoCancel() |
|
76 // |
|
77 // |
|
78 // --------------------------------------------------------------------------- |
|
79 void CMMCScBkupState::DoCancel() |
|
80 { |
|
81 __LOG3("CMMCScBkupState::DoCancel() - START - state: 0x%08x, IsActive: %d, status: %d", StateId().iUid, IsActive(), iStatus.Int() ); |
|
82 PerformAsynchronousCancellation(); |
|
83 CompleteObserver( KErrCancel ); |
|
84 __LOG3("CMMCScBkupState::DoCancel() - END - state: 0x%08x, IsActive: %d, status: %d", StateId().iUid, IsActive(), iStatus.Int() ); |
|
85 } |
|
86 |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // CMMCScBkupState::RunError() |
|
90 // |
|
91 // |
|
92 // --------------------------------------------------------------------------- |
|
93 TInt CMMCScBkupState::RunError(TInt aError) |
|
94 { |
|
95 #ifdef MMCSCBKUP_USE_BREAKPOINTS |
|
96 __BREAKPOINT(); |
|
97 #endif |
|
98 // |
|
99 if ( aError == KErrNoMemory || aError == KErrDiskFull || aError == KErrNotReady || aError == KErrServerTerminated || aError == KErrWrite ) |
|
100 { |
|
101 __LOGFILE2("CMMCScBkupState::RunError() - **** - FATAL ERROR - state: 0x%08x, aError: %d - Notifying Observer (Engine)", StateId().iUid, aError ); |
|
102 CompleteObserver( aError ); |
|
103 } |
|
104 else |
|
105 { |
|
106 __LOGFILE2("CMMCScBkupState::RunError() - **** - ATTEMPT TO HANDLE ERROR - state: 0x%08x, aError: %d...", StateId().iUid, aError ); |
|
107 |
|
108 const TBool errorHandled = PerformAsynchronousErrorCleanup( aError ); |
|
109 |
|
110 __LOGFILE1("CMMCScBkupState::RunError() - **** - handle error result: %d", errorHandled ); |
|
111 |
|
112 // If the cleanup callback didn't set us active again, then |
|
113 // assume the object didn't perform any recovery. Therefore |
|
114 // inform our observer about the error and give up. |
|
115 if (!errorHandled || !IsActive()) |
|
116 { |
|
117 CompleteObserver( aError ); |
|
118 } |
|
119 } |
|
120 // |
|
121 return KErrNone; |
|
122 } |
|
123 |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // CMMCScBkupState::ExecuteL() |
|
127 // |
|
128 // |
|
129 // --------------------------------------------------------------------------- |
|
130 void CMMCScBkupState::ExecuteL(TRequestStatus& aObserver) |
|
131 { |
|
132 SetObserver(aObserver); |
|
133 TRAPD(error, PerformStateInitL()); |
|
134 |
|
135 // If the object is active, then it is making use of asynchronous |
|
136 // functionality, in which case we do nothing. |
|
137 // |
|
138 // If the object is not active or the call to PerformStateActionL left, |
|
139 // then we complete the observer with the result of the trap |
|
140 if (error != KErrNone || IsActive() == EFalse) |
|
141 { |
|
142 if (error == KErrNone) |
|
143 { |
|
144 PerformLastRightsL(); |
|
145 } |
|
146 // |
|
147 CompleteObserver(error); |
|
148 } |
|
149 } |
|
150 |
|
151 |
|
152 // --------------------------------------------------------------------------- |
|
153 // CMMCScBkupState::PerformAsynchronousStateStepL() |
|
154 // |
|
155 // |
|
156 // --------------------------------------------------------------------------- |
|
157 void CMMCScBkupState::PerformAsynchronousStateStepL() |
|
158 { |
|
159 // Derived classes should override this if they implement |
|
160 // asynchronous behaviour |
|
161 User::Invariant(); |
|
162 } |
|
163 |
|
164 |
|
165 // --------------------------------------------------------------------------- |
|
166 // CMMCScBkupState::PerformAsynchronousCancellation() |
|
167 // |
|
168 // |
|
169 // --------------------------------------------------------------------------- |
|
170 void CMMCScBkupState::PerformAsynchronousCancellation() |
|
171 { |
|
172 // Derived classes are expected to implement this if they have |
|
173 // resources to free. For calls to CompleteSelf(), no action is needed. |
|
174 __LOG3("CMMCScBkupState::PerformAsynchronousCancellation() - ERROR - cancellation not implemented for state: 0x%08x, IsActive: %d, status: %d", StateId().iUid, IsActive(), iStatus.Int() ); |
|
175 } |
|
176 |
|
177 |
|
178 // --------------------------------------------------------------------------- |
|
179 // CMMCScBkupState::PerformLastRightsL() |
|
180 // |
|
181 // |
|
182 // --------------------------------------------------------------------------- |
|
183 void CMMCScBkupState::PerformLastRightsL() |
|
184 { |
|
185 } |
|
186 |
|
187 |
|
188 // --------------------------------------------------------------------------- |
|
189 // CMMCScBkupState::PerformAsynchronousErrorCleanup() |
|
190 // |
|
191 // |
|
192 // --------------------------------------------------------------------------- |
|
193 TBool CMMCScBkupState::PerformAsynchronousErrorCleanup( TInt aError ) |
|
194 { |
|
195 (void) aError; |
|
196 __LOGFILE2("CMMCScBkupState::PerformAsynchronousErrorCleanup() - error: %d, state id: 0x%08x", aError, StateId().iUid ); |
|
197 return EFalse; |
|
198 } |
|
199 |
|
200 |
|
201 // --------------------------------------------------------------------------- |
|
202 // CMMCScBkupState::CompleteSelf() |
|
203 // |
|
204 // |
|
205 // --------------------------------------------------------------------------- |
|
206 void CMMCScBkupState::CompleteSelf( TInt aCompletionCode ) |
|
207 { |
|
208 SetActive(); |
|
209 TRequestStatus* status = &iStatus; |
|
210 User::RequestComplete( status, aCompletionCode ); |
|
211 } |
|
212 |
|
213 |
|
214 // --------------------------------------------------------------------------- |
|
215 // CMMCScBkupState::CompleteObserver() |
|
216 // |
|
217 // |
|
218 // --------------------------------------------------------------------------- |
|
219 void CMMCScBkupState::CompleteObserver( TInt aCompletionCode ) |
|
220 { |
|
221 __ASSERT_ALWAYS(iObserver != NULL, User::Invariant()); |
|
222 User::RequestComplete( iObserver, aCompletionCode ); |
|
223 } |
|
224 |
|
225 |
|
226 // --------------------------------------------------------------------------- |
|
227 // CMMCScBkupState::SetObserver() |
|
228 // |
|
229 // |
|
230 // --------------------------------------------------------------------------- |
|
231 void CMMCScBkupState::SetObserver(TRequestStatus& aStatus) |
|
232 { |
|
233 __ASSERT_ALWAYS(iObserver == NULL, User::Invariant()); |
|
234 aStatus = KRequestPending; |
|
235 iObserver = &aStatus; |
|
236 } |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|