bluetoothengine/bteng/btengconnman/src/btengpairinghandler.cpp
branchRCL_3
changeset 56 9386f31cc85b
parent 55 613943a21004
child 61 269724087bed
equal deleted inserted replaced
55:613943a21004 56:9386f31cc85b
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of pairing a Bluetooth device.
       
    15 *
       
    16 */
       
    17 #include "btengpairinghandler.h"
       
    18 #include "btengconnman.h"
       
    19 #include "btengactive.h"
       
    20 #include "debug.h"
       
    21 
       
    22 const TInt KPairingRequestId = 60;
       
    23 
       
    24 // ======== MEMBER FUNCTIONS ========
       
    25 
       
    26 // ---------------------------------------------------------------------------
       
    27 // C++ default constructor
       
    28 // ---------------------------------------------------------------------------
       
    29 //
       
    30 CBTEngPairingHandler::CBTEngPairingHandler( MBTEngConnObserver* aObserver, 
       
    31     CBTEngConnMan* aParent )
       
    32 :   iObserver( aObserver ),
       
    33     iParent( aParent )
       
    34     {
       
    35     }
       
    36 
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // Symbian 2nd-phase constructor
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 void CBTEngPairingHandler::ConstructL()
       
    43     {
       
    44     ASSERT( iObserver );
       
    45     iActive = CBTEngActive::NewL( *this, KPairingRequestId, 
       
    46                                    CActive::EPriorityStandard );
       
    47     }
       
    48 
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // NewL
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 CBTEngPairingHandler* CBTEngPairingHandler::NewL( MBTEngConnObserver* aObserver, 
       
    55     CBTEngConnMan* aParent )
       
    56     {
       
    57     CBTEngPairingHandler* self = new( ELeave ) CBTEngPairingHandler( aObserver, 
       
    58                                                                       aParent );
       
    59     CleanupStack::PushL( self );
       
    60     self->ConstructL();
       
    61     CleanupStack::Pop( self );
       
    62     return self;
       
    63     }
       
    64 
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // Destructor
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 CBTEngPairingHandler::~CBTEngPairingHandler()
       
    71     {
       
    72     delete iActive;
       
    73     iBtNotifier.Close();
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // ?implementation_description
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 void CBTEngPairingHandler::StartPairingL( const TBTDevAddr& aAddr, 
       
    81         TBTDeviceClass& aDeviceClass  )
       
    82     {
       
    83     TRACE_FUNC_ENTRY
       
    84     if ( !iBtNotifier.Handle() ) 
       
    85         {
       
    86         User::LeaveIfError( iBtNotifier.Connect() );
       
    87         }
       
    88     iAddr() = aAddr;
       
    89     iCod = aDeviceClass;
       
    90     iBtNotifier.PairDevice( iAddr, iCod.DeviceClass(), iActive->RequestStatus() );
       
    91     iActive->GoActive();
       
    92     TRACE_FUNC_EXIT
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // Cancel a pairing request.
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 void CBTEngPairingHandler::CancelPairing()
       
   100     {
       
   101     TRACE_FUNC_ENTRY
       
   102     if( iActive->IsActive() )
       
   103         {
       
   104         iBtNotifier.CancelPairDevice();
       
   105         iActive->Cancel();
       
   106         }
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // From class MBTEngActiveObserver.
       
   111 // ?implementation_description
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 void CBTEngPairingHandler::RequestCompletedL( CBTEngActive* aActive, 
       
   115     TInt aStatus )
       
   116     {
       
   117     TRACE_FUNC_ARG( ( _L( "status: %d" ), aStatus ) )
       
   118     ASSERT( aActive->RequestId() != 0 );
       
   119     (void) aActive;
       
   120     // Pairing completes, inform client.
       
   121     iObserver->PairingComplete( iAddr(), aStatus );
       
   122     TRACE_FUNC_EXIT
       
   123     }
       
   124 
       
   125 // ---------------------------------------------------------------------------
       
   126 // From class MBTEngActiveObserver.
       
   127 // Handles cancelation of an outstanding request
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 void CBTEngPairingHandler::CancelRequest( TInt aRequestId )
       
   131     {
       
   132     TRACE_FUNC_ARG( ( _L( "reqID %d" ), aRequestId ) );
       
   133     if ( aRequestId == KPairingRequestId )
       
   134         {
       
   135         iBtNotifier.CancelPairDevice();
       
   136         }
       
   137     TRACE_FUNC_EXIT 
       
   138     }
       
   139 
       
   140 // ---------------------------------------------------------------------------
       
   141 // From class MBTEngActiveObserver.
       
   142 // ?implementation_description
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 void CBTEngPairingHandler::HandleError( CBTEngActive* aActive, 
       
   146     TInt aError )
       
   147     {
       
   148     // Our RunL can actually not leave, so we should never reach here.
       
   149     (void) aActive;
       
   150     (void) aError;
       
   151     }
       
   152