1 /* |
|
2 * Copyright (c) 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: Implementation of the CLcVtCmdExecutor class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "clcvtcmdexecutor.h" |
|
21 #include "mlcvtenginecommandmanager.h" |
|
22 #include <mvtengcommandhandler.h> |
|
23 #include <cvtlogger.h> |
|
24 |
|
25 // MODULE DATA STRUCTURES |
|
26 |
|
27 /** |
|
28 * Active object to perform asynchronous commands. |
|
29 * @since Series 60 2.6 |
|
30 */ |
|
31 class CLcVtCmdExecutor::CActiveCmd |
|
32 : public CActive |
|
33 { |
|
34 public: // Constructors and destructor |
|
35 |
|
36 /** |
|
37 * Constructor. |
|
38 */ |
|
39 CActiveCmd( |
|
40 CLcVtCmdExecutor& aDialog, |
|
41 MVtEngCommandHandler& aCommandHandler, |
|
42 TVtEngCommandId aCommand, |
|
43 TDesC8* aParams ); |
|
44 |
|
45 /** |
|
46 * Destructor. |
|
47 */ |
|
48 ~CActiveCmd(); |
|
49 |
|
50 public: // New functions |
|
51 |
|
52 /** |
|
53 * Starts active object. Command will be performed in RunL. |
|
54 */ |
|
55 void Start(); |
|
56 |
|
57 /** |
|
58 * Checks if command has been performed. |
|
59 * @return ETrue if command has been performed. |
|
60 */ |
|
61 TBool CommandPerformed() const; |
|
62 |
|
63 private: |
|
64 |
|
65 /** |
|
66 * @see CActive::RunL |
|
67 */ |
|
68 void RunL(); |
|
69 |
|
70 /** |
|
71 * @see CActive::DoCancel. |
|
72 */ |
|
73 void DoCancel(); |
|
74 |
|
75 /** |
|
76 * @see CActive::RunError. |
|
77 */ |
|
78 TInt RunError( TInt aResult ); |
|
79 |
|
80 private: |
|
81 |
|
82 // Ref to dialog. |
|
83 CLcVtCmdExecutor& iExecutor; |
|
84 |
|
85 // Ref to command handler. |
|
86 MVtEngCommandHandler& iCommandHandler; |
|
87 |
|
88 // Command to be executed. |
|
89 TVtEngCommandId iCommand; |
|
90 |
|
91 // Owned parameters. |
|
92 TDesC8* iCommandParams; |
|
93 |
|
94 // ETrue if command has been performed. |
|
95 TBool iCommandPerformed; |
|
96 |
|
97 }; |
|
98 |
|
99 // ============================ MEMBER FUNCTIONS =============================== |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CLcVtCmdExecutor::CLcVtCmdExecutor |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 CLcVtCmdExecutor::CLcVtCmdExecutor( |
|
106 CLcVtCmdExecutor** aSelfPtr, |
|
107 MVtEngCommandHandler& aCommandHandler, |
|
108 MLcVtEngineCommandManager& aCommandManager ) |
|
109 : iSelfPtr( aSelfPtr ), |
|
110 iCommandHandler( aCommandHandler ), |
|
111 iCommandManager( aCommandManager ) |
|
112 { |
|
113 iRequest = NULL; |
|
114 __VTPRINT2( DEBUG_GEN, "CLcVtCmdExecutor.Ctor this=%d", (TInt)this ) |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CLcVtCmdExecutor::~CLcVtCmdExecutor |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 CLcVtCmdExecutor::~CLcVtCmdExecutor() |
|
122 { |
|
123 __VTPRINTENTER( "CLcVtCmdExecutor.~" ) |
|
124 __VTPRINT2( DEBUG_GEN, "CLcVtCmdExecutor.~ this=%d", (TInt)this ) |
|
125 if ( iActiveCmd ) |
|
126 { |
|
127 if ( !iCommandCompleted && iActiveCmd->CommandPerformed() ) |
|
128 { |
|
129 iCommandHandler.CancelCommand( iCommand ); // ignore error |
|
130 } |
|
131 } |
|
132 delete iCommandParams; |
|
133 delete iActiveCmd; |
|
134 |
|
135 iCommandManager.RemoveObserver( *this ); |
|
136 |
|
137 if ( iSelfPtr ) |
|
138 { |
|
139 *iSelfPtr = NULL; |
|
140 iSelfPtr = NULL; |
|
141 } |
|
142 |
|
143 if ( iRequest ) |
|
144 { |
|
145 __VTPRINT(DEBUG_GEN, "CLcVtCmdExecutor::~CLcVtCmdExecutor RequestComplete") |
|
146 User::RequestComplete( iRequest, KErrCancel ); |
|
147 iRequest = NULL; |
|
148 } |
|
149 else |
|
150 { |
|
151 if ( iWait.IsStarted()) |
|
152 { |
|
153 __VTPRINT(DEBUG_GEN, "CLcVtCmdExecutor::~CLcVtCmdExecutor AsyncStop") |
|
154 iWait.AsyncStop(); |
|
155 } |
|
156 } |
|
157 |
|
158 |
|
159 __VTPRINTEXIT( "CLcVtCmdExecutor.~" ) |
|
160 } |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // CLcVtCmdExecutor::ExecuteCmdL |
|
164 // ----------------------------------------------------------------------------- |
|
165 // |
|
166 void CLcVtCmdExecutor::ExecuteCmdL( |
|
167 const TVtEngCommandId aCommandId, |
|
168 TDesC8* aParams, |
|
169 TRequestStatus* aRequest ) |
|
170 { |
|
171 __VTPRINTENTER( "CLcVtCmdExecutor.ExecuteCmdL" ) |
|
172 __VTPRINT2( DEBUG_GEN, "CLcVtCmdExecutor.ExecuteCmdL this=%d", (TInt)this ) |
|
173 iCommand = aCommandId; |
|
174 CleanupStack::PushL( this ); |
|
175 if ( aParams ) |
|
176 { |
|
177 iCommandParams = aParams->AllocL(); |
|
178 } |
|
179 |
|
180 iCommandManager.AddObserverL( *this ); |
|
181 CleanupStack::Pop( this ); |
|
182 |
|
183 iActiveCmd = |
|
184 new ( ELeave ) CActiveCmd( |
|
185 *this, iCommandHandler, iCommand, iCommandParams ); |
|
186 iActiveCmd->Start(); |
|
187 |
|
188 if ( !aRequest ) |
|
189 { |
|
190 TInt error = KErrNone; |
|
191 iError = &error; |
|
192 //Start Active Schedule |
|
193 iWait.Start(); |
|
194 User::LeaveIfError( error ); |
|
195 } |
|
196 else |
|
197 { |
|
198 *aRequest = KRequestPending; |
|
199 iRequest = aRequest; |
|
200 } |
|
201 |
|
202 __VTPRINTEXIT( "CLcVtCmdExecutor.ExecuteCmdL" ) |
|
203 } |
|
204 |
|
205 |
|
206 // ----------------------------------------------------------------------------- |
|
207 // CLcVtCmdExecutor::Complete |
|
208 // ----------------------------------------------------------------------------- |
|
209 // |
|
210 void CLcVtCmdExecutor::Complete( const TInt aError ) |
|
211 { |
|
212 if ( iError ) |
|
213 { |
|
214 *iError = aError; |
|
215 } |
|
216 |
|
217 if ( iRequest ) |
|
218 { |
|
219 User::RequestComplete( iRequest, aError ); |
|
220 iRequest = NULL; |
|
221 } |
|
222 |
|
223 delete this; |
|
224 } |
|
225 |
|
226 // ----------------------------------------------------------------------------- |
|
227 // CLcVtCmdExecutor::HandleVTCommandPerformedL |
|
228 // ----------------------------------------------------------------------------- |
|
229 // |
|
230 void CLcVtCmdExecutor::HandleVTCommandPerformedL( |
|
231 TVtEngCommandId aCommand, |
|
232 const TInt aError ) |
|
233 { |
|
234 __VTPRINTENTER( "CLcVtCmdExecutor.HandleVTCommandPerformed" ) |
|
235 __VTPRINT2( DEBUG_GEN, "CLcVtCmdExecutor.HandleVTCommandPerformed.cmd.%d", aCommand ) |
|
236 __VTPRINT2( DEBUG_GEN, "CLcVtCmdExecutor.HandleVTCommandPerformed.err.%d", aError ) |
|
237 if ( iActiveCmd && ( aCommand == iCommand ) ) |
|
238 { |
|
239 if ( iActiveCmd->CommandPerformed() && !iCommandCompleted ) |
|
240 { |
|
241 __VTPRINT( DEBUG_GEN, "CLcVtCmdExecutor.match" ) |
|
242 iCommandCompleted = ETrue; |
|
243 // Corrupted images may leave during initialization, thus we have |
|
244 // to mask out errors when they happen during share initialize. |
|
245 // Error code is handled correctly in CVtUiAppUi::CEventObserver:: |
|
246 // HandleVTCommandPerformedL() method, thus it will not be ignored. |
|
247 if ( aCommand == KVtEngInitializeShareImage ) |
|
248 { |
|
249 Complete( KErrNone ); |
|
250 } |
|
251 else |
|
252 { |
|
253 Complete( aError ); |
|
254 } |
|
255 } |
|
256 } |
|
257 __VTPRINTEXIT( "CLcVtCmdExecutor.HandleVTCommandPerformed" ) |
|
258 } |
|
259 |
|
260 // ----------------------------------------------------------------------------- |
|
261 // CLcVtCmdExecutor::HandleExecuteFailed |
|
262 // ----------------------------------------------------------------------------- |
|
263 // |
|
264 void CLcVtCmdExecutor::HandleExecuteFailed( TInt aResult ) |
|
265 { |
|
266 __VTPRINT3( DEBUG_GEN, "CLcVtCmdExecutor.Fail this=%d res=%d", |
|
267 (TInt)this, aResult ) |
|
268 Complete( aResult ); |
|
269 } |
|
270 |
|
271 // Implementation of CLcVtCmdExecutor::CActiveCmd: |
|
272 |
|
273 // ----------------------------------------------------------------------------- |
|
274 // CLcVtCmdExecutor::CActiveCmd::CActiveCmd |
|
275 // ----------------------------------------------------------------------------- |
|
276 // |
|
277 CLcVtCmdExecutor::CActiveCmd::CActiveCmd( |
|
278 CLcVtCmdExecutor& aExecutor, |
|
279 MVtEngCommandHandler& aCommandHandler, |
|
280 TVtEngCommandId aCommand, |
|
281 TDesC8* aParams) |
|
282 : CActive( CActive::EPriorityHigh ), |
|
283 iExecutor( aExecutor ), |
|
284 iCommandHandler( aCommandHandler ), |
|
285 iCommand( aCommand ), |
|
286 iCommandParams( aParams ) |
|
287 { |
|
288 CActiveScheduler::Add( this ); |
|
289 } |
|
290 |
|
291 // ----------------------------------------------------------------------------- |
|
292 // CLcVtCmdExecutor::CActiveCmd::~CActiveCmd |
|
293 // ----------------------------------------------------------------------------- |
|
294 // |
|
295 CLcVtCmdExecutor::CActiveCmd::~CActiveCmd() |
|
296 { |
|
297 __VTPRINT2( DEBUG_GEN, "CLcVtCmdExecutor.CActiveCmd.Dtor this=%d", (TInt)this ) |
|
298 Cancel(); |
|
299 } |
|
300 |
|
301 // ----------------------------------------------------------------------------- |
|
302 // CLcVtCmdExecutor::CActiveCmd::Start |
|
303 // ----------------------------------------------------------------------------- |
|
304 // |
|
305 void CLcVtCmdExecutor::CActiveCmd::Start() |
|
306 { |
|
307 __VTPRINTENTER( "CLcVtCmdExecutor.CActiveCmd.Start" ) |
|
308 TRequestStatus* status = &iStatus; |
|
309 User::RequestComplete( status, KErrNone ); |
|
310 SetActive(); |
|
311 __VTPRINTEXITR( "CLcVtCmdExecutor.CActiveCmd.Start this=%d", (TInt)this ) |
|
312 } |
|
313 |
|
314 // ----------------------------------------------------------------------------- |
|
315 // CLcVtCmdExecutor::CActiveCmd::CommandPerformed |
|
316 // ----------------------------------------------------------------------------- |
|
317 // |
|
318 TBool CLcVtCmdExecutor::CActiveCmd::CommandPerformed() const |
|
319 { |
|
320 __VTPRINT3( DEBUG_GEN, "CLcVtCmdExecutor.CActiveCmd.Perf this=%d,cmd=%d", |
|
321 (TInt)this, iCommandPerformed ) |
|
322 return iCommandPerformed; |
|
323 } |
|
324 |
|
325 // ----------------------------------------------------------------------------- |
|
326 // CLcVtCmdExecutor::CActiveCmd::RunL |
|
327 // ----------------------------------------------------------------------------- |
|
328 // |
|
329 void CLcVtCmdExecutor::CActiveCmd::RunL() |
|
330 { |
|
331 __VTPRINTENTER( "CLcVtCmdExecutor.CActiveCmd.RunL" ) |
|
332 iCommandHandler.ExecuteL( iCommand, iCommandParams ); |
|
333 iCommandPerformed = ETrue; |
|
334 __VTPRINTEXITR( "CLcVtCmdExecutor.CActiveCmd.RunL this=%d", (TInt)this ) |
|
335 } |
|
336 |
|
337 // ----------------------------------------------------------------------------- |
|
338 // CLcVtCmdExecutor::CActiveCmd::DoCancel |
|
339 // ----------------------------------------------------------------------------- |
|
340 // |
|
341 void CLcVtCmdExecutor::CActiveCmd::DoCancel() |
|
342 { |
|
343 __VTPRINT2( DEBUG_GEN, "CLcVtCmdExecutor.CActiveCmd.DoCnl this=%d", (TInt)this ) |
|
344 // Request is completed immediately. |
|
345 } |
|
346 |
|
347 // ----------------------------------------------------------------------------- |
|
348 // CVtUiExecuteCmdDialog::CActiveCmd::RunError |
|
349 // ----------------------------------------------------------------------------- |
|
350 // |
|
351 TInt CLcVtCmdExecutor::CActiveCmd::RunError( TInt aResult ) |
|
352 { |
|
353 __VTPRINTENTER( "CLcVtCmdExecutor.CActiveCmd.RunError" ) |
|
354 // Exception was raised in RunL. Inform the dialog to close itself. |
|
355 iExecutor.HandleExecuteFailed( aResult ); |
|
356 __VTPRINTEXITR( "CLcVtCmdExecutor.CActiveCmd.RunError this=%d", (TInt)this ) |
|
357 return KErrNone; |
|
358 } |
|
359 |
|
360 // End of File |
|