|
1 /* |
|
2 * Copyright (c) 2006-2008 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: CFStarter class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "cfstarter.h" |
|
20 #include "cfstarterobserver.h" |
|
21 #include "cfphasedevicestarting.h" |
|
22 #include "cfphasedevicestarted.h" |
|
23 #include "cfphaseloadingplugins.h" |
|
24 #include "cfphaseloadingrules.h" |
|
25 #include "cfphasecfwready.h" |
|
26 #include "cfwcontextdef.h" |
|
27 #include "cfcontextinterface.h" |
|
28 #include "cftrace.h" |
|
29 |
|
30 // CONSTANTS |
|
31 |
|
32 #ifdef _DEBUG |
|
33 |
|
34 // Panic category |
|
35 _LIT( KPanicCat, "CFStarter" ); |
|
36 |
|
37 // Panic codes |
|
38 enum TPanicReason |
|
39 { |
|
40 EInvalidObserver, |
|
41 EAlreadyStarted, |
|
42 EInvalidState |
|
43 }; |
|
44 |
|
45 // Local panic function |
|
46 LOCAL_C void Panic( TInt aCode ) |
|
47 { |
|
48 User::Panic( KPanicCat, aCode ); |
|
49 } |
|
50 |
|
51 #endif |
|
52 |
|
53 // MEMBER FUNCTIONS |
|
54 |
|
55 CCFStarter* CCFStarter::NewL( MCFContextInterface& aCF ) |
|
56 { |
|
57 FUNC_LOG; |
|
58 |
|
59 CCFStarter* self = CCFStarter::NewLC( aCF ); |
|
60 CleanupStack::Pop( self ); |
|
61 |
|
62 return self; |
|
63 } |
|
64 |
|
65 CCFStarter* CCFStarter::NewLC( MCFContextInterface& aCF ) |
|
66 { |
|
67 FUNC_LOG; |
|
68 |
|
69 CCFStarter* self = new ( ELeave ) CCFStarter( aCF ); |
|
70 CleanupStack::PushL( self ); |
|
71 self->ConstructL(); |
|
72 |
|
73 return self; |
|
74 } |
|
75 |
|
76 CCFStarter::~CCFStarter() |
|
77 { |
|
78 FUNC_LOG; |
|
79 |
|
80 Cancel(); |
|
81 iPhases.ResetAndDestroy(); |
|
82 iObservers.Close(); |
|
83 } |
|
84 |
|
85 CCFStarter::CCFStarter( MCFContextInterface& aCF ): |
|
86 CActive( EPriorityStandard ), |
|
87 iCF( aCF ) |
|
88 { |
|
89 FUNC_LOG; |
|
90 |
|
91 CActiveScheduler::Add( this ); |
|
92 } |
|
93 |
|
94 void CCFStarter::ConstructL() |
|
95 { |
|
96 FUNC_LOG; |
|
97 |
|
98 // Construct starter phases |
|
99 iPhases.InsertL( |
|
100 CCFPhaseDeviceStarting::NewL( iCF ), |
|
101 CCFPhaseBase::ECFDeviceStarting ); |
|
102 iPhases.InsertL( |
|
103 CCFPhaseDeviceStarted::NewL( iCF ), |
|
104 CCFPhaseBase::ECFDeviceStarted ); |
|
105 iPhases.InsertL( |
|
106 CCFPhaseLoadingPlugins::NewL( iCF ), |
|
107 CCFPhaseBase::ECFLoadingPlugins ); |
|
108 iPhases.InsertL( |
|
109 CCFPhaseLoadingRules::NewL( iCF ), |
|
110 CCFPhaseBase::ECFLoadingRules ); |
|
111 iPhases.InsertL( |
|
112 CCFPhaseCfwReady::NewL( iCF ), |
|
113 CCFPhaseBase::ECFCfwReady ); |
|
114 } |
|
115 |
|
116 // METHODS |
|
117 |
|
118 //----------------------------------------------------------------------------- |
|
119 // CCFStarter::AddObserverL |
|
120 //----------------------------------------------------------------------------- |
|
121 // |
|
122 void CCFStarter::AddObserverL( MCFStarterObserver* aObserver ) |
|
123 { |
|
124 FUNC_LOG; |
|
125 |
|
126 __ASSERT_DEBUG( aObserver, Panic( EInvalidObserver ) ); |
|
127 |
|
128 iObservers.AppendL( aObserver ); |
|
129 |
|
130 aObserver->SetEventHandler( *this ); |
|
131 } |
|
132 |
|
133 //----------------------------------------------------------------------------- |
|
134 // CCFStarter::Start |
|
135 //----------------------------------------------------------------------------- |
|
136 // |
|
137 void CCFStarter::StartL() |
|
138 { |
|
139 FUNC_LOG; |
|
140 |
|
141 HEAP( "Starting CF initialization" ); |
|
142 TIMESTAMP( "Starting CF initialization" ); |
|
143 |
|
144 // Define context: [ContextFramework: Status] |
|
145 iCF.DefineContext( KCfwSource, KCfwSourceStatus, KCfwSourceStatusSec ); |
|
146 |
|
147 // Set in first state and run it |
|
148 iCurrentPhase = CCFPhaseBase::ECFDeviceStarting; |
|
149 RunNextL(); |
|
150 } |
|
151 |
|
152 //----------------------------------------------------------------------------- |
|
153 // CCFStarter::RunL |
|
154 //----------------------------------------------------------------------------- |
|
155 // |
|
156 void CCFStarter::RunL() |
|
157 { |
|
158 FUNC_LOG; |
|
159 |
|
160 // First switch to next phase if error occurs we can continue |
|
161 CCFPhaseBase::TCFPhaseId phaseId = SwitchToNextPhase(); |
|
162 |
|
163 INFO_1( "Phase %d execution start", phaseId ); |
|
164 HEAP_1( "Phase %d execution start", phaseId ); |
|
165 TIMESTAMP( "Phase execution start" ); |
|
166 |
|
167 // Handle current phase |
|
168 if( iStatus == KErrNone ) |
|
169 { |
|
170 TInt count = iObservers.Count(); |
|
171 for( TInt i = 0; i < count; i++ ) |
|
172 { |
|
173 TInt err = KErrNone; |
|
174 TRAP( err, iObservers[i]->InitializePhaseL( phaseId ) ); |
|
175 ERROR_3( err, "Phase observer with index: [%d] failed to init in phase: [%d] with error code: %d", |
|
176 i, |
|
177 phaseId, |
|
178 err ); |
|
179 } |
|
180 } |
|
181 |
|
182 INFO_1( "Phase %d execution end", phaseId ); |
|
183 HEAP_1( "Phase %d execution end", phaseId ); |
|
184 TIMESTAMP( "Phase execution end" ); |
|
185 |
|
186 // Run next phase |
|
187 RunNextL(); |
|
188 } |
|
189 |
|
190 //----------------------------------------------------------------------------- |
|
191 // CCFStarter::DoCancel |
|
192 //----------------------------------------------------------------------------- |
|
193 // |
|
194 void CCFStarter::DoCancel() |
|
195 { |
|
196 FUNC_LOG; |
|
197 |
|
198 if( iCurrentPhase < iPhases.Count() ) |
|
199 { |
|
200 iPhases[iCurrentPhase]->Cancel(); |
|
201 } |
|
202 } |
|
203 |
|
204 //----------------------------------------------------------------------------- |
|
205 // CCFStarter::RunError |
|
206 //----------------------------------------------------------------------------- |
|
207 // |
|
208 TInt CCFStarter::RunError( TInt /*aError*/ ) |
|
209 { |
|
210 FUNC_LOG; |
|
211 |
|
212 // Current phase failed to run in RunL |
|
213 // Switch to next phase |
|
214 SwitchToNextPhase(); |
|
215 TInt count = iPhases.Count(); |
|
216 for( TInt i = iCurrentPhase; i < count; i++ ) |
|
217 { |
|
218 TRAPD( err, RunNextL() ); |
|
219 if( err == KErrNone ) |
|
220 { |
|
221 break; |
|
222 } |
|
223 else |
|
224 { |
|
225 // Failed to run next phase again |
|
226 // Switch to next phase |
|
227 SwitchToNextPhase(); |
|
228 } |
|
229 } |
|
230 return KErrNone; |
|
231 } |
|
232 |
|
233 //----------------------------------------------------------------------------- |
|
234 // CCFStarter::HandleEvent |
|
235 //----------------------------------------------------------------------------- |
|
236 // |
|
237 void CCFStarter::HandleEvent( TCFStarterEvents aEvent ) |
|
238 { |
|
239 FUNC_LOG; |
|
240 |
|
241 if( iCurrentPhase >= 0 && iCurrentPhase < iPhases.Count() ) |
|
242 { |
|
243 iPhases[iCurrentPhase]->HandleEvent( aEvent ); |
|
244 } |
|
245 } |
|
246 |
|
247 //----------------------------------------------------------------------------- |
|
248 // CCFStarter::SwitchToNextPhase |
|
249 //----------------------------------------------------------------------------- |
|
250 // |
|
251 CCFPhaseBase::TCFPhaseId CCFStarter::SwitchToNextPhase() |
|
252 { |
|
253 FUNC_LOG; |
|
254 |
|
255 __ASSERT_DEBUG( iCurrentPhase >= 0 && iCurrentPhase < iPhases.Count(), |
|
256 Panic( EInvalidState ) ); |
|
257 |
|
258 CCFPhaseBase::TCFPhaseId previous = iCurrentPhase; |
|
259 iCurrentPhase = iPhases[iCurrentPhase]->NextPhase(); |
|
260 |
|
261 return previous; |
|
262 } |
|
263 |
|
264 //----------------------------------------------------------------------------- |
|
265 // CCFStarter::RunNextL |
|
266 //----------------------------------------------------------------------------- |
|
267 // |
|
268 void CCFStarter::RunNextL() |
|
269 { |
|
270 FUNC_LOG; |
|
271 |
|
272 __ASSERT_DEBUG( !IsActive(), Panic( EAlreadyStarted ) ); |
|
273 |
|
274 if( iCurrentPhase < iPhases.Count() ) |
|
275 { |
|
276 iStatus = KRequestPending; |
|
277 iPhases[iCurrentPhase]->ExecuteL( &iStatus ); |
|
278 SetActive(); |
|
279 } |
|
280 else |
|
281 { |
|
282 HEAP( "[END] CF Starter phases executed" ); |
|
283 } |
|
284 } |