bluetoothengine/btui/devmodel/inc/btdevmodel.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:   Maintain a Bluetooth devices data model for UI components.
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef BTDEVMODEL_H
       
    19 #define BTDEVMODEL_H
       
    20 
       
    21 #include <e32base.h>     
       
    22 #include <btmanclient.h>
       
    23 #include <btdevice.h>
       
    24 #include <e32cmn.h>
       
    25   
       
    26 // used to support different device list of UI
       
    27 enum TBTDeviceGroup
       
    28     {
       
    29     EGroupPaired, // for paired device list
       
    30     EGroupBlocked // for blocked device list
       
    31     };
       
    32     
       
    33 // for showing left side icon of a device in device list. Based on CoD major device
       
    34 enum TBTDeviceType
       
    35     {
       
    36     EDeviceComputer = 0,// computer
       
    37     EDevicePhone,		// mobile phone
       
    38     EDeviceAudio, 		// headset or loudspeakers    
       
    39     EDeviceCarkit, 		// audio-caraudio
       
    40     EDevicePrinter, 	// imaging-printer
       
    41     EDeviceKeyboard,	// peripheral-keyboard
       
    42     EDeviceMice, 		// peripheral-pointer
       
    43     EDeviceGPS, 		// major service positioning
       
    44     EDeviceDefault,		// device of other type than define above.
       
    45     };
       
    46 
       
    47 // for showing right side icon of a device on a device list    
       
    48 enum TBTDeviceStatus
       
    49     {
       
    50     EStatusTrusted = 0x0001,	 		// show authorised icon on both paired and blocked lists
       
    51     EStatusBtuiConnected = 0x0002,  	// show connected icon on paired list
       
    52     EStatusBlocked = 0x0004, 			// show device on blocked list
       
    53     EStatusPaired = 0x0008, 			// show the device in paired devices list
       
    54     EStatusConnectable = 0x0010, 		// The device can be connected to.
       
    55     									// NOTE: connected devices are also connectable,
       
    56     									// despite they cannot be connected before disconnect.
       
    57 	EStatusPhysicallyConnected = 0x0020  // Physical bluetooth connection. 
       
    58     };
       
    59     
       
    60 enum TBTDeviceOp
       
    61     {
       
    62     EOpPair,	
       
    63     EOpUnpair,	
       
    64     EOpBlock,	
       
    65     EOpUnblock, 
       
    66     EOpConnect, 
       
    67     EOpDisconnect,
       
    68     EOpTrust,
       
    69     EOpUntrust,
       
    70     EOpChangeName,
       
    71     EOpNone,
       
    72     EOPInternalUntust // used by CBTDevModel internally
       
    73     };
       
    74     
       
    75 /* TBTDevAddr that is not address of any device
       
    76 */    
       
    77 #define KNullAddress TBTDevAddr(TInt64(0))
       
    78    
       
    79 // contain all device info needed for shown on a device list
       
    80 NONSHARABLE_CLASS( TBTDevice )
       
    81     {
       
    82 public:
       
    83 	/** Constructor, that initialized this as empty*/
       
    84     IMPORT_C TBTDevice();
       
    85     /** Copy constructor */
       
    86     IMPORT_C TBTDevice(const TBTDevice& aDevice);
       
    87     /** Copy  */
       
    88     IMPORT_C TBTDevice& operator=(const TBTDevice& aDevice);
       
    89     
       
    90     TBTDeviceType iType; 				// left side icon
       
    91     TBTDeviceClass iDeviceClass; 		// this is needed by connect
       
    92     TBTDeviceName iName; 				// a formated friendly/device name in corresponding CBTDevice
       
    93     TBTDeviceName iFriendlyName;        // still need to remember if friendly name has been set   
       
    94     TUint iStatus; 						// mask of TDeviceStatus
       
    95     TBTDeviceOp iOperation; 			// last operation on the device
       
    96     TBTDevAddr iAddr; 					// bt device address
       
    97     TInt iIndex; 						// new position of the device in the device list. 
       
    98                  						// Default value means iAddr should be used instead.
       
    99     TBTLinkKeyType iLinkKeyType;
       
   100     TNameEntry iNameEntry; // the device's EIR data
       
   101     };   
       
   102 /** Static methods for TBTDeviceComparison. These are meant to be given to TBTDeviceSortOrder and
       
   103 * to be used for defining sort orders.
       
   104 */
       
   105 class TBTDeviceComparison
       
   106 	{
       
   107 public:
       
   108 	/** 
       
   109 	* Compare function for alphabetic sorting order.
       
   110 	* @param aFirstDevice to be compared
       
   111 	* @param aSecondDevice sencond device to be compared
       
   112 	* @return 1 if aFirstDevice is before aSecondDevice -1 otherwise. May not return 0,
       
   113 	* on devices that are not the same.
       
   114 	*/
       
   115 		
       
   116 	IMPORT_C static TInt CompareAphabetically(
       
   117 		const TBTDevice& aFirstDevice, const TBTDevice& aSecondDevice) ;
       
   118 		
       
   119 	/** 
       
   120 	* Compare function for reverse alphabetic sorting order.
       
   121 	* @param aFirstDevice to be compared
       
   122 	* @param aSecondDevice sencond device to be compared
       
   123 	* @return 1 if aFirstDevice is before aSecondDevice -1 otherwise. May not return 0,
       
   124 	* on devices that are not the same.
       
   125 	*/	
       
   126 	IMPORT_C static TInt ReverseCompareAphabetically(
       
   127 	 	const TBTDevice& aFirstDevice, const TBTDevice& aSecondDevice) ;
       
   128 	};
       
   129 	     
       
   130 typedef RPointerArray<TBTDevice> RDeviceArray; 
       
   131 typedef RPointerArray<TBTDeviceName> RBTDevNameArray; 
       
   132 typedef TLinearOrder<TBTDevice> TBTDeviceSortOrder ;
       
   133 
       
   134 class CBTDevModelBase;
       
   135 
       
   136 /**
       
   137 * Callback interface for informing about the changes in the devices shown by the listening view.
       
   138 * Also a callback interface that informs the listener when the issued commands have been completed.
       
   139 */
       
   140 class MBTDeviceObserver
       
   141     {
       
   142 public: 
       
   143     /** 
       
   144     * Informs the observer that ChangeDevice command has been completed.
       
   145     *
       
   146     * The listener must not change the displaid devices, since RefreshDeviceList is used for that purpose.
       
   147     * Also this will not be called, if changes happen from outside such as pairing initiated by 3rd party
       
   148     * of blocking from notifier.
       
   149     *
       
   150     * @param aErr Symbian error code, KErrNone if no error.
       
   151     * @param aDevice the device which is changed. This has allways given to the listener by RefreshDeviceList 
       
   152     * prior this call, if that device is visible at the listening view. This not passed by refrence,
       
   153     * since this device could change, if registry is changed
       
   154     * @param aDevNameArray hold conflicting devices' short names if "AlreadyExist" error happened during "connect"
       
   155     * @return None.
       
   156     */
       
   157     virtual void NotifyChangeDeviceComplete(const TInt aErr, const TBTDevice& aDevice, 
       
   158         const RBTDevNameArray* aDevNameArray = NULL) = 0;
       
   159 	
       
   160 	/** 
       
   161 	 * This is used to notify the listening graphic component that the deviceList is changed.
       
   162 	 * After receiving this call the graphic component has to redraw its screen to match this list.
       
   163 	 * @param aDevices The devices to be displaid. 
       
   164 	 * @param aSelectedItemIndex The index of the item to be selected in the given devices.
       
   165 	 */
       
   166 	virtual void RefreshDeviceList(const RDeviceArray* aDevices,TInt aSelectedItemIndex) =0;
       
   167 	
       
   168 	/** 
       
   169 	* This is used before calling RefreshDeviceList to save the currently selected index,
       
   170 	* so that the same device could be selected after the refresh, if that device still exists.
       
   171 	* @param None.
       
   172 	* @return the selected device. KErrNotFound if the view has no devices.
       
   173 	*/
       
   174 	virtual TInt CurrentItemIndex() =0;
       
   175     };
       
   176 
       
   177 /**
       
   178 * This is a abstract class providing basic common fucntions for derived classes.
       
   179 * It act as a facade between UI applications and Bluetooth Engine Device Management API.
       
   180 */
       
   181 NONSHARABLE_CLASS( CBTDevModel ) : public CBase
       
   182     {
       
   183 public: // Constructors and destructor
       
   184     /**
       
   185     * Constructs devmodel.
       
   186     * @param aGroup. do you wish to list other or blocked devices.
       
   187     * @param MBTDeviceObserver The object that will receive the notifications for command completes,
       
   188     * @param the order the devices are sorted in the list. If you do not give this the devices
       
   189     * will be sorted in ascending alphabetic order. Devices with same name are sorted according to
       
   190     * bluetooth addreses. DevModel will take the ownership of this object.
       
   191     */    
       
   192     IMPORT_C static CBTDevModel* NewL(const TBTDeviceGroup aGroup,
       
   193                                       MBTDeviceObserver* aObserver=NULL, 
       
   194                                       TBTDeviceSortOrder* aOrder=NULL);
       
   195     /** Destructor */
       
   196     virtual ~CBTDevModel();       
       
   197 
       
   198 public: // New functions
       
   199 
       
   200    /**
       
   201     * Get device based on addr or index.
       
   202     * @param aDevice the TBTDevice holder. The device address is passed in
       
   203     * @return KErrNone if ok.
       
   204     * KErrArgument, if neither index not address is filled.
       
   205     * KErrOverFlow if index is out of range. 
       
   206     * KErrNotFound if the given address does not exists, in the internal array.
       
   207     */
       
   208     IMPORT_C TInt GetDevice(TBTDevice& aDevice);
       
   209     
       
   210 	/** 
       
   211 	* Checks if any of the devices shown in view have active bluetooth connection.
       
   212 	* @return ETrue, if one or more devices are connected. EFalse if no devices are connected.
       
   213 	* This also return EFalse, in case of blocked devices.
       
   214 	*/
       
   215 	IMPORT_C TBool IsAnyDeviceConnected();
       
   216 	
       
   217     /** 
       
   218     * Creates and allocates TBTDevice representation of this device.
       
   219     * The caller is responsibe for the garbage connection of the created device.
       
   220     * @param aRegDevice the device to be converted
       
   221     * @return the TBTDevice representation of the same device
       
   222     */
       
   223     IMPORT_C TBTDevice* CreateDeviceL(const CBTDevice* aRegDevice,
       
   224             TNameEntry* aNameEntry); 
       
   225            
       
   226     /**
       
   227     * Change status of all devices on the list, e.g. used by unpair all and unblock all commands.
       
   228     * @param aOperation unpair/unblock
       
   229     * @return None.
       
   230     */
       
   231     IMPORT_C void ChangeAllDevices(const TBTDeviceOp aOperation);
       
   232     
       
   233     /**
       
   234     * Change device status, add device, e.g. pair/block, or delete device,e.g. unpair/unblcok
       
   235     * You must not pair device without properly filling deviceName.
       
   236     * @param aDevice the TBTDevice holder. The device address is passed in
       
   237     * @return None
       
   238     */
       
   239     IMPORT_C void ChangeDevice(const TBTDevice& aDevice);
       
   240     
       
   241     /**
       
   242     * Change device status, add device, e.g. pair/block, or delete device,e.g. unpair/unblcok
       
   243     * @param aDevice the CBTDevice holder.
       
   244     * @return None.
       
   245     */
       
   246   	IMPORT_C void ChangeDevice(const CBTDevice* aDevice,
       
   247   	      TNameEntry* aNameEntry,
       
   248   	        TBTDeviceOp aOp) ;
       
   249   	
       
   250     /**
       
   251     * Cancel ongoing operation, such as connecting or pairing.
       
   252     * At the moment btui does not support other Other operations than pairing and connecting cannot be canceled.
       
   253     *
       
   254     * @param aDevice the device, whose command is to be canceled.   
       
   255     * @return None.
       
   256     */
       
   257     IMPORT_C void CancelChange(const TBTDevice& aDevice);
       
   258 
       
   259 	/** 
       
   260 	*Checks if there are ChangeDeviceCommands that are not finnished.
       
   261 	*/
       
   262 	IMPORT_C TBool DeviceChangeInProgress();
       
   263 	
       
   264 	
       
   265 private:
       
   266 	/** constructor */
       
   267     CBTDevModel();
       
   268     
       
   269     /** Symbian 2nd phase constuctor that may leave.
       
   270      * @param aGroup EGroupPaired and EGroupBlocked are supported.
       
   271      * @param aObserver the observer of the device list. This is not mandatory
       
   272      * @param aOrder The order the devices are sorted
       
   273      */
       
   274     void ConstructL(const TBTDeviceGroup aGroup,
       
   275                     MBTDeviceObserver* aObserver,
       
   276 					TBTDeviceSortOrder* aOrder );
       
   277 private:
       
   278 	
       
   279     CBTDevModelBase* iDevModel; // CBTDevModelPaired or CBTDevModel Blocked 
       
   280     TBTDeviceGroup iGroup;
       
   281     };    
       
   282 	
       
   283      
       
   284 /** Adds flags to iStatus of TBTDevice.
       
   285  *@param aStatus the status of the device
       
   286  *@param aFlags the flags to be set
       
   287  */
       
   288 inline TUint SetStatusFlags(TUint& aStatus,TBTDeviceStatus aFlags)
       
   289 	{
       
   290 		aStatus |=aFlags;
       
   291 		return aStatus;
       
   292 	}
       
   293 /** Clear status flags to iStatus of TBTDevice.
       
   294  *@param aStatus the status of the device
       
   295  *@param aFlags the flags to be set
       
   296  */	
       
   297 inline TUint UnsetStatusFlags(TUint& aStatus,TBTDeviceStatus aFlags)
       
   298 	{
       
   299 		aStatus &= ~aFlags;
       
   300 		return aStatus;
       
   301 	}
       
   302 
       
   303 #endif     
       
   304