bluetoothengine/btui/devmodel/inc/btpairedmodel.h
branchRCL_3
changeset 56 9386f31cc85b
parent 0 f63038272f30
equal deleted inserted replaced
55:613943a21004 56:9386f31cc85b
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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:  The model that is used to list and handle all paired devices.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef BTPAIREDMODEL_H
       
    20 #define BTPAIREDMODEL_H
       
    21 
       
    22 #include "btdevmodelbase.h"
       
    23 #include <btengconnman.h>
       
    24 #include <bt_sock.h> 				// for TBTDevAddr
       
    25 #include <btserversdkcrkeys.h> 		//for TBTPowerStateValue
       
    26 #include <btengconstants.h>
       
    27 #include <btengsettings.h>
       
    28 
       
    29 enum TPairedModelState
       
    30 	{
       
    31 	EIdleState=0,
       
    32 	EDeleteDeviceState,
       
    33 	EAddDeviceState,
       
    34 	EPairDeviceState,
       
    35 	EDisconnectBeforeOperationState,	
       
    36 	};
       
    37 class CBTEngSettings;
       
    38 
       
    39 /**
       
    40 * This is a adds pairing and connecting functionality to BTDevModelBase.
       
    41 *
       
    42 * It act as a mediator between UI applications and Bluetooth Engine Device Management API.
       
    43 *
       
    44 *@lib btdevmodel.dll
       
    45 *@since S60 V3.2
       
    46 */	
       
    47 NONSHARABLE_CLASS(CBTPairedModel) :
       
    48 		public CBTDevModelBase, public MBTEngConnObserver, 
       
    49 		public MBluetoothPhysicalLinksNotifier,
       
    50 		public MBTEngSettingsObserver
       
    51     {
       
    52     
       
    53 public: // Constructors and destructor
       
    54 
       
    55 	/**
       
    56     * C++ default constructor.
       
    57     */
       
    58 	CBTPairedModel(MBTDeviceObserver* aObserver, 
       
    59                   TBTDeviceSortOrder* aOrder  );
       
    60                   
       
    61     /** Symbian 2nd phase constuctor that may leave.
       
    62     *@param None.
       
    63     *@return None.
       
    64     */
       
    65     void ConstructL();
       
    66 
       
    67 	/** 
       
    68 	* NewL function 
       
    69 	* @param aObserver The observer will receive information about command completes and
       
    70 	* changes in the devices.
       
    71 	* @param aOrder The order the devices are sorted. Default order is added by CBTDevMan, so
       
    72 	* this class can assume this parameter to be used. This class is responsible for deleting this parameter on
       
    73 	* its destructor.
       
    74 	*/
       
    75     static CBTPairedModel* NewL(MBTDeviceObserver* aObserver,
       
    76                                 TBTDeviceSortOrder* aOrder  );
       
    77     
       
    78     /** 
       
    79     * Destructor
       
    80     * @param None.
       
    81     */
       
    82     virtual ~CBTPairedModel();       
       
    83 
       
    84 	/** 
       
    85 	* Checks if any of the devices shown in paired devices view have active bluetooth connection.
       
    86     *
       
    87 	* NOTE: TBTUIViewsCommonUtils::IsAnyDeviceConnectedL will also check
       
    88 	* those devices that are not paired.
       
    89 	*
       
    90 	*@return ETrue, if one or more devices are connected. EFalse if no devices are connected.
       
    91 	*/
       
    92 	TBool virtual IsAnyDeviceConnected();
       
    93 	
       
    94 	/** 
       
    95 	* Start new device pairing. This is handled by Queue, like
       
    96 	* all other device changes. 
       
    97 	*
       
    98 	* This is used by CBTDevice::ChangeDevice(CBTDevice* ,EOpPair)
       
    99 	*
       
   100 	* @param aPairingDevice the device to be paired.
       
   101 	* @return KErrInUse, if another operation has be queued and not finnished. KErrNone otherwise.
       
   102 	*/
       
   103 	TInt PairDeviceL(const CBTDevice* aPairingDevice,
       
   104 	        TNameEntry* aNameEntry);
       
   105 	
       
   106 protected:
       
   107 
       
   108     /**
       
   109 	* Change device status, add device, e.g. block, unpair,unblock etc.
       
   110     *
       
   111     * This is the operation that is used to to execute the operation queued by ChangeDevice.
       
   112     *
       
   113     * This class will add connection releted operations to CBTDevModelBase::DoChangeDevice.
       
   114     *
       
   115     * @param aDevice. The device and the type of the change. If the address is empty, then the 
       
   116     * device index means what device is to be used.
       
   117     * @return KerrNone or system wide error code.
       
   118     */
       
   119     TInt DoChangeDeviceL(const TBTDevice& aDevice);
       
   120 
       
   121     /**
       
   122     * Cancel ongoing connecting, pairing, modifying device in BTRegistry
       
   123     *
       
   124     * This is the operation that is used to cancel ongoing operation.
       
   125     *
       
   126     * @param aDevice. The device and the type of the change that will be canceled. 
       
   127     * If the address is empty, then the 
       
   128     * device index means what device is to be used.
       
   129     * @return None.
       
   130     */    
       
   131     void DoCancelChangeL(const TBTDevice& aDevice);
       
   132 
       
   133     /** 
       
   134     * These two methods set the EStatusPhysicallyConnected attribute to 
       
   135     * the devices that have active connection.
       
   136     */
       
   137     void FlagPhysicallyConnectedDevices(RDeviceArray &aDevices);
       
   138     void FlagPhysicallyConnectedDevices(TBTDevice& aDevice, RBTDevAddrArray& aBTDeviceArray);
       
   139 
       
   140 	
       
   141 private:
       
   142 			
       
   143 	/** 
       
   144 	* Start the actual pairing of iPairingDevice
       
   145 	* This is called by DoChangeDevice, if the operation is pairing.
       
   146 	*@param none.
       
   147 	*@return none.
       
   148 	*/
       
   149 	void DoPairDeviceL();
       
   150 
       
   151 	/** 
       
   152 	* BTEngConnMan will call this when the connecting is finnished.
       
   153 	* This is called as callback not only for connections initiated by this class,
       
   154 	* but also for all BT Engines supported porofile connections, including those
       
   155 	* initiated by remote devices.
       
   156 	* @param aAddr The address of the device whose connection attempt has been finnished.
       
   157 	* @param aErr KErrNone if connection is succesfull, Otherwise system wide error code.
       
   158 	* @param aConflicts The conflicting devices in case of unsuccesfull connection attempt if any.
       
   159 	* @return none.
       
   160 	*/    
       
   161     void ConnectComplete(TBTDevAddr& aAddr, TInt aErr, RBTDevAddrArray* aConflicts = NULL);
       
   162 
       
   163 	/** 
       
   164 	* BTEngConnMan will call this when the disconnecting is finnished.
       
   165 	* This is called as callback not only for disconnections initiated by this class,
       
   166 	* but also for disconnection of BT Engines supported porofile connections, including those
       
   167 	* initiated by remote devices.
       
   168 	* @param aAddr The address of the device whose connection attempt has been finnished.
       
   169 	* @param aErr KErrNone if disconnection is succesfull, Otherwise system wide error code.
       
   170 	* @return none.
       
   171 	*/    
       
   172 	void DisconnectComplete(TBTDevAddr& aAddr, TInt aErr);
       
   173     
       
   174 	/**
       
   175 	*  from BTEng's MBTEngConnObserver
       
   176 	*/
       
   177     void PairingComplete(TBTDevAddr& aAddr, TInt aErr);
       
   178     
       
   179     /** 
       
   180     * The leaving version of PairingComplete. Internally called by PairingComplete
       
   181     */
       
   182     void PairingCompleteL(TBTDevAddr& aAddr, TInt aErr);
       
   183 
       
   184     /** 
       
   185     * Creates and allocates TBTDevice representation of this device
       
   186     *
       
   187     * This class will add the connection status information to 
       
   188     * to CBTDevModelBase::CreateDevice.
       
   189     *
       
   190     * @param aRegDevice the device to be converted
       
   191     * @return the TBTDevice representation of the same device. (Note the caller is responsible for deleting
       
   192     * the returned item.)
       
   193     */    
       
   194     TBTDevice* CreateDeviceL(const CBTDevice* aRegDevice, TNameEntry* aNameEntry);
       
   195     
       
   196     /** 
       
   197     * Adds the given device to internal structures of this class
       
   198     * using AddDeviceL, if it is paired and not blocked.
       
   199     *
       
   200     * @param aRegDevice
       
   201     */    
       
   202     void HandleNewDeviceL(const CBTDevice* aRegDevice,
       
   203             TNameEntry* aNameEntry);
       
   204 
       
   205     /** 
       
   206     * This callback is used to to notify this call from completed changed from iDevMan.
       
   207     * Inherited from MBTEngDevManObserver.    
       
   208     *
       
   209     * This funtion will trap any leave if they may occur and report them as errors in the
       
   210     * corresponfing device change operarion.
       
   211     *
       
   212     * @param aErr KErrNone or system wide error code.
       
   213     */
       
   214     void HandleDevManComplete(TInt aErr);
       
   215     
       
   216 public: 
       
   217     
       
   218     /**
       
   219      * From MBTEngSettingsObserver - Called when powerstate is changed
       
   220      * @param TBTPowerStateValue power state
       
   221      * @return None
       
   222      */       
       
   223 	void PowerStateChanged( TBTPowerStateValue aState );
       
   224 		
       
   225     /**
       
   226      * From MBTEngSettingsObserver - Called when visibility is changed
       
   227      * @param TBTPowerStateValue state of visibility mode
       
   228      * @return None
       
   229      */    		
       
   230 	void VisibilityModeChanged( TBTVisibilityMode aState );  
       
   231     
       
   232     
       
   233 public:    //from MBluetoothPhysicalLinksNotifier
       
   234 
       
   235 	/** 
       
   236 	* Inherited from MBluetoothPhysicalLinksNotifier and implemented empty
       
   237 	*/
       
   238 	void HandleCreateConnectionCompleteL(TInt ) {};
       
   239 	
       
   240 	/** 
       
   241 	* Disconnect from non BTEng device by iLinks is complete.
       
   242 	*@param aErr KErrNone or system wide errorcode.
       
   243 	*/	
       
   244 	void HandleDisconnectCompleteL(TInt aErr) ;
       
   245 	
       
   246 	/** Inherited from MBluetoothPhysicalLinksNotifier and not used.
       
   247 	*/
       
   248 	void HandleDisconnectAllCompleteL(TInt aErr) {HandleDisconnectCompleteL(aErr); }
       
   249 
       
   250     /**
       
   251     * Get device based on addr or index.
       
   252     * @param aDevice the TBTDevice holder. The device address is passed in
       
   253     * @return KErrNone if ok.
       
   254     * KErrArgument, if neither index not address is filled.
       
   255     * KErrOverFlow if index is out of range. 
       
   256     * KErrNotFound if the given address does not exists, in the internal array.
       
   257     */
       
   258     TInt virtual GetDevice(TBTDevice& aDevice);
       
   259 
       
   260 	/** 
       
   261 	* This is used to make callback to iObserver, when a leave has been detected.
       
   262 	*
       
   263 	*@param aErr the leave error code
       
   264 	*@param aDevice The device and operation that cause the leave.
       
   265 	*/
       
   266 	virtual void HandleLeave(TInt aErr,const TBTDevice* aDevice );               
       
   267 	
       
   268 private:
       
   269 
       
   270     CBTEngConnMan* iConnMan;
       
   271     CBTDevice* iPairingDevice;	
       
   272 
       
   273     TBTDevice* iDisconnectDevice;
       
   274     TPairedModelState iState;	// The device is deleted and written back to bt registry before pairing
       
   275     							// this is used to control those operations
       
   276 	//used for disconnecting connections not managed by BTEngine    							
       
   277 	CBluetoothPhysicalLinks *iLinks;   							
       
   278 	RSocketServ iSocketServ;
       
   279 	CBTEngSettings *iBtEngSettings; // used for turning on BT, if not enabled
       
   280     };
       
   281     
       
   282 #endif