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