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: Abstract base class for concete models. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef BTDEVMODELBASE_H |
|
20 #define BTDEVMODELBASE_H |
|
21 |
|
22 #include <btengdevman.h> // for MBTEngDevManObserver |
|
23 |
|
24 #include "btdevmodel.h" |
|
25 #include "btregistryobserver.h" // for MBTRegistryObserver |
|
26 |
|
27 /** |
|
28 * This is a abstract class providing basic common fucntions for derived classes. |
|
29 * It act as a mediator between UI applications and Bluetooth Engine Device Management API. |
|
30 * |
|
31 *@lib btdevmodel.dll |
|
32 *@since S60 V3.2 |
|
33 */ |
|
34 NONSHARABLE_CLASS( CBTDevModelBase ): public CBase, public MBTEngDevManObserver, public MBTRegistryObserver |
|
35 { |
|
36 public: // Constructors and destructor |
|
37 /** destructor |
|
38 *@param none. |
|
39 *@return none. |
|
40 */ |
|
41 virtual ~CBTDevModelBase(); |
|
42 public: |
|
43 |
|
44 /** Checks if any of the devices shown in view have active bluetooth connection. |
|
45 * This baseclass does not support connections, so the answer is allways EFalse. |
|
46 * |
|
47 * NOTE: TBTUIViewsCommonUtils::IsAnyDeviceConnectedL will report also those devices |
|
48 * that are not part of particular view, such as paired devices. |
|
49 * CBTPairedModel::IsAnyDeviceConnected reports only connection from paired devices. |
|
50 * |
|
51 *@return ETrue, if one or more devices are connected. EFalse if no devices are connected. |
|
52 */ |
|
53 TBool virtual IsAnyDeviceConnected(); |
|
54 /** |
|
55 * Get device based on addr or index. |
|
56 * @param aDevice the TBTDevice holder. You have to set either the deviceAddress or the |
|
57 * or the device index. If you specify both the device address and the index then the address is used, |
|
58 * this includes those cases when there is no device corresponding the address. |
|
59 * @return KErrNone if ok. |
|
60 * KErrArgument, if neither index not address is filled. |
|
61 * KErrOverFlow if index is out of range. which means it is negative or the internal array does not have that |
|
62 * many items. |
|
63 * KErrNotFound if the given address does not exists, in the internal array. |
|
64 */ |
|
65 TInt virtual GetDevice(TBTDevice& aDevice); |
|
66 |
|
67 /** |
|
68 * Change status of all devices on the list. This is used by Delete All operations in paired devices view |
|
69 * (EOpPair) and Blocked devices view(EOpUnblock) |
|
70 * |
|
71 * This creates multiple operations in the intergal queue that are all executed on by one. |
|
72 * |
|
73 * @param aOperation unpair/unblock |
|
74 * @return None. |
|
75 */ |
|
76 void ChangeAllDevices(const TBTDeviceOp aOperation); |
|
77 |
|
78 /** |
|
79 * Change device status, add device, e.g. block, unpair,unblock etc. |
|
80 * |
|
81 * The operation is put to queue and executed when the prior operations |
|
82 * of the queue are finnished. Immeadiately if the queue is empty. |
|
83 * |
|
84 * @param aDevice. The device and the type of the change. If the address is empty, then the |
|
85 * device index means what device is to be used. |
|
86 * @return none |
|
87 */ |
|
88 virtual void ChangeDeviceL(const TBTDevice& aDevice); |
|
89 |
|
90 /** |
|
91 * Change device status, add device, e.g. block, unpair,unblock etc. |
|
92 * This will check for leaves and make a callback, if leave occurs. |
|
93 * |
|
94 * The operation is put to queue and executed when the prior operations |
|
95 * of the queue are finnished. Immeadiately if the queue is empty. |
|
96 * |
|
97 * @param aDevice. The device and the type of the change. If the address is empty, then the |
|
98 * device index means what device is to be used. |
|
99 * @return none |
|
100 */ |
|
101 |
|
102 virtual void ChangeDevice(const TBTDevice& aDevice); |
|
103 |
|
104 /** |
|
105 * Cancel connecting, pairing, modifying device in BTRegistry |
|
106 * |
|
107 * Cancels ongoing operation or operation from queue, if it has not been started yet. |
|
108 * Cancels it, if it is being executed. Used by Canceling Connecting and pairing operations. |
|
109 * |
|
110 * @param aDevice. The device and the type of the change that will be canceled. |
|
111 * If the address is empty, then the |
|
112 * device index means what device is to be used. |
|
113 * @return None. |
|
114 */ |
|
115 virtual void CancelChange(const TBTDevice& aDevice); |
|
116 |
|
117 /** Creates and allocates TBTDevice representation of this device |
|
118 *@param aRegDevice the device to be converted, |
|
119 *@param aNameEntry contains the EIR data of the device if its data is valid |
|
120 *@return the TBTDevice representation of the same device. (Note the caller is responsible for deleting |
|
121 * the returned item.) |
|
122 */ |
|
123 virtual TBTDevice* CreateDeviceL(const CBTDevice* aRegDevice, |
|
124 TNameEntry* aNameEntry); |
|
125 |
|
126 /** Checks if there are any ChangeDeviceCommands that are not finnished. |
|
127 *@return ETrue if the are one or more commands being executed or are in the execution queue. |
|
128 */ |
|
129 virtual TBool DeviceChangeInProgress(); |
|
130 |
|
131 /** This is used to make callback to iObserver, when a leave has been detected. |
|
132 *It will also clean up the partial operation. |
|
133 * |
|
134 *@param aErr the leave error code |
|
135 *@param aDevice The device and operation that cause the leave. |
|
136 * If this is inserted in the queue, it is deleted from there. |
|
137 * If the leave occurred before inserting it to execution queue |
|
138 * (not common), then it will not deleted from there. |
|
139 *@return none. |
|
140 */ |
|
141 virtual void HandleLeave(TInt aErr,const TBTDevice* aDevice ); |
|
142 |
|
143 protected: |
|
144 /** |
|
145 * Change device status, add device, e.g. block, unpair,unblock etc. |
|
146 * |
|
147 * This is the operation that is used to to execute the operation queued by ChangeDevice. |
|
148 * |
|
149 * @param aDevice. The device and the type of the change. If the address is empty, then the |
|
150 * device index means what device is to be used. |
|
151 * @return KerrNone or system wide error code. |
|
152 */ |
|
153 virtual TInt DoChangeDeviceL(const TBTDevice& aDevice); |
|
154 |
|
155 /** |
|
156 * Cancel ongoing connecting, pairing, modifying device in BTRegistry |
|
157 * |
|
158 * This is the operation that is used to cancel ongoing operation. |
|
159 * |
|
160 * @param aDevice. The device and the type of the change that will be canceled. |
|
161 * If the address is empty, then the |
|
162 * device index means what device is to be used. |
|
163 * @return None. |
|
164 */ |
|
165 virtual void DoCancelChangeL(const TBTDevice& aDevice); |
|
166 |
|
167 /** This function recounts the indexes of iDeviceArray. |
|
168 *@return none. |
|
169 */ |
|
170 void RenumberDeviceArray(); |
|
171 |
|
172 /** Constructor |
|
173 * @param aObserver The observer will receive information about command completes and |
|
174 * changes in the devices. |
|
175 * @param aOrder The order the devices are sorted. Default order is added by CBTDevMan, so |
|
176 * this class can assume this parameter to be used. This class is responsible for deleting this parameter on |
|
177 * its destructor. |
|
178 */ |
|
179 CBTDevModelBase(MBTDeviceObserver* aObserver, |
|
180 TBTDeviceSortOrder* aOrder ); |
|
181 |
|
182 /** Get the index for a device specified by bluetooth device address. |
|
183 * |
|
184 *@param aAddr the address of the searched device or KNullAddres. |
|
185 *@param aIndexIfNullAddress, if this parameter is defined this function |
|
186 *returns this index instead of KErrNotFound, it the device has nullAddress. |
|
187 *@return index of the address. If the given address is KNullAddress then returns aIndexIfNullAddress or KErrNotFound if one is not specified by called. |
|
188 *This will allways return KErrNone if the given address is not a KNullAddress and is not found. |
|
189 */ |
|
190 TInt GetIndexByAddress(const TBTDevAddr aAddr,TInt aIndexIfNullAddress=KErrNotFound); |
|
191 |
|
192 /** Adds the TBTDevice representation of this device to iDeviceArray, if |
|
193 * this device is of that type (paired/blocked) that this model supports. |
|
194 * If the device is not that type, it will not be added. |
|
195 * |
|
196 * NOTE: This function is not guaranteed againt duplicates, so multiple |
|
197 * additions of the same device will lead to multiple copies of it. |
|
198 * |
|
199 * Subclasses can also implement their version of this function to add information |
|
200 * to the device objects, such as connection information. |
|
201 * |
|
202 * @param aRegDevice the device to be added (if not filtered). |
|
203 * @param aNameEntry contains the EIR data of the device if its data is valid |
|
204 * @aOperation the operation that this device will contain when added. |
|
205 */ |
|
206 void AddDeviceL(const CBTDevice* aRegDevice, |
|
207 TNameEntry* aNameEntry, |
|
208 const TBTDeviceOp aOperation=EOpNone); |
|
209 |
|
210 /** Replaces iDeviceArray contents with the given devices |
|
211 *@param aDeviceArray the devices that will be added to internal structures. |
|
212 */ |
|
213 virtual void CreateDevicesL(const CBTDeviceArray* aDeviceArray); |
|
214 |
|
215 /** Adds the given device to internal structures of this class |
|
216 * using AddDeviceL, if the device is such that it should not be listed by this |
|
217 * class, then it is not added. |
|
218 * |
|
219 * Implementing is used to filter out devices that are not handled by particular view. |
|
220 * |
|
221 * @param aNameEntry contains the EIR data of the device if its data is valid |
|
222 */ |
|
223 virtual void HandleNewDeviceL(const CBTDevice* aRegDevice, |
|
224 TNameEntry* aNameEntry) = 0; |
|
225 |
|
226 /** Sends refresh of list of shown devices to listener. |
|
227 * |
|
228 * @param aErr If this is not KErrNone, then this function |
|
229 * will send refresh to the listener. Allways send, if not specified. |
|
230 * If this funtion is not KEerrNone, then the funtion does nothing. |
|
231 * @param aSelectedItem. If this is specified, then select this item. |
|
232 * if not specified uses the same item that the listener used to have active. |
|
233 */ |
|
234 virtual void SendRefreshIfNoError(TInt aErr=KErrNone,TInt aSelectedItem = KErrNotSupported ); |
|
235 |
|
236 protected: |
|
237 |
|
238 /** This callback is used to to notify this call from completed changed from iDevMan. |
|
239 * Inherited from MBTEngDevManObserver. |
|
240 * |
|
241 * This funtion will trap any leave if they may occur and report them as errors in the |
|
242 * corresponfing device change operarion. |
|
243 */ |
|
244 void HandleDevManComplete(TInt aErr); |
|
245 |
|
246 /** Inherited from BTEng's MBTEngDevManObserver, and implemented as empty, |
|
247 * because we do ask devicelists directly from iDevman, but trough iRegistryObserver->Refresh() |
|
248 */ |
|
249 void HandleGetDevicesComplete(TInt aErr, CBTDeviceArray* aDeviceArray); |
|
250 |
|
251 /** This callback is used by iRegistryObserver to notify device changes, that |
|
252 * originate both from changes of the BTRegistry as well as refreshes requested |
|
253 * by this class. |
|
254 * @aDeviceArray the devices that the registry observer gets. |
|
255 */ |
|
256 void RegistryChangedL(const CBTDeviceArray* aDeviceArray); |
|
257 |
|
258 /** Check if there is allready one or more devices with this name. |
|
259 *@return ETrue if there is. |
|
260 */ |
|
261 TBool IsNameExisting(const TDesC& aName); |
|
262 |
|
263 /** Executes the next one in the queue, if any. |
|
264 * Leaves are trapped by this class and send as failed commands to iObserver |
|
265 * using HandleLeave. |
|
266 *@param none. |
|
267 *@return none. |
|
268 */ |
|
269 void HandleQueue(); |
|
270 |
|
271 protected: // Data |
|
272 MBTDeviceObserver* iObserver; // the listener of the completed commands and registry changes. |
|
273 CBTEngDevMan* iDevMan; // This is used to change the devices. |
|
274 TBTDeviceSortOrder* iSortOrder; // The order the devices are sorted to. |
|
275 RDeviceArray iDeviceArray; // The list of current devices. |
|
276 CBTRegistryObserver* iRegistryObserver; // This takes care of sending the devicelist to us each time |
|
277 // something may have been changes. |
|
278 TBTRegistrySearch iSearchPattern; // the pattern iRegistrySearch uses in retrieving devicelist. |
|
279 // NOTE: HandleDeviceL is used to filter the results. |
|
280 TBool iIsChangeAll; |
|
281 TBTDevice* iDevice; // the currently changed device, if any |
|
282 RDeviceArray iQueue; // The queue of commands to be executed |
|
283 }; |
|
284 |
|
285 #endif // BT_DEV_MODEL_BASE_H |
|
286 |
|