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