1 /* |
|
2 * Copyright (c) 2006-2009 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: CUsbPersonalityNotifier class prevents confirmation notes |
|
15 * from overlapping. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include <cusbpersonalitynotifier.h> |
|
21 #include "debug.h" |
|
22 |
|
23 // ============================ MEMBER FUNCTIONS ============================== |
|
24 |
|
25 // ---------------------------------------------------------------------------- |
|
26 // C++ constructor |
|
27 // ---------------------------------------------------------------------------- |
|
28 // |
|
29 CUsbPersonalityNotifier::CUsbPersonalityNotifier() |
|
30 : CActive( EPriorityStandard ) |
|
31 { |
|
32 LOG_FUNC |
|
33 |
|
34 CActiveScheduler::Add( this ); |
|
35 } |
|
36 |
|
37 // ---------------------------------------------------------------------------- |
|
38 // Symbian 2nd phase constructor can leave. |
|
39 // ---------------------------------------------------------------------------- |
|
40 // |
|
41 void CUsbPersonalityNotifier::ConstructL() |
|
42 { |
|
43 LOG_FUNC |
|
44 } |
|
45 |
|
46 // ---------------------------------------------------------------------------- |
|
47 // Two-phased constructor. |
|
48 // ---------------------------------------------------------------------------- |
|
49 // |
|
50 EXPORT_C CUsbPersonalityNotifier* CUsbPersonalityNotifier::NewL() |
|
51 { |
|
52 LOG_FUNC |
|
53 |
|
54 CUsbPersonalityNotifier* self = new ( ELeave ) CUsbPersonalityNotifier(); |
|
55 CleanupStack::PushL( self ); |
|
56 self->ConstructL(); |
|
57 CleanupStack::Pop(); // pop self |
|
58 return self; |
|
59 } |
|
60 |
|
61 // ---------------------------------------------------------------------------- |
|
62 // Destructor |
|
63 // ---------------------------------------------------------------------------- |
|
64 // |
|
65 EXPORT_C CUsbPersonalityNotifier::~CUsbPersonalityNotifier() |
|
66 { |
|
67 LOG_FUNC |
|
68 |
|
69 Cancel(); |
|
70 |
|
71 for( TInt i = 0; iNotifierClient.Count(); i++ ) |
|
72 { |
|
73 delete iNotifierClient[i]; |
|
74 } |
|
75 |
|
76 iNotifierClient.Reset(); |
|
77 iNotifierClient.Close(); |
|
78 } |
|
79 |
|
80 // ---------------------------------------------------------------------------- |
|
81 // Called when information note or query is completed. |
|
82 // ---------------------------------------------------------------------------- |
|
83 // |
|
84 void CUsbPersonalityNotifier::RunL() |
|
85 { |
|
86 LOG_FUNC |
|
87 |
|
88 LOG1( "iStatus = %d", iStatus.Int() ); |
|
89 |
|
90 if( iCallBack ) |
|
91 { |
|
92 iCallBack->CallBack( iStatus.Int() ); |
|
93 } |
|
94 |
|
95 iNotifier.CancelNotifier( iNotifierUid ); |
|
96 iNotifier.Close(); |
|
97 |
|
98 iState = EUsbPersonalityNotifierIdle; |
|
99 |
|
100 if( iRequestStatus ) |
|
101 { |
|
102 User::RequestComplete( iRequestStatus, iStatus.Int() ); |
|
103 iRequestStatus = NULL; |
|
104 } |
|
105 |
|
106 if( iNotifierClient.Count() ) |
|
107 { |
|
108 if( iNotifierClient[0]->iConfirmation ) |
|
109 { |
|
110 DoShowQuery( iNotifierClient[0]->iCallBack, |
|
111 iNotifierClient[0]->iNotifierUid, |
|
112 iNotifierClient[0]->iBuffer, |
|
113 iNotifierClient[0]->iResponse, |
|
114 iNotifierClient[0]->iRequestStatus ); |
|
115 } |
|
116 else |
|
117 { |
|
118 DoShowNote( iNotifierClient[0]->iNotifierUid, |
|
119 iNotifierClient[0]->iBuffer, |
|
120 iNotifierClient[0]->iResponse ); |
|
121 } |
|
122 |
|
123 delete iNotifierClient[0]; |
|
124 iNotifierClient.Remove( 0 ); |
|
125 } |
|
126 } |
|
127 |
|
128 // ---------------------------------------------------------------------------- |
|
129 // This method is never called in this implementation. |
|
130 // ---------------------------------------------------------------------------- |
|
131 // |
|
132 TInt CUsbPersonalityNotifier::RunError( TInt aError ) |
|
133 { |
|
134 LOG_FUNC |
|
135 |
|
136 LOG1( "aError %d", aError ); |
|
137 // Currently no leaving functions called in RunL, thus nothing should cause |
|
138 // this to be called -> return. |
|
139 return KErrNone; |
|
140 } |
|
141 |
|
142 // ---------------------------------------------------------------------------- |
|
143 // Called if there is outstanding request. |
|
144 // ---------------------------------------------------------------------------- |
|
145 // |
|
146 void CUsbPersonalityNotifier::DoCancel() |
|
147 { |
|
148 LOG_FUNC |
|
149 |
|
150 if( EUsbPersonalityNotifierStarted == iState ) |
|
151 { |
|
152 LOG( "Canceling and closing notifier" ); |
|
153 iNotifier.CancelNotifier( iNotifierUid ); |
|
154 iNotifier.Close(); |
|
155 iState = EUsbPersonalityNotifierIdle; |
|
156 |
|
157 if( iRequestStatus ) |
|
158 { |
|
159 LOG( "Completing request" ); |
|
160 User::RequestComplete( iRequestStatus, KErrCancel ); |
|
161 iRequestStatus = NULL; |
|
162 } |
|
163 } |
|
164 } |
|
165 |
|
166 // ---------------------------------------------------------------------------- |
|
167 // Show query or queue it. |
|
168 // ---------------------------------------------------------------------------- |
|
169 // |
|
170 EXPORT_C TInt CUsbPersonalityNotifier::ShowQuery( TUid aNotifierUid, |
|
171 const TDesC8 &aBuffer, TDes8 &aResponse, |
|
172 MUsbNotifierCallBack* aCallBack, TRequestStatus* aStatus ) |
|
173 { |
|
174 LOG_FUNC |
|
175 |
|
176 TInt ret = KErrNone; |
|
177 |
|
178 if( aStatus ) |
|
179 { |
|
180 // set to pending |
|
181 *aStatus = KRequestPending; |
|
182 } |
|
183 |
|
184 if( iState == EUsbPersonalityNotifierIdle ) |
|
185 { |
|
186 // no request pending, don't que the requests |
|
187 ret = DoShowQuery( aCallBack, aNotifierUid, aBuffer, aResponse, |
|
188 aStatus ); |
|
189 } |
|
190 else |
|
191 { |
|
192 // request pending, put request to the queue |
|
193 TNotifierClient* ptr; |
|
194 |
|
195 if( (ptr = new TNotifierClient( aCallBack, aNotifierUid, aBuffer, |
|
196 aResponse, aStatus, ETrue ) ) == NULL ) |
|
197 { |
|
198 return KErrGeneral; |
|
199 } |
|
200 |
|
201 iNotifierClient.Append(ptr); |
|
202 } |
|
203 |
|
204 return ret; |
|
205 } |
|
206 |
|
207 // ---------------------------------------------------------------------------- |
|
208 // Show note or queue it. |
|
209 // ---------------------------------------------------------------------------- |
|
210 // |
|
211 EXPORT_C TInt CUsbPersonalityNotifier::ShowNote( TUid aNotifierUid, |
|
212 const TDesC8 &aBuffer, TDes8 &aResponse ) |
|
213 { |
|
214 LOG_FUNC |
|
215 |
|
216 TInt ret = KErrNone; |
|
217 |
|
218 if( EUsbPersonalityNotifierIdle == iState ) |
|
219 { |
|
220 // no request pending, don't que the requests |
|
221 ret = DoShowNote( aNotifierUid, aBuffer, aResponse ); |
|
222 } |
|
223 else |
|
224 { |
|
225 // request pending, put request to the queue |
|
226 TNotifierClient* ptr; |
|
227 |
|
228 if( ( ptr = new TNotifierClient( NULL, aNotifierUid, aBuffer, |
|
229 aResponse, NULL, EFalse ) ) == NULL ) |
|
230 { |
|
231 return KErrGeneral; |
|
232 } |
|
233 |
|
234 iNotifierClient.Append( ptr ); |
|
235 } |
|
236 |
|
237 return ret; |
|
238 } |
|
239 |
|
240 // ---------------------------------------------------------------------------- |
|
241 // Cancel currently on going query and all queued gueries and notes. |
|
242 // ---------------------------------------------------------------------------- |
|
243 // |
|
244 EXPORT_C void CUsbPersonalityNotifier::CancelAll() |
|
245 { |
|
246 LOG_FUNC |
|
247 |
|
248 Cancel(); |
|
249 |
|
250 for (TInt i = 0; i < iNotifierClient.Count(); i++ ) |
|
251 { |
|
252 LOG( "Deleting client entry" ); |
|
253 |
|
254 if( iNotifierClient[i]->iRequestStatus ) |
|
255 { |
|
256 LOG( "Completing request" ); |
|
257 User::RequestComplete( iNotifierClient[i]->iRequestStatus, |
|
258 KErrCancel ); |
|
259 } |
|
260 |
|
261 delete iNotifierClient[i]; |
|
262 iNotifierClient[i] = NULL; |
|
263 } |
|
264 |
|
265 iNotifierClient.Reset(); |
|
266 |
|
267 } |
|
268 |
|
269 // ---------------------------------------------------------------------------- |
|
270 // Cancel specific query. |
|
271 // ---------------------------------------------------------------------------- |
|
272 // |
|
273 EXPORT_C void CUsbPersonalityNotifier::CancelQuery( TUid aNotifierUid ) |
|
274 { |
|
275 LOG_FUNC |
|
276 |
|
277 TBool done = EFalse; |
|
278 TInt i = 0; |
|
279 |
|
280 if( iNotifierUid == aNotifierUid ) |
|
281 { |
|
282 Cancel(); |
|
283 } |
|
284 |
|
285 while( !done ) |
|
286 { |
|
287 for( i = 0; i < iNotifierClient.Count(); i++ ) |
|
288 { |
|
289 LOG1( "CancelQuery i = %d", i ); |
|
290 |
|
291 if(iNotifierClient[i]->iNotifierUid == aNotifierUid) |
|
292 { |
|
293 LOG( "Uid match" ); |
|
294 if(iNotifierClient[i]->iRequestStatus) |
|
295 { |
|
296 User::RequestComplete(iNotifierClient[i]->iRequestStatus, |
|
297 KErrCancel); |
|
298 } |
|
299 |
|
300 delete iNotifierClient[i]; |
|
301 iNotifierClient.Remove(i); |
|
302 break; |
|
303 } |
|
304 } |
|
305 |
|
306 if( i >= iNotifierClient.Count() ) |
|
307 { |
|
308 done = ETrue; |
|
309 } |
|
310 } |
|
311 } |
|
312 |
|
313 // ---------------------------------------------------------------------------- |
|
314 // Cancel all other queued gueries and notes but the current. |
|
315 // ---------------------------------------------------------------------------- |
|
316 // |
|
317 EXPORT_C void CUsbPersonalityNotifier::CancelAllButCurrent() |
|
318 { |
|
319 LOG_FUNC |
|
320 |
|
321 if( iNotifierClient.Count() > 0 ) |
|
322 { |
|
323 //The index 0 is the current, which is not deleted. |
|
324 for( TInt i = 1; i < iNotifierClient.Count(); i++ ) |
|
325 { |
|
326 LOG( "Deleting client entry" ); |
|
327 |
|
328 if( iNotifierClient[i]->iRequestStatus ) |
|
329 { |
|
330 LOG( "Completing request" ); |
|
331 User::RequestComplete( iNotifierClient[i]->iRequestStatus, |
|
332 KErrCancel); |
|
333 } |
|
334 |
|
335 delete iNotifierClient[i]; |
|
336 } |
|
337 |
|
338 //Remove all but the 1st |
|
339 TNotifierClient* ptr = iNotifierClient[0]; |
|
340 iNotifierClient.Reset(); |
|
341 iNotifierClient.Append( ptr ); |
|
342 } |
|
343 } |
|
344 |
|
345 // ---------------------------------------------------------------------------- |
|
346 // Return ETrue, if the notifier with the UID is currently showing. |
|
347 // DEPRICATED |
|
348 // ---------------------------------------------------------------------------- |
|
349 // |
|
350 EXPORT_C TBool CUsbPersonalityNotifier::IsShowing( TUid aNotifierUid ) |
|
351 { |
|
352 LOG_FUNC |
|
353 |
|
354 return ( ( iState == EUsbPersonalityNotifierStarted ) |
|
355 && ( iNotifierUid == aNotifierUid) ); |
|
356 } |
|
357 |
|
358 // ---------------------------------------------------------------------------- |
|
359 // Implementation for showing notes. |
|
360 // ---------------------------------------------------------------------------- |
|
361 // |
|
362 TInt CUsbPersonalityNotifier::DoShowNote( TUid aNotifierUid, |
|
363 const TDesC8 &aBuffer, TDes8 &aResponse ) |
|
364 { |
|
365 LOG_FUNC |
|
366 |
|
367 TInt ret = KErrNone; |
|
368 |
|
369 iCallBack = NULL; |
|
370 iNotifierUid = aNotifierUid; |
|
371 iRequestStatus = NULL; |
|
372 |
|
373 // initializations |
|
374 ret = iNotifier.Connect(); |
|
375 |
|
376 if( ret != KErrNone ) |
|
377 { |
|
378 LOG1( "ERROR: RNotifier::Connect = %d", ret ); |
|
379 return ret; |
|
380 } |
|
381 |
|
382 ret = iNotifier.StartNotifier( aNotifierUid, aBuffer, aResponse ); |
|
383 |
|
384 if( ret != KErrNone ) |
|
385 { |
|
386 LOG1( "ERROR: StartNotifier() failed. Code: %d", ret ); |
|
387 } |
|
388 |
|
389 TRequestStatus* status = &iStatus; |
|
390 User::RequestComplete( status, ret ); |
|
391 SetActive(); |
|
392 iState = EUsbPersonalityNotifierStarted; |
|
393 |
|
394 return ret; |
|
395 } |
|
396 |
|
397 // ---------------------------------------------------------------------------- |
|
398 // Implementation for showing queries. |
|
399 // ---------------------------------------------------------------------------- |
|
400 // |
|
401 TInt CUsbPersonalityNotifier::DoShowQuery( MUsbNotifierCallBack* aCallBack, |
|
402 TUid aNotifierUid, const TDesC8 &aBuffer, TDes8 &aResponse, |
|
403 TRequestStatus* aStatus ) |
|
404 { |
|
405 LOG_FUNC |
|
406 |
|
407 TInt ret; |
|
408 |
|
409 iCallBack = aCallBack; |
|
410 iNotifierUid = aNotifierUid; |
|
411 iRequestStatus = aStatus; |
|
412 |
|
413 if( ( ret = iNotifier.Connect() ) != KErrNone ) |
|
414 { |
|
415 LOG( "ERROR in notifier connection!" ); |
|
416 return ret; |
|
417 } |
|
418 |
|
419 iNotifier.StartNotifierAndGetResponse( iStatus, aNotifierUid, aBuffer, |
|
420 aResponse ); |
|
421 SetActive(); |
|
422 iState = EUsbPersonalityNotifierStarted; |
|
423 |
|
424 return ret; |
|
425 } |
|
426 |
|
427 // ---------------------------------------------------------------------------- |
|
428 // Constructor of TNotifierClient |
|
429 // ---------------------------------------------------------------------------- |
|
430 // |
|
431 CUsbPersonalityNotifier::TNotifierClient::TNotifierClient( |
|
432 MUsbNotifierCallBack* aCallBack, TUid aNotifierUid, |
|
433 const TDesC8 &aBuffer, TDes8 &aResponse, TRequestStatus* aStatus, |
|
434 TBool aConfirmation ) |
|
435 : iCallBack( aCallBack ) |
|
436 , iNotifierUid( aNotifierUid ) |
|
437 , iBuffer( aBuffer ) |
|
438 , iResponse( aResponse ) |
|
439 , iRequestStatus( aStatus ) |
|
440 , iConfirmation( aConfirmation ) |
|
441 { |
|
442 LOG_FUNC |
|
443 |
|
444 } |
|
445 |
|
446 // End of file |
|