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