1 /* |
|
2 * Copyright (c) 2002-2007 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: Service starter implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "BTServiceStarter.h" |
|
22 #include "BTSUDebug.h" |
|
23 #include "BTSOPPController.h" |
|
24 #include "BTSBIPController.h" |
|
25 #include "BTSBPPController.h" |
|
26 |
|
27 #include <obexutilsmessagehandler.h> |
|
28 #include <featmgr.h> |
|
29 #include <hbdevicenotificationdialogsymbian.h> |
|
30 #include <hbtextresolversymbian.h> |
|
31 |
|
32 // CONSTANTS |
|
33 |
|
34 // From BT SIG - Assigned numbers |
|
35 const TUint KBTServiceOPPSending = 0x1105; |
|
36 const TUint KBTServiceDirectPrinting = 0x1118; |
|
37 const TUint KBTServiceImagingResponder = 0x111B; |
|
38 |
|
39 const TUint KBTProgressInterval = 1000000; |
|
40 |
|
41 const TUid KUidMsgTypeBt = {0x10009ED5}; |
|
42 //todo need to find a suitable header to include. This is from obexutilslayer.h |
|
43 |
|
44 const TInt KMaxDesCLength = 256; |
|
45 |
|
46 |
|
47 //_LIT(KSendingDialog,"com.nokia.hb.btdevicedialog/1.0"); |
|
48 |
|
49 _LIT(KLocFileName, "btdialogs_"); |
|
50 _LIT(KPath, "z:/resource/qt/translations/"); |
|
51 |
|
52 _LIT(KFilesSentText, "txt_bt_dpophead_all_files_sent");//All files sent |
|
53 _LIT(KDeviceText,"txt_bt_dpopinfo_sent_to_1"); |
|
54 //_LIT(KNotConnectedText,"txt_bt_info_unable_to_connect_with_bluetooth"); |
|
55 _LIT(KSendingFailedText,"txt_bt_dpophead_sending_failed"); |
|
56 |
|
57 // ============================ MEMBER FUNCTIONS =============================== |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CBTServiceStarter::CBTServiceStarter |
|
61 // C++ default constructor can NOT contain any code, that |
|
62 // might leave. |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 CBTServiceStarter::CBTServiceStarter() |
|
66 : CActive( CActive::EPriorityStandard ), |
|
67 iBTEngDiscovery(NULL), |
|
68 iService( EBTSendingService ), |
|
69 iServiceStarted( EFalse ), |
|
70 iMessageServerIndex(0), |
|
71 iBytesSendWithBIP(0), |
|
72 iProgressDialogActive(EFalse), |
|
73 iUserCancel(EFalse), |
|
74 iFeatureManagerInitialized(EFalse), |
|
75 iTriedBIP(EFalse), |
|
76 iTriedOPP(EFalse) |
|
77 { |
|
78 CActiveScheduler::Add( this ); |
|
79 } |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // CBTServiceStarter::ConstructL |
|
83 // Symbian 2nd phase constructor can leave. |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 void CBTServiceStarter::ConstructL() |
|
87 { |
|
88 FLOG(_L("[BTSU]\t CBTServiceStarter::ConstructL()")); |
|
89 iDevice = CBTDevice::NewL(); |
|
90 iDialog = CObexUtilsDialog::NewL( this ); |
|
91 iDelayedDestroyer = CBTServiceDelayedDestroyer::NewL(CActive::EPriorityStandard); |
|
92 FeatureManager::InitializeLibL(); |
|
93 iFeatureManagerInitialized = ETrue; |
|
94 iLocalisationInit = HbTextResolverSymbian::Init(KLocFileName, KPath); |
|
95 FLOG(_L("[BTSU]\t CBTServiceStarter::ConstructL() completed")); |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CBTServiceStarter::NewL |
|
100 // Two-phased constructor. |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 CBTServiceStarter* CBTServiceStarter::NewL() |
|
104 { |
|
105 CBTServiceStarter* self = new( ELeave ) CBTServiceStarter(); |
|
106 CleanupStack::PushL( self ); |
|
107 self->ConstructL(); |
|
108 CleanupStack::Pop(); |
|
109 return self; |
|
110 } |
|
111 |
|
112 CBTServiceStarter::~CBTServiceStarter() |
|
113 { |
|
114 FLOG(_L("[BTSU]\t CBTServiceStarter::Destructor()")); |
|
115 if ( iMessageServerIndex != 0 ) |
|
116 { |
|
117 TRAPD( notUsedRetVal, TObexUtilsMessageHandler::DeleteOutboxEntryL( iMessageServerIndex ) ); |
|
118 notUsedRetVal=notUsedRetVal; |
|
119 FTRACE(FPrint(_L("[BTSU]\t ~CBTServiceStarter() delete ob entry %d"), notUsedRetVal ) ); |
|
120 } |
|
121 StopTransfer(KErrCancel); // Cancels active object |
|
122 |
|
123 delete iList; |
|
124 delete iDevice; |
|
125 |
|
126 delete iController; |
|
127 delete iBTEngDiscovery; |
|
128 delete iDialog; |
|
129 delete iDelayedDestroyer; |
|
130 |
|
131 if(iWaiter && iWaiter->IsStarted() ) |
|
132 { |
|
133 iWaiter->AsyncStop(); |
|
134 } |
|
135 delete iBTEngSettings; |
|
136 |
|
137 if ( iFeatureManagerInitialized ) |
|
138 { |
|
139 FeatureManager::UnInitializeLib(); |
|
140 } |
|
141 |
|
142 FLOG(_L("[BTSU]\t CBTServiceStarter::Destructor() completed")); |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CBTServiceStarter::StartServiceL |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 void CBTServiceStarter::StartServiceL( TBTServiceType aService, |
|
150 CBTServiceParameterList* aList, |
|
151 CActiveSchedulerWait* aWaiter ) |
|
152 { |
|
153 FLOG(_L("[BTSU]\t CBTServiceStarter::StartServiceL()")); |
|
154 |
|
155 // Delete old list and take ownership of the new one |
|
156 // |
|
157 |
|
158 delete iList; |
|
159 iList = aList; |
|
160 |
|
161 if ( iServiceStarted ) |
|
162 { |
|
163 User::Leave( KErrInUse ); |
|
164 } |
|
165 if ( !ValidParameters( aService, aList ) ) |
|
166 { |
|
167 User::Leave( KErrArgument ); |
|
168 } |
|
169 |
|
170 // Store the waiter pointer, a NULL value is also accepted |
|
171 // |
|
172 iWaiter = aWaiter; |
|
173 |
|
174 // Store the requested service |
|
175 // |
|
176 iService = aService; |
|
177 |
|
178 if( !iBTEngSettings ) |
|
179 { |
|
180 iBTEngSettings = CBTEngSettings::NewL( this ); |
|
181 } |
|
182 TBTPowerStateValue power = EBTPowerOff; |
|
183 User::LeaveIfError( iBTEngSettings->GetPowerState( power ) ); |
|
184 TBool offline = EFalse; |
|
185 if( !power ) |
|
186 { |
|
187 //offline = CheckOfflineModeL(); |
|
188 offline = EFalse; |
|
189 } |
|
190 if( !offline ) |
|
191 { |
|
192 FLOG(_L("[BTSU]\t CBTServiceStarter::StartServiceL() Phone is online, request temporary power on.")); |
|
193 TurnBTPowerOnL( power ); |
|
194 } |
|
195 |
|
196 FLOG(_L("[BTSU]\t CBTServiceStarter::StartServiceL() completed")); |
|
197 } |
|
198 |
|
199 |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // CBTServiceStarter::ControllerComplete |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 void CBTServiceStarter::ControllerComplete( TInt aStatus ) |
|
206 { |
|
207 FLOG(_L("[BTSU]\t CBTServiceStarter::ControllerComplete()")); |
|
208 TInt error; |
|
209 if ( iAllSend ) //stop transfer if everything is send |
|
210 { |
|
211 StopTransfer( aStatus ); |
|
212 return; |
|
213 } |
|
214 if(( aStatus==KErrNone || aStatus==EBTSNoError ) && |
|
215 iState == EBTSStarterFindingBIP ) |
|
216 { |
|
217 iBytesSendWithBIP=0; |
|
218 if( iProgressGetter ) |
|
219 { |
|
220 iBytesSendWithBIP=iProgressGetter->GetProgressStatus(); |
|
221 iProgressGetter=NULL; |
|
222 delete iController; |
|
223 iController = NULL; |
|
224 } |
|
225 if ( !iBTEngDiscovery ) |
|
226 { |
|
227 TRAPD(err, iBTEngDiscovery = CBTEngDiscovery::NewL(this) ); |
|
228 if (err != KErrNone ) |
|
229 { |
|
230 StopTransfer(EBTSPuttingFailed); |
|
231 return; |
|
232 } |
|
233 } |
|
234 error=iBTEngDiscovery->RemoteProtocolChannelQuery(iDevice->BDAddr(), |
|
235 TUUID(KBTServiceOPPSending)); |
|
236 if( error == KErrNone ) |
|
237 { |
|
238 iState = EBTSStarterFindingOPP; |
|
239 } |
|
240 else |
|
241 { |
|
242 StopTransfer(EBTSPuttingFailed); |
|
243 } |
|
244 } |
|
245 else |
|
246 { |
|
247 StopTransfer( aStatus ); |
|
248 } |
|
249 FLOG(_L("[BTSU]\t CBTServiceStarter::ControllerComplete() completed")); |
|
250 } |
|
251 |
|
252 // ----------------------------------------------------------------------------- |
|
253 // CBTServiceStarter::GetProgressStatus |
|
254 // ----------------------------------------------------------------------------- |
|
255 // |
|
256 TInt CBTServiceStarter::GetProgressStatus() |
|
257 { |
|
258 if ( iProgressGetter ) |
|
259 { |
|
260 return iProgressGetter->GetProgressStatus()+iBytesSendWithBIP; |
|
261 } |
|
262 else |
|
263 { |
|
264 return iBytesSendWithBIP; |
|
265 } |
|
266 } |
|
267 |
|
268 |
|
269 // ----------------------------------------------------------------------------- |
|
270 // CBTServiceStarter::ValidParameters |
|
271 // ----------------------------------------------------------------------------- |
|
272 // |
|
273 TBool CBTServiceStarter::ValidParameters( |
|
274 TBTServiceType aService, const CBTServiceParameterList* aList) const |
|
275 { |
|
276 FLOG(_L("[BTSU]\t CBTServiceStarter::ValidParameters()")); |
|
277 |
|
278 TBool result = EFalse; |
|
279 |
|
280 if ( aList != NULL ) |
|
281 { |
|
282 switch ( aService ) |
|
283 { |
|
284 case EBTSendingService: |
|
285 { |
|
286 // Sending service must have object or image parameters |
|
287 // |
|
288 if ( aList->ObjectCount() > 0 || aList->ImageCount() > 0 ) |
|
289 { |
|
290 result = ETrue; |
|
291 } |
|
292 break; |
|
293 } |
|
294 case EBTPrintingService: |
|
295 { |
|
296 // Printing service must have xhtml parameters |
|
297 // |
|
298 if ( aList->XhtmlCount() > 0 ) |
|
299 { |
|
300 result = ETrue; |
|
301 } |
|
302 break; |
|
303 } |
|
304 case EBTObjectPushService: |
|
305 { |
|
306 // Sending service must have object or image parameters |
|
307 // |
|
308 if ( aList->ObjectCount() > 0 || aList->ImageCount() > 0 ) |
|
309 { |
|
310 result = ETrue; |
|
311 } |
|
312 break; |
|
313 } |
|
314 default: |
|
315 { |
|
316 result = EFalse; |
|
317 break; |
|
318 } |
|
319 } |
|
320 } |
|
321 FTRACE(FPrint(_L("[BTSU]\t CBTServiceStarter::ValidParameters() completed with %d"), result ) ); |
|
322 |
|
323 return result; |
|
324 } |
|
325 |
|
326 // ----------------------------------------------------------------------------- |
|
327 // CBTServiceStarter::StartProfileSelectL |
|
328 // ----------------------------------------------------------------------------- |
|
329 // |
|
330 void CBTServiceStarter::StartProfileSelectL( TBTServiceType aService ) |
|
331 { |
|
332 FLOG(_L("[BTSU]\t CBTServiceStarter::StartProfileSelectL()")); |
|
333 LaunchWaitNoteL(); |
|
334 iAllSend=EFalse; |
|
335 iSendToBIPOnlyDevice = EFalse; |
|
336 |
|
337 if ( !iBTEngDiscovery ) |
|
338 { |
|
339 iBTEngDiscovery = CBTEngDiscovery::NewL(this); |
|
340 } |
|
341 |
|
342 if ( !FeatureManager::FeatureSupported( KFeatureIdBtImagingProfile ) && (aService != EBTPrintingService) ) |
|
343 { |
|
344 // If BTimagingProfile is disabled, use OPP instead. |
|
345 User::LeaveIfError( iBTEngDiscovery->RemoteProtocolChannelQuery(iDevice->BDAddr(), |
|
346 TUUID(KBTServiceOPPSending))); |
|
347 iState = EBTSStarterFindingOPP; |
|
348 return; |
|
349 } |
|
350 |
|
351 switch ( aService ) |
|
352 { |
|
353 case EBTSendingService: // Find OPP |
|
354 { |
|
355 if ( iList->ObjectCount() > 0 ) // We try to send files with OPP profile as long as it contains non-bip objects |
|
356 { |
|
357 FLOG(_L("[BTSU]\t CBTServiceStarter::StartProfileSelectL() OPP")); |
|
358 User::LeaveIfError( iBTEngDiscovery->RemoteProtocolChannelQuery(iDevice->BDAddr(), |
|
359 TUUID(KBTServiceOPPSending))); |
|
360 iState = EBTSStarterFindingOPP; |
|
361 } |
|
362 else if(iList->ObjectCount() == 0 && iList->ImageCount() > 0) |
|
363 { |
|
364 FLOG(_L("[BTSU]\t CBTServiceStarter::StartProfileSelectL() BIP")); |
|
365 User::LeaveIfError( iBTEngDiscovery->RemoteProtocolChannelQuery(iDevice->BDAddr(), |
|
366 TUUID(KBTServiceImagingResponder))); |
|
367 iState = EBTSStarterFindingBIP; |
|
368 } |
|
369 break; |
|
370 } |
|
371 case EBTPrintingService: // Find BPP |
|
372 { |
|
373 FLOG(_L("[BTSU]\t CBTServiceStarter::StartProfileSelectL() BPP")); |
|
374 User::LeaveIfError( iBTEngDiscovery->RemoteProtocolChannelQuery(iDevice->BDAddr(), |
|
375 TUUID(KBTServiceDirectPrinting))); |
|
376 iState = EBTSStarterFindingBPP; |
|
377 break; |
|
378 } |
|
379 case EBTObjectPushService: // Find BIP |
|
380 { |
|
381 FLOG(_L("[BTSU]\t CBTServiceStarter::StartProfileSelectL() BIP")); |
|
382 User::LeaveIfError( iBTEngDiscovery->RemoteProtocolChannelQuery(iDevice->BDAddr(), |
|
383 TUUID(KBTServiceOPPSending))); |
|
384 iState = EBTSStarterFindingOPP; |
|
385 break; |
|
386 } |
|
387 default: |
|
388 { |
|
389 FLOG(_L("[BTSU]\t CBTServiceStarter::StartProfileSelectL() ERROR, unhandled case")); |
|
390 break; |
|
391 } |
|
392 } |
|
393 |
|
394 FLOG(_L("[BTSU]\t CBTServiceStarter::StartProfileSelectL() completed")); |
|
395 } |
|
396 |
|
397 |
|
398 // ----------------------------------------------------------------------------- |
|
399 // CBTServiceStarter::StartProfileL |
|
400 // ----------------------------------------------------------------------------- |
|
401 // |
|
402 void CBTServiceStarter::StartProfileL( TBTServiceProfile aProfile ) |
|
403 { |
|
404 FLOG(_L("[BTSU]\t CBTServiceStarter::StartProfileL()")); |
|
405 |
|
406 switch ( aProfile ) |
|
407 { |
|
408 case EBTSBPP: |
|
409 { |
|
410 iController = CBTSBPPController::NewL( this, iClientChannel, |
|
411 iDevice->BDAddr(), iList, |
|
412 iBTEngDiscovery ); |
|
413 break; |
|
414 } |
|
415 case EBTSOPP: |
|
416 { |
|
417 iController = CBTSOPPController::NewL( this, iClientChannel, |
|
418 iDevice->BDAddr(), iList ); |
|
419 break; |
|
420 } |
|
421 case EBTSBIP: |
|
422 { |
|
423 iController = CBTSBIPController::NewL( this, iClientChannel, |
|
424 iDevice->BDAddr(), iList ); |
|
425 break; |
|
426 } |
|
427 case EBTSNone: |
|
428 default: |
|
429 { |
|
430 FLOG(_L("[BTSU]\t CBTServiceStarter::StartProfileL() ERROR, unhandled case")); |
|
431 break; |
|
432 } |
|
433 } |
|
434 |
|
435 FLOG(_L("[BTSU]\t CBTServiceStarter::StartProfileL() completed")); |
|
436 } |
|
437 |
|
438 // ----------------------------------------------------------------------------- |
|
439 // CBTServiceStarter::LaunchWaitNoteL |
|
440 // ----------------------------------------------------------------------------- |
|
441 // |
|
442 void CBTServiceStarter::LaunchWaitNoteL() |
|
443 { |
|
444 FLOG(_L("[BTSU]\t CBTServiceStarter::LaunchWaitNoteL()")); |
|
445 if ( iService == EBTPrintingService ) |
|
446 { |
|
447 // iDialog->LaunchWaitDialogL( R_BT_PRINTING_WAIT_NOTE ); |
|
448 } |
|
449 else |
|
450 { |
|
451 //todo need to do the localisation here |
|
452 _LIT(KConnectText, "Connecting..."); |
|
453 iDialog->LaunchWaitDialogL(KConnectText); |
|
454 |
|
455 } |
|
456 FLOG(_L("[BTSU]\t CBTServiceStarter::LaunchWaitNoteL() completed")); |
|
457 } |
|
458 |
|
459 // ----------------------------------------------------------------------------- |
|
460 // CBTServiceStarter::CancelWaitNote |
|
461 // ----------------------------------------------------------------------------- |
|
462 // |
|
463 void CBTServiceStarter::CancelWaitNote() |
|
464 { |
|
465 FLOG(_L("[BTSU]\t CBTServiceStarter::CancelWaitNote()")); |
|
466 |
|
467 if ( iDialog ) |
|
468 { |
|
469 iDialog->CancelWaitDialog(); |
|
470 } |
|
471 |
|
472 FLOG(_L("[BTSU]\t CBTServiceStarter::CancelWaitNote() completed")); |
|
473 } |
|
474 |
|
475 |
|
476 // ----------------------------------------------------------------------------- |
|
477 // CBTServiceStarter::LaunchProgressNoteL |
|
478 // ----------------------------------------------------------------------------- |
|
479 // |
|
480 //todo reusing the second param aTotalSize to aFileCount as it is no longer used check it being used in other places |
|
481 void CBTServiceStarter::LaunchProgressNoteL( MBTServiceProgressGetter* aGetter, |
|
482 TInt aFileCount) |
|
483 { |
|
484 FLOG(_L("[BTSU]\t CBTServiceStarter::LaunchProgressNoteL()")); |
|
485 RBuf deviceName; |
|
486 if ( iService != EBTPrintingService ) |
|
487 { |
|
488 iProgressGetter = aGetter; |
|
489 CancelWaitNote(); |
|
490 |
|
491 if ( !iProgressDialogActive ) |
|
492 { |
|
493 // todo need to change the last parameter because we are now using the textmap id which is a string |
|
494 // whether we replace it with that or remove the parameter is to be decided |
|
495 iMessageServerIndex = TObexUtilsMessageHandler::CreateOutboxEntryL( |
|
496 KUidMsgTypeBt, 0 ); |
|
497 |
|
498 deviceName.CreateL(KMaxDesCLength); |
|
499 |
|
500 if ( iDevice->IsValidFriendlyName() ) |
|
501 { |
|
502 deviceName.Copy( iDevice->FriendlyName() ); |
|
503 } |
|
504 else |
|
505 { |
|
506 deviceName.Copy( BTDeviceNameConverter::ToUnicodeL(iDevice->DeviceName())); |
|
507 } |
|
508 iDialog->LaunchProgressDialogL( this, aFileCount, |
|
509 deviceName, KBTProgressInterval ); |
|
510 deviceName.Close(); |
|
511 } |
|
512 iProgressDialogActive=ETrue; |
|
513 } |
|
514 |
|
515 FLOG(_L("[BTSU]\t CBTServiceStarter::LaunchProgressNoteL() completed")); |
|
516 } |
|
517 |
|
518 // ----------------------------------------------------------------------------- |
|
519 // CBTServiceStarter::UpdateProgressNoteL |
|
520 // ----------------------------------------------------------------------------- |
|
521 // |
|
522 void CBTServiceStarter::UpdateProgressNoteL(TInt aFileSize,TInt aFileIndex, const TDesC& aFileName ) |
|
523 { |
|
524 |
|
525 iDialog->UpdateProgressNoteL(aFileSize,aFileIndex,aFileName); |
|
526 } |
|
527 |
|
528 // ----------------------------------------------------------------------------- |
|
529 // CBTServiceStarter::CancelProgressNote |
|
530 // ----------------------------------------------------------------------------- |
|
531 // |
|
532 void CBTServiceStarter::CancelProgressNote() |
|
533 { |
|
534 FLOG(_L("[BTSU]\t CBTServiceStarter::CancelProgressNote()")); |
|
535 |
|
536 if ( iDialog ) |
|
537 { |
|
538 iDialog->CancelProgressDialog(); |
|
539 } |
|
540 } |
|
541 |
|
542 // ----------------------------------------------------------------------------- |
|
543 // CBTServiceStarter::DialogDismissed |
|
544 // ----------------------------------------------------------------------------- |
|
545 // |
|
546 void CBTServiceStarter::DialogDismissed(TInt aButtonId ) |
|
547 { |
|
548 FLOG(_L("[BTSU]\t CBTServiceStarter::DialogDismissed()")); |
|
549 if( aButtonId == ECancelButton ) |
|
550 { // this condition is hit for the progress dialog and connecting dialog cancel |
|
551 FLOG(_L("[BTSU]\t CBTServiceStarter::DialogDissmissed(), cancelled by user")); |
|
552 iUserCancel=ETrue; |
|
553 if ( iController ) |
|
554 { |
|
555 iController->Abort(); |
|
556 } |
|
557 else |
|
558 { |
|
559 StopTransfer(KErrCancel); |
|
560 } |
|
561 } |
|
562 else if ( aButtonId == ENoButton ) |
|
563 { |
|
564 // user abortion |
|
565 // |
|
566 iUserCancel = ETrue; |
|
567 StopTransfer( KErrCancel ); |
|
568 CancelWaitNote(); |
|
569 } |
|
570 else //EYesButton |
|
571 {// this condition is hit when user is ok with sending the unsupported images |
|
572 iController->SendUnSupportedFiles(); |
|
573 } |
|
574 FLOG(_L("[BTSU]\t CBTServiceStarter::DialogDismissed() completed")); |
|
575 } |
|
576 |
|
577 // ----------------------------------------------------------------------------- |
|
578 // CBTServiceStarter::ShowErrorNote |
|
579 // ----------------------------------------------------------------------------- |
|
580 // |
|
581 void CBTServiceStarter::ShowErrorNote( TInt aReason ) const |
|
582 { |
|
583 FLOG(_L("[BTSU]\t CBTServiceStarter::ShowErrorNote()")); |
|
584 |
|
585 TBuf<KMaxDesCLength> buf; |
|
586 TPtrC sendTextMapId; |
|
587 |
|
588 if ( iDevice->IsValidFriendlyName() ) |
|
589 { |
|
590 buf.Copy( iDevice->FriendlyName() ); |
|
591 } |
|
592 else |
|
593 { |
|
594 TRAP_IGNORE( buf.Copy( BTDeviceNameConverter::ToUnicodeL(iDevice->DeviceName()))); |
|
595 } |
|
596 |
|
597 |
|
598 switch ( aReason ) |
|
599 { |
|
600 case EBTSNoError: |
|
601 { |
|
602 sendTextMapId.Set(KFilesSentText()); |
|
603 break; |
|
604 } |
|
605 case EBTSConnectingFailed: |
|
606 case EBTSGettingFailed: |
|
607 case EBTSPuttingFailed: |
|
608 case EBTSNoSuitableProfiles: |
|
609 //todo below three enums are not valid and it is not being used at anywhere do we need to have it |
|
610 |
|
611 // case EBTSBIPSomeSend: |
|
612 // case EBTSBIPOneNotSend: |
|
613 // case EBTSBIPNoneSend: |
|
614 default: |
|
615 { |
|
616 sendTextMapId.Set(KSendingFailedText()); |
|
617 break; |
|
618 } |
|
619 } |
|
620 |
|
621 |
|
622 if(iLocalisationInit) |
|
623 { |
|
624 TRAP_IGNORE( |
|
625 HBufC* sendText = HbTextResolverSymbian::LoadLC(sendTextMapId); |
|
626 HBufC* deviceName = HbTextResolverSymbian::LoadLC(KDeviceText,buf); |
|
627 CHbDeviceNotificationDialogSymbian::NotificationL(KNullDesC, deviceName->Des(), sendText->Des()); |
|
628 CleanupStack::PopAndDestroy( deviceName ); |
|
629 CleanupStack::PopAndDestroy( sendText ); |
|
630 ); |
|
631 } |
|
632 else |
|
633 { |
|
634 TRAP_IGNORE(CHbDeviceNotificationDialogSymbian::NotificationL(KNullDesC, KDeviceText(), sendTextMapId)); |
|
635 } |
|
636 FLOG(_L("[BTSU]\t CBTServiceStarter::ShowErrorNote() completed")); |
|
637 } |
|
638 |
|
639 |
|
640 |
|
641 // ----------------------------------------------------------------------------- |
|
642 // CBTServiceStarter::LaunchConfirmationQuery |
|
643 // ----------------------------------------------------------------------------- |
|
644 // |
|
645 void CBTServiceStarter::LaunchConfirmationQuery(const TDesC& aConfirmText) |
|
646 { |
|
647 TRAP_IGNORE(iDialog->LaunchQueryDialogL(aConfirmText )); |
|
648 } |
|
649 |
|
650 // ----------------------------------------------------------------------------- |
|
651 // CBTServiceStarter::StopTransfer |
|
652 // ----------------------------------------------------------------------------- |
|
653 // |
|
654 void CBTServiceStarter::StopTransfer(TInt aError) |
|
655 { |
|
656 |
|
657 FLOG(_L("[BTSU]\t CBTServiceStarter::StopTransfer()")); |
|
658 Cancel(); |
|
659 if( !iUserCancel ) |
|
660 { |
|
661 CancelWaitNote(); |
|
662 CancelProgressNote(); |
|
663 |
|
664 if ( aError != KErrCancel ) |
|
665 { |
|
666 ShowErrorNote( aError ); |
|
667 } |
|
668 } |
|
669 if ( iMessageServerIndex != 0 ) |
|
670 { |
|
671 TRAPD( notUsedRetVal, TObexUtilsMessageHandler::DeleteOutboxEntryL( iMessageServerIndex ) ); |
|
672 notUsedRetVal=notUsedRetVal; |
|
673 iMessageServerIndex=0; |
|
674 FTRACE(FPrint(_L("[BTSU]\t CBTServiceStarter::StopTransfer() delete ob entry %d"), notUsedRetVal ) ); |
|
675 } |
|
676 // Release resources |
|
677 // |
|
678 if ( iList ) |
|
679 { |
|
680 delete iList; |
|
681 iList = NULL; |
|
682 } |
|
683 |
|
684 if ( iController ) |
|
685 { |
|
686 delete iController; |
|
687 iController = NULL; |
|
688 } |
|
689 |
|
690 if ( iNotifier.Handle() ) |
|
691 { |
|
692 iNotifier.Close(); |
|
693 } |
|
694 |
|
695 // Reset states |
|
696 // |
|
697 iServiceStarted = EFalse; |
|
698 if ( iWaiter && iWaiter->IsStarted() ) |
|
699 { |
|
700 iWaiter->AsyncStop(); |
|
701 } |
|
702 |
|
703 iState = EBTSStarterStoppingService; |
|
704 } |
|
705 |
|
706 // ----------------------------------------------------------------------------- |
|
707 // CBTServiceStarter::ConnectTimedOut() |
|
708 // ----------------------------------------------------------------------------- |
|
709 // |
|
710 void CBTServiceStarter::ConnectTimedOut() |
|
711 { |
|
712 FLOG(_L("[BTSU]\t CBTServiceStarter::ConnectTimedOut()")); |
|
713 StopTransfer(EBTSConnectingFailed); |
|
714 FLOG(_L("[BTSU]\t CBTServiceStarter::ConnectTimedOut() completed")); |
|
715 } |
|
716 // ----------------------------------------------------------------------------- |
|
717 // CBTServiceStarter::ServiceSearchComplete() |
|
718 // ----------------------------------------------------------------------------- |
|
719 // |
|
720 void CBTServiceStarter::ServiceSearchComplete( const RSdpRecHandleArray& /*aResult*/, |
|
721 TUint /*aTotalRecordsCount*/, TInt /*aErr */) |
|
722 { |
|
723 FLOG(_L("[BTSU]\t CBTServiceStarter::ServiceSearchComplete()")); |
|
724 } |
|
725 |
|
726 // ----------------------------------------------------------------------------- |
|
727 // CBTServiceStarter::AttributeSearchComplete() |
|
728 // ----------------------------------------------------------------------------- |
|
729 // |
|
730 void CBTServiceStarter::AttributeSearchComplete( TSdpServRecordHandle /*aHandle*/, |
|
731 const RSdpResultArray& /*aAttr*/, |
|
732 TInt /*aErr*/ ) |
|
733 { |
|
734 FLOG(_L("[BTSU]\t CBTServiceStarter::AttributeSearchComplete()")); |
|
735 } |
|
736 // ----------------------------------------------------------------------------- |
|
737 // CBTServiceStarter::ServiceAttributeSearchComplete() |
|
738 // ----------------------------------------------------------------------------- |
|
739 // |
|
740 void CBTServiceStarter::ServiceAttributeSearchComplete( TSdpServRecordHandle /*aHandle*/, |
|
741 const RSdpResultArray& aAttr, |
|
742 TInt aErr ) |
|
743 { |
|
744 FLOG(_L("[BTSU]\t CBTServiceStarter::ServiceAttributeSearchComplete()")); |
|
745 TInt err = KErrNone; |
|
746 if ((aErr==KErrEof || aErr==KErrNone) && aAttr.Count()>0 ) |
|
747 { |
|
748 RSdpResultArray results=aAttr; |
|
749 iBTEngDiscovery->ParseRfcommChannel(results,iClientChannel); |
|
750 |
|
751 iBTEngDiscovery->CancelRemoteSdpQuery(); |
|
752 |
|
753 switch (iState) |
|
754 { |
|
755 case EBTSStarterFindingBIP: |
|
756 { |
|
757 TRAP(err, StartProfileL( EBTSBIP )); |
|
758 iTriedBIP = ETrue; |
|
759 if (err != KErrNone) |
|
760 { |
|
761 StopTransfer(EBTSConnectingFailed); |
|
762 } |
|
763 if ( iSendToBIPOnlyDevice ) |
|
764 { |
|
765 iAllSend = ETrue; |
|
766 } |
|
767 else |
|
768 { |
|
769 if(iList->ObjectCount() == 0) |
|
770 { |
|
771 iAllSend=ETrue; |
|
772 } |
|
773 } |
|
774 break; |
|
775 } |
|
776 case EBTSStarterFindingOPP: |
|
777 { |
|
778 TRAP(err, StartProfileL( EBTSOPP ) ); |
|
779 iTriedOPP = ETrue; |
|
780 if (err != KErrNone) |
|
781 { |
|
782 StopTransfer(EBTSConnectingFailed); |
|
783 } |
|
784 iAllSend=ETrue; |
|
785 break; |
|
786 } |
|
787 case EBTSStarterFindingBPP: |
|
788 { |
|
789 TRAP(err, StartProfileL( EBTSBPP )); |
|
790 if (err != KErrNone) |
|
791 { |
|
792 StopTransfer(EBTSConnectingFailed); |
|
793 } |
|
794 break; |
|
795 } |
|
796 } |
|
797 } |
|
798 else if ( aErr==KErrEof && aAttr.Count()==0 && |
|
799 iState == EBTSStarterFindingBIP && !iTriedBIP ) |
|
800 { |
|
801 iBTEngDiscovery->RemoteProtocolChannelQuery(iDevice->BDAddr(),TUUID(KBTServiceOPPSending)); |
|
802 iState = EBTSStarterFindingOPP; |
|
803 iTriedBIP = ETrue; |
|
804 } |
|
805 else if ( aErr==KErrEof && aAttr.Count()==0 && |
|
806 iState == EBTSStarterFindingOPP && !iTriedOPP && |
|
807 iList->ImageCount() > 0 && |
|
808 FeatureManager::FeatureSupported( KFeatureIdBtImagingProfile ) ) |
|
809 { |
|
810 iSendToBIPOnlyDevice = ETrue; |
|
811 iBTEngDiscovery->RemoteProtocolChannelQuery(iDevice->BDAddr(),TUUID(KBTServiceImagingResponder)); |
|
812 iState = EBTSStarterFindingBIP; |
|
813 iTriedOPP = ETrue; |
|
814 } |
|
815 else if (aErr==KErrNone && aAttr.Count()==0) |
|
816 { |
|
817 // This isn't KErrEof so we aren't done yet, wait for further matches |
|
818 } |
|
819 else |
|
820 { |
|
821 // Set destroyer AO active (destroys CBTEngDiscovery/CBTEngSdpQuery classes). This is done |
|
822 // to ensure that CBTEngDiscovery/CBTEngSdpQuery classes have finished all their activities, |
|
823 // callbacks etc.. Destructing it self is handled in CBTServiceDelayedDestroyer's RunL. |
|
824 iDelayedDestroyer->SetDestructPointer(iBTEngDiscovery); |
|
825 iDelayedDestroyer->GoActive(); |
|
826 // Set iBTEngDiscovery pointer to zero. Pointer doesn't exist CBTServiceStarter point of view anymore. |
|
827 iBTEngDiscovery = NULL; |
|
828 StopTransfer(EBTSConnectingFailed); |
|
829 } |
|
830 FLOG(_L("[BTSU]\t CBTServiceStarter::ServiceAttributeSearchComplete() done")); |
|
831 } |
|
832 // ----------------------------------------------------------------------------- |
|
833 // CBTServiceStarter::DeviceSearchComplete() |
|
834 // ----------------------------------------------------------------------------- |
|
835 // |
|
836 void CBTServiceStarter::DeviceSearchComplete( CBTDevice* /*aDevice*/, TInt aErr ) |
|
837 { |
|
838 FLOG(_L("[BTSU]\t CBTServiceStarter::DeviceSearchComplete()")); |
|
839 FTRACE(FPrint(_L("[BTSU]\t CBTServiceStarter DeviceSearchComplete()aErr = %d"), aErr) ); |
|
840 if ( aErr == KErrNone ) |
|
841 { |
|
842 TRAPD(err, StartProfileSelectL( iService )); |
|
843 if (err != KErrNone ) |
|
844 { |
|
845 StopTransfer(err); |
|
846 } |
|
847 |
|
848 iServiceStarted = ETrue; |
|
849 } |
|
850 else |
|
851 { |
|
852 if ( aErr == KErrCancel ) |
|
853 { |
|
854 iUserCancel=ETrue; |
|
855 } |
|
856 StopTransfer(aErr); |
|
857 } |
|
858 FLOG(_L("[BTSU]\t CBTServiceStarter::DeviceSearchComplete() done")); |
|
859 } |
|
860 |
|
861 // ----------------------------------------------------------------------------- |
|
862 // From class MBTEngSettingsObserver. |
|
863 // Power has changed, start searching for BT devices. |
|
864 // ----------------------------------------------------------------------------- |
|
865 // |
|
866 void CBTServiceStarter::PowerStateChanged( TBTPowerStateValue aState ) |
|
867 { |
|
868 FLOG(_L("[BTSU]\t CBTServiceStarter::PowerStateChanged()")); |
|
869 if( aState == EBTPowerOn && iWaitingForBTPower ) |
|
870 { |
|
871 iWaitingForBTPower = EFalse; |
|
872 TRAP_IGNORE( StartDiscoveryL() ); |
|
873 } |
|
874 FLOG(_L("[BTSU]\t CBTServiceStarter::PowerStateChanged() - completed")); |
|
875 } |
|
876 |
|
877 |
|
878 // ----------------------------------------------------------------------------- |
|
879 // From class MBTEngSettingsObserver. |
|
880 // Visibility has changed, ignore event. |
|
881 // ----------------------------------------------------------------------------- |
|
882 // |
|
883 void CBTServiceStarter::VisibilityModeChanged( TBTVisibilityMode aState ) |
|
884 { |
|
885 (void) aState; |
|
886 } |
|
887 |
|
888 // ----------------------------------------------------------------------------- |
|
889 // Check if the phone is in offline mode, and ask the user if it is. |
|
890 // ----------------------------------------------------------------------------- |
|
891 // |
|
892 TBool CBTServiceStarter::CheckOfflineModeL() |
|
893 { |
|
894 FLOG(_L("[BTSU]\t CBTServiceStarter::CheckOfflineModeL()")); |
|
895 TCoreAppUIsNetworkConnectionAllowed offline = ECoreAppUIsNetworkConnectionNotAllowed; |
|
896 TBTEnabledInOfflineMode offlineAllowed = EBTDisabledInOfflineMode; |
|
897 User::LeaveIfError( iBTEngSettings->GetOfflineModeSettings( offline, offlineAllowed ) ); |
|
898 if( offline == ECoreAppUIsNetworkConnectionNotAllowed && |
|
899 offlineAllowed == EBTEnabledInOfflineMode ) |
|
900 { |
|
901 User::LeaveIfError( iNotifier.Connect() ); |
|
902 TBTGenericQueryNotiferParamsPckg pckg; |
|
903 pckg().iMessageType = EBTActivateOffLineQuery; |
|
904 pckg().iNameExists = EFalse; |
|
905 iActiveNotifier = EOfflineQuery; |
|
906 iNotifier.StartNotifierAndGetResponse( iStatus, KBTGenericQueryNotifierUid, |
|
907 pckg, iOffline ); |
|
908 SetActive(); |
|
909 } |
|
910 else if( offline == ECoreAppUIsNetworkConnectionNotAllowed && |
|
911 offlineAllowed == EBTDisabledInOfflineMode ) |
|
912 { |
|
913 StopTransfer( KErrNotSupported ); |
|
914 } |
|
915 FLOG(_L("[BTSU]\t CBTServiceStarter::CheckOfflineModeL() - completed")); |
|
916 return ( offline == ECoreAppUIsNetworkConnectionNotAllowed ); |
|
917 } |
|
918 |
|
919 |
|
920 // ----------------------------------------------------------------------------- |
|
921 // Start BT device discovery. |
|
922 // ----------------------------------------------------------------------------- |
|
923 // |
|
924 void CBTServiceStarter::StartDiscoveryL() |
|
925 { |
|
926 FLOG(_L("[BTSU]\t CBTServiceStarter::StartDiscoveryL()")); |
|
927 if( !iBTEngDiscovery ) |
|
928 { |
|
929 iBTEngDiscovery = CBTEngDiscovery::NewL(this); |
|
930 } |
|
931 TInt err = iBTEngDiscovery->SearchRemoteDevice(iDevice ); |
|
932 if( err ) |
|
933 { |
|
934 StopTransfer( err ); |
|
935 } |
|
936 FLOG(_L("[BTSU]\t CBTServiceStarter::StartDiscoveryL() - completed")); |
|
937 } |
|
938 |
|
939 |
|
940 // ----------------------------------------------------------------------------- |
|
941 // Turn BT on and start BT device discovery if possible. |
|
942 // ----------------------------------------------------------------------------- |
|
943 // |
|
944 void CBTServiceStarter::TurnBTPowerOnL( const TBTPowerStateValue aState ) |
|
945 { |
|
946 FLOG( _L("[BTSU]\t CBTServiceStarter::TurnBTPowerOnL()") ); |
|
947 // if (iName() != EFalse) |
|
948 { |
|
949 if( !iBTEngSettings ) |
|
950 { |
|
951 iBTEngSettings = CBTEngSettings::NewL( this ); |
|
952 } |
|
953 TInt err = iBTEngSettings->ChangePowerStateTemporarily(); |
|
954 iWaitingForBTPower = ETrue; |
|
955 if( err ) |
|
956 { |
|
957 iWaitingForBTPower = EFalse; |
|
958 StopTransfer( err ); |
|
959 } |
|
960 else if( aState == EBTPowerOn ) |
|
961 { |
|
962 // Power is already on, we just registered for turning it off if needed. |
|
963 // Since there is no callback at this point (power is already on), start |
|
964 // searching straight away. |
|
965 iWaitingForBTPower = EFalse; |
|
966 StartDiscoveryL(); |
|
967 } |
|
968 } |
|
969 /* else |
|
970 { |
|
971 if ( !iNotifier.Handle() ) |
|
972 { |
|
973 User::LeaveIfError( iNotifier.Connect() ); |
|
974 } |
|
975 TBTGenericQueryNotiferParamsPckg pckg; |
|
976 pckg().iMessageType = EBTNameQuery; |
|
977 pckg().iNameExists = EFalse; |
|
978 iActiveNotifier = ENameQuery; |
|
979 iNotifier.StartNotifierAndGetResponse( iStatus, KBTGenericQueryNotifierUid, |
|
980 pckg, iName ); |
|
981 SetActive(); |
|
982 }*/ |
|
983 FLOG(_L("[BTSU]\t CBTServiceStarter::TurnBTPowerOnL() - completed")); |
|
984 } |
|
985 |
|
986 |
|
987 // --------------------------------------------------------------------------- |
|
988 // From class CActive. |
|
989 // Called by the active scheduler when the request has been cancelled. |
|
990 // --------------------------------------------------------------------------- |
|
991 // |
|
992 void CBTServiceStarter::DoCancel() |
|
993 { |
|
994 FLOG(_L("[BTSU]\t CBTServiceStarter::DoCancel()")); |
|
995 iNotifier.CancelNotifier( KBTGenericQueryNotifierUid ); |
|
996 iNotifier.Close(); |
|
997 FLOG(_L("[BTSU]\t CBTServiceStarter::DoCancel() - completed")); |
|
998 } |
|
999 |
|
1000 |
|
1001 // --------------------------------------------------------------------------- |
|
1002 // From class CActive. |
|
1003 // Called by the active scheduler when the request has been completed. |
|
1004 // --------------------------------------------------------------------------- |
|
1005 // |
|
1006 void CBTServiceStarter::RunL() |
|
1007 { |
|
1008 FLOG(_L("[BTSU]\t CBTServiceStarter::RunL()")); |
|
1009 TInt err = iStatus.Int(); |
|
1010 if( !err ) |
|
1011 { |
|
1012 if ( (iActiveNotifier == ENameQuery && iName() != EFalse ) || ( iActiveNotifier == EOfflineQuery && iOffline() != EFalse ) ) |
|
1013 { |
|
1014 TBTPowerStateValue power = EBTPowerOff; |
|
1015 if ( iNotifier.Handle() ) |
|
1016 { |
|
1017 iNotifier.Close(); |
|
1018 } |
|
1019 User::LeaveIfError( iBTEngSettings->GetPowerState( power ) ); |
|
1020 TurnBTPowerOnL( power ); |
|
1021 } |
|
1022 else |
|
1023 { |
|
1024 err = KErrCancel; |
|
1025 } |
|
1026 } |
|
1027 |
|
1028 if( err ) |
|
1029 { |
|
1030 |
|
1031 err = ( err == KErrNotSupported ? KErrCancel : err ); |
|
1032 if ( iWaiter && err != KErrInUse && err != KErrCancel ) |
|
1033 { |
|
1034 err = EBTSPuttingFailed; |
|
1035 } |
|
1036 StopTransfer( err ); |
|
1037 } |
|
1038 |
|
1039 FLOG(_L("[BTSU]\t CBTServiceStarter::RunL() - completed")); |
|
1040 } |
|
1041 |
|
1042 |
|
1043 // --------------------------------------------------------------------------- |
|
1044 // From class CActive. |
|
1045 // Called by the active scheduler when an error in RunL has occurred. |
|
1046 // --------------------------------------------------------------------------- |
|
1047 // |
|
1048 TInt CBTServiceStarter::RunError( TInt aError ) |
|
1049 { |
|
1050 FLOG(_L("[BTSU]\t CBTServiceStarter::RunError()")); |
|
1051 StopTransfer( aError ); |
|
1052 FLOG(_L("[BTSU]\t CBTServiceStarter::RunError() - completed")); |
|
1053 return KErrNone; |
|
1054 } |
|
1055 |
|
1056 |
|
1057 |
|
1058 |
|