bluetoothengine/btnotif/btnotifsrv/src/btnotifbasepairinghandler.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: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include "btnotifsecuritymanager.h"
       
    19 #include "btnotifbasepairinghandler.h"
       
    20 #include "btnotificationmanager.h"
       
    21 #include "bluetoothnotification.h"
       
    22 #include "btnotifconnectiontracker.h"
       
    23 #include "bluetoothtrace.h"
       
    24 
       
    25 // ======== MEMBER FUNCTIONS ========
       
    26 
       
    27 // ---------------------------------------------------------------------------
       
    28 // C++ default constructor
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 CBTNotifBasePairingHandler::CBTNotifBasePairingHandler( CBTNotifSecurityManager& aParent, const TBTDevAddr& aAddr)
       
    32     : iAddr( aAddr ), iParent( aParent )
       
    33     {
       
    34     }
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 // Symbian 2nd-phase constructor
       
    38 // ---------------------------------------------------------------------------
       
    39 //
       
    40 void CBTNotifBasePairingHandler::BaseConstructL( )
       
    41     {
       
    42     iActive = CBtSimpleActive::NewL( *this, 0 );  
       
    43     }
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // Destructor
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 CBTNotifBasePairingHandler::~CBTNotifBasePairingHandler()
       
    50     {
       
    51     delete iActive;
       
    52     }
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // Message passes through only if the result is for the same device this 
       
    56 // object is for.
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 void CBTNotifBasePairingHandler::HandlePairServerResult( const TBTDevAddr& aAddr, TInt aResult )
       
    60     {
       
    61     if ( aAddr == iAddr )
       
    62         {
       
    63          DoHandlePairServerResult( aResult );
       
    64         }
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // Message passes through only if the result is for the same device this 
       
    69 // object is for.
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 void CBTNotifBasePairingHandler::HandleRegistryNewPairedEvent( const TBTNamelessDevice& aDev )
       
    73     {
       
    74     if ( aDev.Address() == iAddr )
       
    75         {
       
    76         DoHandleRegistryNewPairedEvent( aDev );
       
    77         }
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // Default impl of virtual function. do nothing
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 void CBTNotifBasePairingHandler::CancelOutgoingPair()
       
    85     {
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // Default impl does not offer a known PIN code for pairing 
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 void CBTNotifBasePairingHandler::GetPinCode(
       
    93         TBTPinCode& aPin, const TBTDevAddr& aAddr, TInt aMinPinLength )
       
    94     {
       
    95     aPin().iLength = 0;
       
    96     (void) aAddr;
       
    97     (void) aMinPinLength;
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // Invalidate iPairResultSet
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 void CBTNotifBasePairingHandler::UnSetPairResult()
       
   105     {
       
   106     iPairResultSet = EFalse;
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // Save the result and validate the flag
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 void CBTNotifBasePairingHandler::SetPairResult( TInt aResult )
       
   114     {
       
   115     iPairResult = aResult;
       
   116     iPairResultSet = ETrue;
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // Returns the flag
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 TBool CBTNotifBasePairingHandler::IsPairResultSet()
       
   124     {
       
   125     return iPairResultSet;
       
   126     }
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 // Invalidate iPairResultSet
       
   130 // ---------------------------------------------------------------------------
       
   131 //
       
   132 void CBTNotifBasePairingHandler::ShowPairingResultNoteL(TInt aResult)
       
   133     {
       
   134     BOstraceFunctionEntry0( DUMMY_DEVLIST );
       
   135     CBluetoothNotification* notification = 
       
   136             iParent.ConnectionTracker().NotificationManager()->GetNotification();
       
   137     User::LeaveIfNull( notification ); // For OOM exception, leaves with KErrNoMemory
       
   138     TBTDialogResourceId resourceId = EPairingSuccess;
       
   139     if(KErrNone != aResult)
       
   140         {
       
   141         resourceId = EPairingFailureOk;
       
   142         }
       
   143     notification->SetNotificationType( TBluetoothDialogParams::ENote, resourceId );
       
   144     const CBtDevExtension* dev = iParent.BTDevRepository().Device(iAddr);
       
   145     if(dev)
       
   146         {
       
   147         User::LeaveIfError(notification->SetData( TBluetoothDeviceDialog::EDeviceName, dev->Alias()));
       
   148         User::LeaveIfError(notification->SetData( TBluetoothDeviceDialog::EDeviceClass, dev->Device().DeviceClass().DeviceClass()));
       
   149         }
       
   150     else
       
   151         {
       
   152         TBTDeviceName name;
       
   153         iAddr.GetReadable(name);
       
   154         User::LeaveIfError(notification->SetData( TBluetoothDialogParams::EAddress, name ));
       
   155         User::LeaveIfError(notification->SetData( TBluetoothDeviceDialog::EDeviceClass, 0)); // No device class
       
   156         }
       
   157     iParent.ConnectionTracker().NotificationManager()->QueueNotificationL( notification);
       
   158     BOstraceFunctionExit0( DUMMY_DEVLIST );
       
   159     }
       
   160 
       
   161 
       
   162