bluetoothengine/btnotif/btnotifsrv/inc/btnotifpairnotifier.h
changeset 31 a0ea99b6fa53
child 40 997690c3397a
equal deleted inserted replaced
30:df7a93ede42e 31:a0ea99b6fa53
       
     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 #ifndef BTNOTIFPAIRNOTIFIER_H
       
    19 #define BTNOTIFPAIRNOTIFIER_H
       
    20 
       
    21 #include <e32base.h>
       
    22 #include <btmanclient.h>
       
    23 #include "bluetoothdevicedialogs.h"
       
    24 #include "btnotificationresult.h"
       
    25 #include "bluetoothtrace.h"
       
    26 
       
    27 class CBTNotifPairingManager;
       
    28 class CBTNotifConnectionTracker;
       
    29 class CBluetoothNotification;
       
    30 
       
    31 /**
       
    32  *  Helper class for performing user prompt for pairing and authorization.
       
    33  *  
       
    34  *  The design of this class is focussed on structure and maintainability first.
       
    35  *  Duplicate (state) information is kept to a minimum. And memory usage comes
       
    36  *  before processing. Pairing is an infrequent operation, and this class is
       
    37  *  only instantiated when there is pairing-related processing, so extreme
       
    38  *  focus on memory or processing efficiency would have relatively little effect.
       
    39  *  
       
    40  *  Auth represents Authenticate and Authorize
       
    41  *  
       
    42  *  @since Symbian^4
       
    43  */
       
    44 NONSHARABLE_CLASS( CBTNotifPairNotifier ) : public CBase,
       
    45                                             public MBTNotificationResult
       
    46     {
       
    47 
       
    48 public:
       
    49 
       
    50     /**
       
    51      * Two-phased constructor.
       
    52      * @param aConnection Pointer to the parent.
       
    53      * @param aDevice Pointer to information of the remote device.
       
    54      * aParam The owner of this object
       
    55      */
       
    56     static CBTNotifPairNotifier* NewL( CBTNotifPairingManager& aParent );
       
    57 
       
    58     /**
       
    59     * Destructor.
       
    60     */
       
    61     virtual ~CBTNotifPairNotifier();
       
    62 
       
    63     /**
       
    64      * Handle a notifier request for pairing with the remote device
       
    65      * of this connection.
       
    66      *
       
    67      * @since Symbian^4
       
    68      * @param aMessage The client of this request.
       
    69      */    
       
    70     void StartPairingNotifierL( const RMessage2& aMessage );
       
    71 
       
    72     /**
       
    73      * Update an outstanding request for this connection.
       
    74      *  
       
    75      * @since Symbian^4
       
    76      * @param aUid The UID of the notifier for this update.
       
    77      * @param aParams The updated parameters for this request from the client.
       
    78      */
       
    79     void UpdatePairingNotifierL( TInt aUid, const TDesC8& aParams );
       
    80 
       
    81     /**
       
    82      * Cancel an outstanding request for this connection.
       
    83      *  
       
    84      * @since Symbian^4
       
    85      * @param aUid The UID of the notifier for this pairing request.
       
    86      */
       
    87     void CancelPairingNotifierL( TInt aUid );
       
    88 
       
    89 // from base class MBTNotificationResult
       
    90 
       
    91     /**
       
    92      * From MBTNotificationResult.
       
    93      * Handle an intermediate result from a user query.
       
    94      * This function is called if the user query passes information
       
    95      * back before it has finished i.e. is dismissed. The final acceptance/
       
    96      * denial of a query is passed back in MBRNotificationClosed.
       
    97      *
       
    98      * @since Symbian^4
       
    99      * @param aData the returned data. The actual format 
       
   100      *              is dependent on the actual notifier.
       
   101      */
       
   102     virtual void MBRDataReceived( CHbSymbianVariantMap& aData );
       
   103 
       
   104     /**
       
   105      * From MBTNotificationResult.
       
   106      * The notification is finished. The resulting data (e.g. user input or
       
   107      * acceptance/denial of the query) is passed back here.
       
   108      *
       
   109      * @since Symbian^4
       
   110      * @param aErr KErrNone or one of the system-wide error codes.
       
   111      * @param aData the returned data. The actual format 
       
   112      *              is dependent on the actual notifier.
       
   113      */
       
   114     virtual void MBRNotificationClosed( TInt aError, const TDesC8& aData );
       
   115     
       
   116 private:
       
   117 
       
   118     /**
       
   119      * C++ default constructor.
       
   120      */
       
   121     CBTNotifPairNotifier( CBTNotifPairingManager& aParent );
       
   122 
       
   123     /**
       
   124      * Symbian 2nd-phase constructor.
       
   125      */
       
   126     void ConstructL();
       
   127 
       
   128     void StartPairingUserInputL();
       
   129     
       
   130     /**
       
   131      * Process the user input and complete the outstanding pairing request.
       
   132      *
       
   133      * @since Symbian^4
       
   134      * @param aError The result off the notification.
       
   135      * @param aResult The user response; ETrue if the user accepted the query,
       
   136      *                otherwise EFalse.
       
   137      * @param aData The data returned from the notification dialog.
       
   138      */
       
   139     void CompletePairingNotifierL( TInt aError, TBool aResult, const TDesC8& aData );
       
   140 
       
   141     /**
       
   142      * Ask the user to allow incoming pairing.
       
   143      *
       
   144      * @since Symbian^4
       
   145      */
       
   146     void StartAcceptPairingQueryL();
       
   147 
       
   148     /**
       
   149      * Process the user input and for accepting an incoming pairing and
       
   150      * continue with the outstanding pairing request.
       
   151      *
       
   152      * @since Symbian^4
       
   153      * @param aError The result of the notification.
       
   154      * @param aResult The user response; ETrue if the user accepted the query,
       
   155      *                otherwise EFalse.
       
   156      */
       
   157     void CompleteAcceptPairingQueryL( TInt aError, TBool aResult );
       
   158     
       
   159     /**
       
   160      * Parse the parameters of a request for pairing.
       
   161      * This function also returns values to use for dialog config, and sets
       
   162      * the operation state member variable (iOperation).
       
   163      *
       
   164      * @since Symbian^4
       
   165      */
       
   166     void ParseNotifierReqParamsL();
       
   167 
       
   168     /**
       
   169      * Parse the parameters of a request for pairing using pin query.
       
   170      *
       
   171      * @since Symbian^4
       
   172      * @param aLocallyInitiated On return, will be set to ETrue if the pairing 
       
   173      *                          was initiated by us.
       
   174      * @param aMinPinLength On return, this will contain the minimum passcode length.
       
   175      */
       
   176     void ParseLegacyPinCodeReqParamsL( TBool& aLocallyInitiated, 
       
   177             TInt& aMinPinLength, TBTDevAddr& aAddr );    
       
   178     
       
   179     /**
       
   180      * Parse the parameters of a request for pairing using pin query.
       
   181      *
       
   182      * @since Symbian^4
       
   183      * @param aLocallyInitiated On return, will be set to ETrue if the pairing 
       
   184      *                          was initiated by us.
       
   185      * @param aMinPinLength On return, this will contain the minimum passcode length.
       
   186      */
       
   187     void ParsePinCodeReqParamsL( TBool& aLocallyInitiated, TInt& aMinPinLength,
       
   188             TBTDevAddr& aAddr);
       
   189 
       
   190     /**
       
   191      * Parse the parameters of a request for pairing using numeric comparison.
       
   192      *
       
   193      * @since Symbian^4
       
   194      * @param aLocallyInitiated On return, will be set to ETrue if the pairing 
       
   195      *                          was initiated by us.
       
   196      * @param aNumVal On return, this descriptor will contain the passkey to 
       
   197      *                show to the user.
       
   198      */
       
   199     void ParseNumericCompReqParamsL( TBool& aLocallyInitiated, TDes& aNumVal,
       
   200             TBTDevAddr& aAddr);
       
   201 
       
   202     /**
       
   203      * Parse the parameters of a request for pairing using passkey display.
       
   204      *
       
   205      * @since Symbian^4
       
   206      * @param aLocallyInitiated On return, will be set to ETrue if the pairing 
       
   207      *                          was initiated by us.
       
   208      * @param aNumVal On return, this descriptor will contain the passkey to 
       
   209      *                show to the user.
       
   210      */
       
   211     void ParsePasskeyDisplayReqParamsL( TBool& aLocallyInitiated, TDes& aNumVal,
       
   212             TBTDevAddr& aAddr );
       
   213 
       
   214     /**
       
   215      * Get a notification and configure it according to the current operation.
       
   216      *
       
   217      * @since Symbian^4
       
   218      * @param aType The notification type.
       
   219      * @param aResourceId Identifier for the resource to display.
       
   220      */
       
   221     void PrepareNotificationL( TBluetoothDialogParams::TBTDialogType aType,
       
   222                 TBTDialogResourceId aResourceId );
       
   223 
       
   224     /**
       
   225      * Handle the result from a notification that is finished.
       
   226      *
       
   227      * @since Symbian^4
       
   228      * @param aErr KErrNone or one of the system-wide error codes.
       
   229      * @param aData The returned data. The actual format 
       
   230      *              is dependent on the actual notifier.
       
   231      */
       
   232     void NotificationClosedL( TInt aError, const TDesC8& aData );
       
   233     
       
   234     /**
       
   235      * Ask the user if he/she wants to block future connection requests.
       
   236      *
       
   237      * @since Symbian^4
       
   238      */    
       
   239     void LaunchBlockingQueryL();
       
   240 
       
   241 private: // data
       
   242 
       
   243     enum TNotifierState
       
   244         {
       
   245         EIncomingPairingAcceptconfirm,
       
   246         EPairingInputConfirm,
       
   247         };
       
   248     
       
   249     CBTNotifPairingManager& iParent;
       
   250     
       
   251     /**
       
   252      * The client request.
       
   253      */
       
   254     RMessage2 iNotifierMessage;
       
   255     
       
   256     /**
       
   257      * Buffer containing the parameters of the client message.
       
   258      * Own.
       
   259      */
       
   260     RBuf8 iParams;
       
   261 
       
   262     /**
       
   263      * Pointer to an outstanding user interaction.
       
   264      * Not own.
       
   265      */
       
   266     CBluetoothNotification* iNotification;
       
   267     
       
   268     // will be set to ETrue if the pairing 
       
   269     // was initiated by us.
       
   270     TBool iLocallyInitiated;
       
   271     
       
   272     // contain a number to use in the pairing dialog.
       
   273     TBuf<8> iDialogNumeric;
       
   274     
       
   275     // the dialog type.
       
   276     TBluetoothDialogParams::TBTDialogType iDialog;
       
   277     
       
   278     // the resource id to be loaded to the dialog
       
   279     TBTDialogResourceId iDialogResource;
       
   280     
       
   281     // the address of the device with which the pairing is performed.
       
   282     TBTDevAddr iRemote;
       
   283     
       
   284     // contains the minimum requirements for pin 
       
   285     // code length. -1 indicates this is not PIn code pairing.
       
   286     TInt iMinPinLength;
       
   287     
       
   288     // Contains the device name provided in params
       
   289     TBTDeviceName iCurrentDeviceName;
       
   290     
       
   291     TNotifierState iState;
       
   292     
       
   293     BTUNITTESTHOOK
       
   294 
       
   295     };
       
   296 
       
   297 #endif // BTNOTIFPAIRNOTIFIER_H