bluetoothengine/btnotif/btnotifsrv/inc/btnotifconnection.h
changeset 33 837dcc42fd6a
parent 19 43824b19ee35
child 37 91746b151f97
equal deleted inserted replaced
19:43824b19ee35 33:837dcc42fd6a
     1 /*
       
     2 * ============================================================================
       
     3 *  Name        : btnotifconnection.h
       
     4 *  Part of     : bluetoothengine / btnotif
       
     5 *  Description : Class for observing events of a single connection, and for 
       
     6 *                managing any user notifications related to the connection.
       
     7 *
       
     8 *  Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     9 *  All rights reserved.
       
    10 *  This component and the accompanying materials are made available
       
    11 *  under the terms of "Eclipse Public License v1.0"
       
    12 *  which accompanies this distribution, and is available
       
    13 *  at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
    14 *
       
    15 *  Initial Contributors:
       
    16 *  Nokia Corporation - initial contribution.
       
    17 *
       
    18 *  Contributors:
       
    19 *  Nokia Corporation
       
    20 * ============================================================================
       
    21 * Template version: 4.2
       
    22 */
       
    23 
       
    24 #ifndef BTNOTIFCONNECTION_H
       
    25 #define BTNOTIFCONNECTION_H
       
    26 
       
    27 #include <bt_sock.h>
       
    28 #include <btservices/btsimpleactive.h>
       
    29 #include <btengdevman.h>
       
    30 #include <btengconstants.h>
       
    31 
       
    32 #include "bluetoothnotification.h"
       
    33 
       
    34 #include "bluetoothtrace.h"
       
    35 
       
    36 class CBTNotifConnectionTracker;
       
    37 class CBTNotifPairingHelper;
       
    38 
       
    39 /**
       
    40  * Utility function for getting the name of a device to display.
       
    41  *
       
    42  * @since Symbian^4
       
    43  * @param aName On return, will hold the device name to display.
       
    44  * @param aDevice Data dtructure holding the device record.
       
    45  */
       
    46 void GetDeviceNameL( TBTDeviceName& aName, const CBTDevice& aDevice );
       
    47 
       
    48 
       
    49 /**
       
    50  *  CBTNotifConnection handles the connection information and operations 
       
    51  *  related to remote devices.
       
    52  *  
       
    53  *  @since Symbian^4
       
    54  */
       
    55 NONSHARABLE_CLASS( CBTNotifConnection ) : public CBase,
       
    56                                           public MBTNotificationResult,
       
    57                                           public MBtSimpleActiveObserver,
       
    58                                           public MBTEngDevManObserver
       
    59     {
       
    60 
       
    61 public:
       
    62 
       
    63     /**  Enumeration for the current active operation. */
       
    64     enum TOperation
       
    65         {
       
    66         EIdle,
       
    67         EAuthorizing,
       
    68         EPairing,
       
    69         EBonding,
       
    70         EAdditionalNotes,   // Marks the queries and notes which follow
       
    71                             // notifier requests, but are done after completing
       
    72                             // the actual notifier message
       
    73         EBlocking,
       
    74         EInternalOperations,    // Marks internal operations such as registry update.
       
    75         EReadingRegistry,
       
    76         EUpdatingRegistry
       
    77         };
       
    78 
       
    79     /**  Array of BT profiles. */
       
    80     typedef RArray<TBTProfile> RBTProfileArray;
       
    81 
       
    82     /**
       
    83      * Two-phased constructor.
       
    84      * @param aAddr Address of the remote device for this connection.
       
    85      * @param aTracker Pointer to our parent
       
    86      */
       
    87     static CBTNotifConnection* NewLC( const TBTDevAddr& aAddr, 
       
    88                 CBTNotifConnectionTracker* aTracker );
       
    89 
       
    90     /**
       
    91     * Destructor.
       
    92     */
       
    93     virtual ~CBTNotifConnection();
       
    94 
       
    95     /**
       
    96      * Get the address of the remote device for this connection.
       
    97      *
       
    98      * @since Symbian^4
       
    99      * @return The BD_ADDR.
       
   100      */
       
   101     inline const TBTDevAddr& Address() const
       
   102         { return iAddr; }
       
   103 
       
   104     /**
       
   105      * Get the device record of the remote device for this connection.
       
   106      *
       
   107      * @since Symbian^4
       
   108      * @return The CBTDevice device record.
       
   109      */
       
   110     inline CBTDevice* BTDevice() const
       
   111         { return iDevice; }
       
   112 
       
   113     /**
       
   114      * Get the current operation for this connection.
       
   115      *
       
   116      * @since Symbian^4
       
   117      * @param aProfile The profile identifying the service.
       
   118      */
       
   119     inline CBTNotifConnection::TOperation CurrentOperation() const
       
   120         { return iCurrentOp; }
       
   121 
       
   122     /**
       
   123      * Checks if we have any outstanding request, and handle the next
       
   124      * in line. Also checks the link state, and informs the tracker
       
   125      * if we have finished processing and the link is down.
       
   126      *  
       
   127      * @since Symbian^4
       
   128      */
       
   129     void CheckNextOperationL();
       
   130 
       
   131     /**
       
   132      * Completes the first outstanding client request and removes 
       
   133      * it from the queue.
       
   134      *  
       
   135      * @since Symbian^4
       
   136      * @param aReason The reason code to complete the message with.
       
   137      * @param aReply Data to write back to the client.
       
   138      */
       
   139     void CompleteClientRequest( TInt aReason, const TDesC8& aReply );
       
   140 
       
   141     /**
       
   142      * Distinguish the type request of this connection and queue it
       
   143      * or handle it.
       
   144      *  
       
   145      * @since Symbian^4
       
   146      * @param aParams The parameters for this request from the client.
       
   147      * @param aMessage The message from the client.
       
   148      */
       
   149     void HandleNotifierRequestL( const TDesC8& aParams, const RMessage2& aMessage );
       
   150 
       
   151     /**
       
   152      * Update an outstanding request for this connection.
       
   153      *  
       
   154      * @since Symbian^4
       
   155      * @param aParams The parameters of the original request from the client.
       
   156      * @param aMessage The update message from the client.
       
   157      */
       
   158     void HandleNotifierUpdateL( const TDesC8& aParams, const RMessage2& aMessage );
       
   159 
       
   160     /**
       
   161      * Cancel an outstanding request for this connection.
       
   162      *  
       
   163      * @since Symbian^4
       
   164      * @param aMessage The message from the client. (Temp! find better way!)
       
   165      */
       
   166     void CancelNotifierRequestL( const RMessage2& aMessage );
       
   167 
       
   168     /**
       
   169      * Start a bonding operation with the remote device.
       
   170      *
       
   171      * @since Symbian^4
       
   172      * @param aMessage The message from the client.
       
   173      */
       
   174     void StartBondingL( const RMessage2& aMessage );
       
   175 
       
   176     /**
       
   177      * Cancel an ongoing bonding operation with the remote device.
       
   178      *
       
   179      * @since Symbian^4
       
   180      */
       
   181     void CancelBondingL();
       
   182 
       
   183     /**
       
   184      * The pairing handler has completed a pairing operation. If this was part 
       
   185      * of a bonding procedure then this will complete the client request.
       
   186      *
       
   187      * @since Symbian^4
       
   188      */
       
   189     void PairingCompleted();
       
   190 
       
   191     /**
       
   192      * Process a new pairing result, and determine if we need to show
       
   193      * anything to the user.
       
   194      *
       
   195      * @since Symbian^4
       
   196      * @param aError Result of the pairing operation.
       
   197      */
       
   198     void PairingResult( TInt aError );
       
   199 
       
   200     /**
       
   201      * A service-level connection has been made with the device 
       
   202      * observed by this instance. The appropriate notification 
       
   203      * will be shown to the user.
       
   204      *
       
   205      * @since Symbian^4
       
   206      * @param aProfile The profile identifying the service.
       
   207      */
       
   208     void ServiceConnectedL( TBTProfile aProfile );
       
   209 
       
   210     /**
       
   211      * A service-level connection has disconnected from the device 
       
   212      * observed by this instance. The appropriate notification 
       
   213      * will be shown to the user.
       
   214      *
       
   215      * @since Symbian^4
       
   216      * @param aProfile The profile identifying the service.
       
   217      */
       
   218     void ServiceDisconnectedL( TBTProfile aProfile );
       
   219 
       
   220     /**
       
   221      * Ask the user if he/she wants to block future connection requests.
       
   222      *
       
   223      * @since Symbian^4
       
   224      */
       
   225     void LaunchBlockingQueryL();
       
   226 
       
   227     /**
       
   228      * Modify the record for the remote device in BTRegistry, with the 
       
   229      * changes already made in the local record.
       
   230      *
       
   231      * @since Symbian^4
       
   232      */
       
   233     void UpdateRegistryEntryL();
       
   234     
       
   235     /**
       
   236      * Modify the record for the remote device in BTRegistry, if 
       
   237      * aTrusted == true, then update trusted status after reading device 
       
   238      * info from registry
       
   239      *
       
   240      * @since Symbian^4
       
   241      */
       
   242      void UpdateRegistryEntryL(TBool aTrusted);
       
   243     
       
   244 // from base class MBTNotificationResult
       
   245 
       
   246     /**
       
   247      * From MBTNotificationResult.
       
   248      * Handle an intermediate result from a user query.
       
   249      * This ffunction is called if the user query passes information
       
   250      * back before it has finished i.e. is dismissed. The final acceptance/
       
   251      * denial of a query is passed back in MBRNotificationClosed.
       
   252      *
       
   253      * @since Symbian^4
       
   254      * @param aData the returned data. The actual format 
       
   255      *              is dependent on the actual notifier.
       
   256      */
       
   257     virtual void MBRDataReceived( CHbSymbianVariantMap & aData );
       
   258 
       
   259     /**
       
   260      * From MBTNotificationResult.
       
   261      * The notification is finished. The resulting data (e.g. user input or
       
   262      * acceptance/denial of the query) is passed back here.
       
   263      *
       
   264      * @since Symbian^4
       
   265      * @param aErr KErrNone or one of the system-wide error codes.
       
   266      * @param aData the returned data. The actual format 
       
   267      *              is dependent on the actual notifier.
       
   268      */
       
   269     virtual void MBRNotificationClosed( TInt aError, const TDesC8& aData );
       
   270 
       
   271 // from base class MBtSimpleActiveObserver
       
   272 
       
   273     /**
       
   274      * From MBtSimpleActiveObserver.
       
   275      * Callback to notify that an outstanding request has completed.
       
   276      *
       
   277      * @since Symbian^4
       
   278      * @param aActive The active object helper that completed this request.
       
   279      * @param aStatus The status of the completed request.
       
   280      */
       
   281     virtual void RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus );
       
   282 
       
   283     /**
       
   284      * From MBtSimpleActiveObserver.
       
   285      * Callback for handling cancelation of an outstanding request.
       
   286      *
       
   287      * @since Symbian^4
       
   288      * @param aId The ID that identifies the outstanding request.
       
   289      */
       
   290     virtual void CancelRequest( TInt aRequestId );
       
   291 
       
   292     /**
       
   293      * Callback to notify that an error has occurred in RunL.
       
   294      *
       
   295      * @param aActive Pointer to the active object that completed.
       
   296      * @param sError The error occured in RunL
       
   297      */
       
   298     virtual void HandleError( CBtSimpleActive* aActive, 
       
   299                                         TInt aError );
       
   300     
       
   301 // from base class MBTEngDevmanObserver
       
   302 
       
   303     /**
       
   304      * From MBTEngDevManObserver.
       
   305      * Indicates to the caller that adding, deleting or modifying a device 
       
   306      * has completed.
       
   307      * When this function is called, new commands can be issued to the 
       
   308      * CBTEngDevMan API immediately.
       
   309      *
       
   310      * @since  S60 v3.2
       
   311      * @param  aErr Status information, if there is an error.
       
   312      */
       
   313     virtual void HandleDevManComplete( TInt aErr );
       
   314     
       
   315     /**
       
   316      * From MBTEngDevManObserver.
       
   317      * Indicates to the caller that getting a device from registry
       
   318      * has completed.
       
   319      *
       
   320      * @param aErr Status information, if there is an error.
       
   321      * @param aDeviceArray Array of devices that match the given criteria 
       
   322      *                     (the array provided by the caller).
       
   323      */
       
   324     virtual void HandleGetDevicesComplete( 
       
   325             TInt err, CBTDeviceArray* deviceArray );
       
   326 
       
   327 private:
       
   328 
       
   329     /**
       
   330      * C++ default constructor.
       
   331      */
       
   332     CBTNotifConnection( const TBTDevAddr& aAddr,
       
   333                 CBTNotifConnectionTracker* aTracker );
       
   334 
       
   335     /**
       
   336      * Symbian 2nd-phase constructor.
       
   337      */
       
   338     void ConstructL();
       
   339 
       
   340     /**
       
   341      * Get a notification and configure it according to the current operation.
       
   342      *
       
   343      * @since Symbian^4
       
   344      * @param aType The notification type.
       
   345      * @param aResourceId Identifier for the resource to display.
       
   346      */
       
   347     void PrepareNotificationL( TBluetoothDialogParams::TBTDialogType aType,
       
   348                 TBTDialogResourceId aResourceId );
       
   349 
       
   350     /**
       
   351      * Handle the result from a notification that is finished.
       
   352      *
       
   353      * @since Symbian^4
       
   354      * @param aErr KErrNone or one of the system-wide error codes.
       
   355      * @param aData The returned data. The actual format 
       
   356      *              is dependent on the actual notifier.
       
   357      */
       
   358     void NotificationClosedL( TInt aError, const TDesC8& aData );
       
   359 
       
   360     /**
       
   361      * Handle a request for authorization of this connection.
       
   362      *
       
   363      * @since Symbian^4
       
   364      * @param aParams The parameters for this request from the client.
       
   365      */
       
   366     void HandleAuthorizationReqL( const TDesC8& aParams );
       
   367 
       
   368     /**
       
   369      * Process the user input and complete the outstanding authorization request.
       
   370      *
       
   371      * @since Symbian^4
       
   372      * @param aError The result off the notification.
       
   373      * @param aData The data returned from the notification dialog.
       
   374      */
       
   375     void CompleteAuthorizationReqL( TInt aError, const TDesC8& aData );
       
   376 
       
   377     /**
       
   378      * Process the user input for blocking a device.
       
   379      *
       
   380      * @since Symbian^4
       
   381      * @param aError The result off the notification.
       
   382      * @param aData The data returned from the notification dialog.
       
   383      */
       
   384     void CompleteBlockingReqL( TInt aError, const TDesC8& aData );
       
   385     
       
   386     /**
       
   387      * Fetch device from registry
       
   388      *
       
   389      * @since Symbian^4
       
   390      * @param addr BT address of device to fetch from registry
       
   391      */
       
   392     void GetDeviceFromRegistry( const TBTDevAddr &addr );
       
   393 
       
   394 private: // data
       
   395 
       
   396     /**
       
   397      * The current operation we are carrying out.
       
   398      */
       
   399     TOperation iCurrentOp;
       
   400 
       
   401     /**
       
   402      * Address of the remote device, identifying this connection.
       
   403      */
       
   404     TBTDevAddr iAddr;
       
   405 
       
   406     /**
       
   407      * Package to receive updates of the physical link state.
       
   408      */
       
   409     TBTBasebandEvent iBasebandEvent;
       
   410 
       
   411     /**
       
   412      * Queue of handles (identifier) of client messages we have been requested to work on.
       
   413      */
       
   414     RArray<TInt> iMsgHandleQ;
       
   415 
       
   416     /**
       
   417      * Array of accepted profile connections (as known here).
       
   418      */
       
   419     RBTProfileArray iAcceptedConnections;
       
   420 
       
   421     /**
       
   422      * Array of rejected profile connections (as known here).
       
   423      */
       
   424     RBTProfileArray iDeniedConnections;
       
   425 
       
   426     /**
       
   427      * Handle to observe and control the baseband connection.
       
   428      */
       
   429     RBTPhysicalLinkAdapter iPhyLink;
       
   430 
       
   431     /**
       
   432      * Subsession with BT registry.
       
   433      */
       
   434     RBTRegistry iRegistry;
       
   435 
       
   436     /**
       
   437      * Details of the remote device.
       
   438      * Own.
       
   439      */
       
   440     CBTDevice* iDevice;
       
   441 
       
   442     /**
       
   443      * Details of the remote device as retrieved from BT registry.
       
   444      * Own.
       
   445      */
       
   446     CBTRegistryResponse* iRegistryResponse;
       
   447 
       
   448     /**
       
   449      * helper for modifying registry.
       
   450      * Own.
       
   451      */
       
   452     CBTEngDevMan* iDevMan;
       
   453 
       
   454     /**
       
   455      * Active object helper for observing physical link changes.
       
   456      * Own.
       
   457      */
       
   458     CBtSimpleActive* iPhyActive;
       
   459 
       
   460     /**
       
   461      * Active object helper for observing BT registry changes.
       
   462      * Own.
       
   463      */
       
   464     CBtSimpleActive* iRegActive;
       
   465 
       
   466     /**
       
   467      * Helper class for processing pairing-related operations.
       
   468      * Own.
       
   469      */
       
   470     CBTNotifPairingHelper* iPairingHelper;
       
   471 
       
   472     /**
       
   473      * Pointer to an outstanding user interaction.
       
   474      * Not own.
       
   475      */
       
   476     CBluetoothNotification* iNotification;
       
   477 
       
   478     /**
       
   479      * Pointer to our parent.
       
   480      * Not own.
       
   481      */
       
   482     CBTNotifConnectionTracker* iTracker;
       
   483     
       
   484     CBTDeviceArray* iRegDevArray;  // used for retrieving devices from registry
       
   485 
       
   486     BTUNITTESTHOOK
       
   487 
       
   488     };
       
   489 
       
   490 #endif // BTNOTIFCONNECTION_H