author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 13 Oct 2010 14:43:49 +0300 | |
branch | RCL_3 |
changeset 72 | 4b59561a31c0 |
parent 56 | 9386f31cc85b |
permissions | -rw-r--r-- |
56 | 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 paired devices view |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
#include "btpairedmodel.h" |
|
20 |
#include <btengutil.h> |
|
21 |
#include "debug.h" |
|
22 |
#include "btui.h" |
|
23 |
||
24 |
const TInt KMaxCheckedConnections=20; |
|
25 |
||
26 |
||
27 |
// --------------------------------------------------------------------- |
|
28 |
// CBTPairedModel::CBTPairedModel |
|
29 |
// --------------------------------------------------------------------- |
|
30 |
// |
|
31 |
CBTPairedModel::CBTPairedModel(MBTDeviceObserver* aObserver, TBTDeviceSortOrder* aOrder) |
|
32 |
: CBTDevModelBase(aObserver, aOrder) |
|
33 |
{ |
|
34 |
TRACE_FUNC_ENTRY |
|
35 |
TRACE_FUNC_EXIT |
|
36 |
} |
|
37 |
||
38 |
// --------------------------------------------------------------------- |
|
39 |
// CBTPairedModel::NewL |
|
40 |
// --------------------------------------------------------------------- |
|
41 |
// |
|
42 |
CBTPairedModel* CBTPairedModel::NewL(MBTDeviceObserver* aObserver, TBTDeviceSortOrder* aOrder ) |
|
43 |
{ |
|
44 |
CBTPairedModel* self = new (ELeave) CBTPairedModel(aObserver, aOrder); |
|
45 |
CleanupStack::PushL(self); |
|
46 |
self->ConstructL(); |
|
47 |
CleanupStack::Pop(self); |
|
48 |
||
49 |
return self; |
|
50 |
} |
|
51 |
||
52 |
// -------------------------------------------------------------------------------------------- |
|
53 |
// Destructor |
|
54 |
// -------------------------------------------------------------------------------------------- |
|
55 |
// |
|
56 |
CBTPairedModel::~CBTPairedModel() |
|
57 |
{ |
|
58 |
TRACE_FUNC_ENTRY |
|
59 |
||
60 |
delete iConnMan; |
|
61 |
delete iPairingDevice; |
|
72
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
62 |
delete iDisconnectDevice; |
56 | 63 |
delete iLinks; |
64 |
delete iBtEngSettings; |
|
65 |
iSocketServ.Close(); |
|
66 |
||
67 |
TRACE_FUNC_EXIT |
|
68 |
} |
|
69 |
||
70 |
// --------------------------------------------------------------------- |
|
71 |
// CBTPairedModel::ConstructL |
|
72 |
// ---------------------------------------------------------------------- |
|
73 |
// |
|
74 |
void CBTPairedModel::ConstructL() |
|
75 |
{ |
|
76 |
TRACE_FUNC_ENTRY |
|
77 |
||
78 |
// get all devices from btregistry to cache - local copy of CBTDeviceArray |
|
79 |
iDevMan = CBTEngDevMan::NewL(this); |
|
80 |
iConnMan = CBTEngConnMan::NewL(this); |
|
81 |
iSearchPattern.FindAll(); |
|
82 |
iRegistryObserver = CBTRegistryObserver::NewL(this, iSearchPattern); |
|
83 |
iRegistryObserver->Refresh(); |
|
84 |
User::LeaveIfError( iSocketServ.Connect() ); |
|
85 |
iLinks=CBluetoothPhysicalLinks::NewL(*this,iSocketServ); |
|
86 |
||
87 |
iBtEngSettings = CBTEngSettings::NewL(this); |
|
88 |
||
89 |
TRACE_FUNC_EXIT |
|
90 |
} |
|
91 |
||
92 |
// --------------------------------------------------------------------- |
|
93 |
// CBTPairedModel::IsAnyDeviceConnected |
|
94 |
// ---------------------------------------------------------------------- |
|
95 |
// |
|
96 |
TBool CBTPairedModel::IsAnyDeviceConnected() |
|
97 |
{ |
|
98 |
TRACE_FUNC_ENTRY |
|
99 |
||
100 |
FlagPhysicallyConnectedDevices(iDeviceArray); |
|
101 |
||
102 |
for(TInt i = 0; i < iDeviceArray.Count(); i++) |
|
103 |
{ |
|
104 |
if(iDeviceArray[i]->iStatus & (EStatusPhysicallyConnected|EStatusBtuiConnected)) |
|
105 |
{ |
|
106 |
TRACE_FUNC_EXIT |
|
107 |
return ETrue; |
|
108 |
} |
|
109 |
} |
|
110 |
||
111 |
TRACE_FUNC_EXIT |
|
112 |
||
113 |
return EFalse; |
|
114 |
} |
|
115 |
||
116 |
// --------------------------------------------------------------------- |
|
117 |
// CBTPairedModel::DoChangeDevice |
|
118 |
// --------------------------------------------------------------------- |
|
119 |
||
120 |
TInt CBTPairedModel::DoChangeDeviceL(const TBTDevice& aDevice) |
|
121 |
{ |
|
122 |
TRACE_FUNC_ENTRY |
|
123 |
TRACE_BDADDR(aDevice.iAddr) |
|
124 |
// check that the device actually still exists |
|
125 |
if(aDevice.iOperation != EOpPair ) |
|
126 |
{ |
|
127 |
User::LeaveIfError( GetIndexByAddress(aDevice.iAddr, aDevice.iIndex ) ); |
|
128 |
} |
|
129 |
||
130 |
// disconnect device to be unpaired, or blocked |
|
131 |
if((aDevice.iOperation == EOpBlock || aDevice.iOperation == EOpUnpair )) |
|
132 |
{ |
|
133 |
if( iState != EDisconnectBeforeOperationState) |
|
134 |
{ |
|
72
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
135 |
TInt code = KErrNone; |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
136 |
iState=EDisconnectBeforeOperationState; |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
137 |
__ASSERT_DEBUG(iDisconnectDevice == NULL,PANIC(EBTPanicClassMemberVariableNotNull)); |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
138 |
iDisconnectDevice = new TBTDevice(aDevice); |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
139 |
|
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
140 |
if( iDisconnectDevice ) |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
141 |
{ |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
142 |
// disconnect by CBTEngConnMan if connected that way. |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
143 |
if ( aDevice.iStatus & static_cast<TInt>(EStatusBtuiConnected ) ) |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
144 |
{ |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
145 |
code = iConnMan->Disconnect(aDevice.iAddr,EBTDiscImmediate); |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
146 |
} |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
147 |
else // try disconnecting from the link layer |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
148 |
{ |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
149 |
code = iLinks->Disconnect(aDevice.iAddr); |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
150 |
} |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
151 |
} |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
152 |
else |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
153 |
{ |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
154 |
code = KErrNoMemory; |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
155 |
} |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
156 |
// if the return code is KErrNone then there will be |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
157 |
// a callback. However if it fails, there will not be any. |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
158 |
// So the execution will go on inside this method, if there was an error. |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
159 |
if( code == KErrNone ) |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
160 |
{ |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
161 |
return code; |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
162 |
} |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
163 |
else |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
164 |
{ |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
165 |
// Reset the state if error happened |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
166 |
TRACE_INFO((_L("[BTUI] CBTPairedModel::DoChangeDeviceL disconnect error = %d, operation %d"), code, aDevice.iOperation)); |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
167 |
delete iDisconnectDevice; |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
168 |
iDisconnectDevice = NULL; |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
169 |
iState = EIdleState; |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
170 |
} |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
171 |
} |
56 | 172 |
} |
72
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
173 |
else |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
174 |
{ |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
175 |
iState=EIdleState; |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
176 |
} |
56 | 177 |
|
178 |
if( aDevice.iOperation ==EOpPair) |
|
179 |
{ |
|
180 |
DoPairDeviceL(); |
|
181 |
TRACE_FUNC_EXIT |
|
182 |
return KErrNone; |
|
183 |
} |
|
184 |
||
185 |
TInt err = CBTDevModelBase::DoChangeDeviceL(aDevice); |
|
72
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
186 |
|
56 | 187 |
if (err != KErrNone) |
188 |
{ |
|
189 |
TBTDevAddr addr; |
|
190 |
if(aDevice.iAddr == KNullAddress ) |
|
191 |
{ |
|
192 |
if(aDevice.iIndex < 0 || aDevice.iIndex >= iDeviceArray.Count()) |
|
193 |
return KErrArgument; |
|
194 |
else |
|
195 |
addr=iDeviceArray[aDevice.iIndex]->iAddr; |
|
196 |
} |
|
197 |
else |
|
198 |
addr=aDevice.iAddr; |
|
199 |
||
200 |
switch (aDevice.iOperation) |
|
201 |
{ |
|
202 |
case EOpConnect: |
|
203 |
{ |
|
204 |
err = iConnMan->Connect(addr, aDevice.iDeviceClass); |
|
205 |
break; |
|
206 |
} |
|
207 |
case EOpDisconnect: |
|
208 |
{ |
|
72
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
209 |
__ASSERT_DEBUG(iDisconnectDevice == NULL,PANIC(EBTPanicClassMemberVariableNotNull)); |
56 | 210 |
iDisconnectDevice=new(ELeave) TBTDevice(aDevice); |
211 |
if (aDevice.iStatus & static_cast<TInt>(EStatusBtuiConnected ) ) |
|
212 |
{ |
|
213 |
err = iConnMan->Disconnect(addr, EBTDiscImmediate); |
|
214 |
} |
|
215 |
else |
|
216 |
{ |
|
217 |
err=iLinks->Disconnect(aDevice.iAddr); |
|
218 |
} |
|
72
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
219 |
// Reset the state if error happened |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
220 |
if( err ) |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
221 |
{ |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
222 |
TRACE_INFO((_L("[BTUI] CBTPairedModel::DoChangeDeviceL disconnect error = %d, operation %d"), err, aDevice.iOperation)); |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
223 |
delete iDisconnectDevice; |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
224 |
iDisconnectDevice = NULL; |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
225 |
iState = EIdleState; |
4b59561a31c0
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
226 |
} |
56 | 227 |
break; |
228 |
} |
|
229 |
default: |
|
230 |
User::Leave(err); |
|
231 |
break; |
|
232 |
} |
|
233 |
} |
|
234 |
||
235 |
TRACE_FUNC_EXIT |
|
236 |
||
237 |
return err; |
|
238 |
} |
|
239 |
||
240 |
// --------------------------------------------------------------------- |
|
241 |
// CBTPairedModel::DoCancelChange |
|
242 |
// --------------------------------------------------------------------- |
|
243 |
// |
|
244 |
void CBTPairedModel::DoCancelChangeL(const TBTDevice& aDevice) |
|
245 |
{ |
|
246 |
TRACE_FUNC_ENTRY |
|
247 |
||
248 |
if(aDevice.iIndex >= iDeviceArray.Count()) |
|
249 |
{ |
|
250 |
TRACE_INFO((_L("index is %d, max expected is %d"), aDevice.iIndex, iDeviceArray.Count())); |
|
251 |
TRACE_FUNC_EXIT |
|
252 |
return; |
|
253 |
} |
|
254 |
||
255 |
// in case it was stopped |
|
256 |
iRegistryObserver->StartIfNotRunning(); |
|
257 |
switch (aDevice.iOperation) |
|
258 |
{ |
|
259 |
case EOpPair: |
|
260 |
if( iState==EDeleteDeviceState || iState==EAddDeviceState ) |
|
261 |
{ |
|
262 |
iDevMan->Cancel(); |
|
263 |
} |
|
264 |
else |
|
265 |
{ |
|
266 |
iConnMan->CancelPairDevice(); |
|
267 |
} |
|
268 |
delete iPairingDevice; |
|
269 |
iPairingDevice=NULL; |
|
270 |
iState=EIdleState; |
|
271 |
iRegistryObserver->Refresh(); |
|
272 |
break; |
|
273 |
||
274 |
case EOpConnect: |
|
275 |
{ |
|
276 |
||
277 |
TBTDevAddr addr; |
|
278 |
if(aDevice.iIndex == KErrNotFound) |
|
279 |
{ |
|
280 |
addr=aDevice.iAddr; |
|
281 |
} |
|
282 |
else |
|
283 |
{ |
|
284 |
addr=iDeviceArray[aDevice.iIndex]->iAddr; |
|
285 |
} |
|
286 |
||
287 |
iConnMan->CancelConnect(addr); |
|
288 |
break; |
|
289 |
} |
|
290 |
default: |
|
291 |
CBTDevModelBase::CancelChange(aDevice); |
|
292 |
return; |
|
293 |
} |
|
294 |
iRegistryObserver->StartIfNotRunning(); |
|
295 |
||
296 |
if(iQueue.Count()>0) |
|
297 |
{ |
|
298 |
delete iQueue[0]; |
|
299 |
iQueue.Remove(0); |
|
300 |
HandleQueue(); |
|
301 |
} |
|
302 |
||
303 |
TRACE_FUNC_EXIT |
|
304 |
} |
|
305 |
||
306 |
// --------------------------------------------------------------------- |
|
307 |
// CBTPairedModel::HandleNewDevice |
|
308 |
// |
|
309 |
// Adds the device if it is not banned |
|
310 |
// --------------------------------------------------------------------- |
|
311 |
// |
|
312 |
void CBTPairedModel::HandleNewDeviceL(const CBTDevice* aRegDevice, |
|
313 |
TNameEntry* aNameEntry) |
|
314 |
{ |
|
315 |
TRACE_FUNC_ENTRY |
|
316 |
||
317 |
// It is needed to filter out blocked devices, |
|
318 |
// since otherwise blocked and paired devices would |
|
319 |
// be listed. |
|
320 |
if( ! aRegDevice->GlobalSecurity().Banned() |
|
321 |
&& IsUserAwarePaired( aRegDevice->AsNamelessDevice() ) ) |
|
322 |
{ |
|
323 |
AddDeviceL(aRegDevice, aNameEntry, EOpNone); |
|
324 |
} |
|
325 |
||
326 |
TRACE_FUNC_EXIT |
|
327 |
} |
|
328 |
||
329 |
// ----------------------------------------------------------------------- |
|
330 |
// CBTPairedModel::CreateDevice |
|
331 |
// |
|
332 |
// This implementaion will add the connectable status from the superclass. |
|
333 |
// ----------------------------------------------------------------------- |
|
334 |
// |
|
335 |
TBTDevice* CBTPairedModel::CreateDeviceL(const CBTDevice* aRegDevice, |
|
336 |
TNameEntry* aNameEntry) |
|
337 |
{ |
|
338 |
TRACE_FUNC_ENTRY |
|
339 |
||
340 |
TBTDevice* device = CBTDevModelBase::CreateDeviceL(aRegDevice, aNameEntry); |
|
341 |
||
342 |
// add EStatusBtuiConnected status if the device has a profile connection |
|
343 |
TBTEngConnectionStatus connStatus; |
|
344 |
iConnMan->IsConnected(device->iAddr, connStatus); |
|
345 |
||
346 |
if(connStatus == EBTEngConnecting || connStatus == EBTEngConnected) |
|
347 |
{ |
|
348 |
SetStatusFlags(device->iStatus,EStatusBtuiConnected); |
|
349 |
} |
|
350 |
||
351 |
// add connectable status |
|
352 |
TBool connectable=EFalse; |
|
353 |
iConnMan->IsConnectable(aRegDevice->BDAddr(), aRegDevice->DeviceClass(), connectable ); |
|
354 |
||
355 |
if( connectable) |
|
356 |
{ |
|
357 |
SetStatusFlags(device->iStatus, EStatusConnectable ); |
|
358 |
} |
|
359 |
||
360 |
TRACE_FUNC_EXIT |
|
361 |
||
362 |
return device; |
|
363 |
} |
|
364 |
||
365 |
// --------------------------------------------------------------------- |
|
366 |
// CBTPairedModel::ConnectComplete |
|
367 |
// from MBTEngConnObserver |
|
368 |
// ---------------------------------------------------------------------- |
|
369 |
// |
|
370 |
void CBTPairedModel::ConnectComplete(TBTDevAddr& aAddr, TInt aErr, RBTDevAddrArray* aConflicts) |
|
371 |
{ |
|
372 |
TRACE_FUNC_ENTRY |
|
373 |
||
374 |
TRACE_INFO((_L("aErr=%d"), aErr)) |
|
375 |
||
376 |
TInt index = GetIndexByAddress(aAddr); |
|
377 |
TBool requestIssuedFromPhone = EFalse; |
|
378 |
TBTDevice connectedDevice; |
|
379 |
||
380 |
// was the device connected from request by the ui |
|
381 |
if(iQueue.Count()>0 && iQueue[0]->iOperation==EOpConnect && |
|
382 |
iQueue[0]->iAddr == aAddr) |
|
383 |
{ |
|
384 |
requestIssuedFromPhone = ETrue; |
|
385 |
if(index >=0) // is it from paired list |
|
386 |
{ |
|
387 |
connectedDevice=*iDeviceArray[index]; |
|
388 |
connectedDevice.iOperation=EOpConnect; |
|
389 |
} |
|
390 |
else |
|
391 |
{ |
|
392 |
connectedDevice=*iQueue[0]; |
|
393 |
} |
|
394 |
||
395 |
} |
|
396 |
else |
|
397 |
{ |
|
398 |
requestIssuedFromPhone = EFalse; |
|
399 |
if(index >=0) // is it from paired list |
|
400 |
{ |
|
401 |
connectedDevice=*iDeviceArray[index]; |
|
402 |
connectedDevice.iOperation=EOpConnect; |
|
403 |
} |
|
404 |
else |
|
405 |
{ |
|
406 |
// it was not. Try to fill what can be filled. |
|
407 |
connectedDevice.iAddr=aAddr; |
|
408 |
connectedDevice.iIndex=KErrNotFound; |
|
409 |
connectedDevice.iOperation = EOpConnect; |
|
410 |
} |
|
411 |
} |
|
412 |
||
413 |
if (aErr == KErrAlreadyExists ) |
|
414 |
{ |
|
415 |
// gather the names of the conflicting devices. |
|
416 |
RBTDevNameArray nameArray; |
|
417 |
for (TInt i = 0; aConflicts!= NULL && i < aConflicts->Count(); i++) |
|
418 |
{ |
|
419 |
//remove duplicates |
|
420 |
if(i>0&& (*aConflicts)[i]==(*aConflicts)[i-1]) |
|
421 |
{ |
|
422 |
continue; |
|
423 |
} |
|
424 |
TInt di = GetIndexByAddress((*aConflicts)[i]); |
|
425 |
||
426 |
if(di >=0 ) |
|
427 |
{ |
|
428 |
nameArray.Append(&iDeviceArray[di]->iName); |
|
429 |
} |
|
430 |
} |
|
431 |
||
432 |
// we will unset the connect status of the device if connection failed & |
|
433 |
// it is found in paired devices. |
|
434 |
if( index >= 0 ) |
|
435 |
{ |
|
436 |
// add EStatusBtuiConnected status if the device has a profile connection |
|
437 |
TBTEngConnectionStatus connStatus; |
|
438 |
iConnMan->IsConnected(connectedDevice.iAddr, connStatus); |
|
439 |
||
440 |
if (connStatus != EBTEngConnecting && connStatus != EBTEngConnected) |
|
441 |
{ |
|
442 |
TRACE_INFO(_L("Unset EStatusBtuiConnected")) |
|
443 |
UnsetStatusFlags(iDeviceArray[index]->iStatus,EStatusBtuiConnected ); |
|
444 |
} |
|
445 |
} |
|
446 |
||
447 |
if(iObserver) |
|
448 |
{ |
|
449 |
//Show only phone issued request complete notes |
|
450 |
//Do not show notes for device issued request when BTUI is active |
|
451 |
if ( requestIssuedFromPhone ) |
|
452 |
{ |
|
453 |
iObserver->NotifyChangeDeviceComplete(aErr, connectedDevice, &nameArray); |
|
454 |
} |
|
455 |
||
456 |
SendRefreshIfNoError(aErr); |
|
457 |
} |
|
458 |
nameArray.Reset(); |
|
459 |
} |
|
460 |
else |
|
461 |
{ |
|
462 |
if (aErr == KErrNone) |
|
463 |
{ |
|
464 |
// we will set the connect status of the device |
|
465 |
// if it is found in paired devices. |
|
466 |
if( index >= 0 ) |
|
467 |
{ |
|
468 |
SetStatusFlags(iDeviceArray[index]->iStatus,EStatusBtuiConnected ); |
|
469 |
} |
|
470 |
} |
|
471 |
else |
|
472 |
{ |
|
473 |
// we will unset the connect status of the device if connection failed & |
|
474 |
// it is found in paired devices. |
|
475 |
if( index >= 0 ) |
|
476 |
{ |
|
477 |
// add EStatusBtuiConnected status if the device has a profile connection |
|
478 |
TBTEngConnectionStatus connStatus; |
|
479 |
iConnMan->IsConnected(connectedDevice.iAddr, connStatus); |
|
480 |
||
481 |
if (connStatus != EBTEngConnecting && connStatus != EBTEngConnected) |
|
482 |
{ |
|
483 |
TRACE_INFO(_L("Unset EStatusBtuiConnected")) |
|
484 |
UnsetStatusFlags(iDeviceArray[index]->iStatus,EStatusBtuiConnected ); |
|
485 |
} |
|
486 |
} |
|
487 |
} |
|
488 |
if(iObserver) |
|
489 |
{ |
|
490 |
//Show only phone issued request complete notes |
|
491 |
//Do not show notes for device issued request when BTUI is active |
|
492 |
if ( requestIssuedFromPhone ) |
|
493 |
{ |
|
494 |
iObserver->NotifyChangeDeviceComplete(aErr, connectedDevice); |
|
495 |
} |
|
496 |
||
497 |
SendRefreshIfNoError(aErr); |
|
498 |
} |
|
499 |
} |
|
500 |
||
501 |
// Process the next command if the connect was |
|
502 |
//initiated by this UI. |
|
503 |
if(iQueue.Count()>0 && iQueue[0]->iOperation==EOpConnect && |
|
504 |
iQueue[0]->iAddr == aAddr) |
|
505 |
{ |
|
506 |
delete iQueue[0]; |
|
507 |
iQueue.Remove(0); |
|
508 |
HandleQueue(); |
|
509 |
} |
|
510 |
else |
|
511 |
{ |
|
512 |
if( iQueue.Count()==0 ) |
|
513 |
{ |
|
514 |
TRACE_INFO((_L("op Q is empty"))); |
|
515 |
} |
|
516 |
else |
|
517 |
{ |
|
518 |
TRACE_INFO((_L("unexpected op Q contents, count is %d, op is %d"), iDeviceArray.Count(), iQueue[0]->iOperation)); |
|
519 |
} |
|
520 |
} |
|
521 |
TRACE_FUNC_EXIT |
|
522 |
} |
|
523 |
||
524 |
// --------------------------------------------------------------------- |
|
525 |
// CBTPairedModel::PowerStateChanged |
|
526 |
// from MBTEngSettingObserver |
|
527 |
// ---------------------------------------------------------------------- |
|
528 |
// |
|
529 |
void CBTPairedModel::PowerStateChanged( TBTPowerStateValue ) |
|
530 |
{ |
|
531 |
TRACE_FUNC_ENTRY |
|
532 |
||
533 |
// This is implemented for case like when user choses offlne mode, Bluetooth is swithced off |
|
534 |
// very fast. Bt audio components don't have enough time to close audio connection. |
|
535 |
// BTUI needs to update UI display. |
|
536 |
||
537 |
TInt count = iDeviceArray.Count(); |
|
538 |
||
539 |
for (TInt i = 0; i < count; i++) |
|
540 |
{ |
|
541 |
UnsetStatusFlags(iDeviceArray[i]->iStatus, EStatusBtuiConnected ); |
|
542 |
} |
|
543 |
||
544 |
SendRefreshIfNoError(KErrNone); |
|
545 |
||
546 |
TRACE_FUNC_EXIT |
|
547 |
} |
|
548 |
||
549 |
// ---------------------------------------------------- |
|
550 |
// CBTPairedModel::VisibilityModeChanged |
|
551 |
// from MBTEngSettingObserver |
|
552 |
// ---------------------------------------------------- |
|
553 |
// |
|
554 |
void CBTPairedModel::VisibilityModeChanged( TBTVisibilityMode ) |
|
555 |
{ |
|
556 |
TRACE_FUNC_ENTRY |
|
557 |
||
558 |
||
559 |
TRACE_FUNC_EXIT |
|
560 |
} |
|
561 |
||
562 |
// --------------------------------------------------------------------- |
|
563 |
// CBTPairedModel::DisconnectComplete |
|
564 |
// from MBTEngConnObserver |
|
565 |
// ---------------------------------------------------------------------- |
|
566 |
// |
|
567 |
void CBTPairedModel::DisconnectComplete(TBTDevAddr& aAddr, TInt aErr) |
|
568 |
{ |
|
569 |
TRACE_FUNC_ENTRY |
|
570 |
||
571 |
// the disconnect was part of a unpairing or blocking operation |
|
572 |
if(iState == EDisconnectBeforeOperationState && iDisconnectDevice && aAddr == iDisconnectDevice->iAddr ) |
|
573 |
{ |
|
574 |
||
575 |
TRAPD(err, |
|
576 |
DoChangeDeviceL(*iDisconnectDevice); |
|
577 |
); |
|
578 |
iState=EIdleState; |
|
579 |
if(err != KErrNone) |
|
580 |
{ |
|
581 |
HandleLeave(err,iDisconnectDevice); |
|
582 |
} |
|
583 |
TRACE_FUNC_EXIT |
|
584 |
return; |
|
585 |
} |
|
586 |
||
587 |
TInt index = GetIndexByAddress(aAddr); |
|
588 |
||
589 |
// the disconnected device was not the devicein the list, |
|
590 |
// so we do not tell anyone about it. |
|
591 |
if ( iDisconnectDevice == NULL || iDisconnectDevice->iAddr != aAddr ) |
|
592 |
{ |
|
593 |
if (index >=0 ) |
|
594 |
{ |
|
595 |
UnsetStatusFlags(iDeviceArray[index]->iStatus, EStatusBtuiConnected ); |
|
596 |
} |
|
597 |
||
598 |
SendRefreshIfNoError(KErrNone); |
|
599 |
||
600 |
TBTDevice disconnectedDevice; |
|
601 |
disconnectedDevice.iAddr = aAddr; |
|
602 |
// Notify needed when there is active disconnect query dialog |
|
603 |
iObserver->NotifyChangeDeviceComplete(KErrDisconnected, disconnectedDevice); |
|
604 |
||
605 |
TRACE_FUNC_EXIT |
|
606 |
return; |
|
607 |
} |
|
608 |
||
609 |
if(index >=0 ) |
|
610 |
{ |
|
611 |
// set it to "not connected" no matter disconnection works or not |
|
612 |
UnsetStatusFlags(iDeviceArray[index]->iStatus, EStatusBtuiConnected ); |
|
613 |
iDeviceArray[index]->iOperation = EOpDisconnect; |
|
614 |
iObserver->NotifyChangeDeviceComplete(aErr, *iDeviceArray[index]); |
|
615 |
} |
|
616 |
else |
|
617 |
{ |
|
618 |
iDisconnectDevice->iIndex=index; |
|
619 |
iObserver->NotifyChangeDeviceComplete(aErr, *iDisconnectDevice); |
|
620 |
} |
|
621 |
||
622 |
delete iDisconnectDevice; |
|
623 |
iDisconnectDevice=NULL; |
|
624 |
||
625 |
SendRefreshIfNoError(aErr); |
|
626 |
// continue processing queue only if the disconnected device is |
|
627 |
// the device with we requested disconnect to. |
|
628 |
// this has to be checked so that we do not end on having multiple |
|
629 |
// queue processors at the same time |
|
630 |
if(iQueue.Count()>0 && iQueue[0]->iOperation==EOpDisconnect && |
|
631 |
iQueue[0]->iAddr == aAddr) |
|
632 |
{ |
|
633 |
delete iQueue[0]; |
|
634 |
iQueue.Remove(0); |
|
635 |
HandleQueue(); |
|
636 |
} |
|
637 |
else |
|
638 |
{ |
|
639 |
if( iQueue.Count()==0 ) |
|
640 |
{ |
|
641 |
TRACE_INFO((_L("op Q is empty"))); |
|
642 |
} |
|
643 |
else |
|
644 |
{ |
|
645 |
TRACE_INFO((_L("unexpected op Q contents, count is %d, op is %d"), iDeviceArray.Count(), iQueue[0]->iOperation)); |
|
646 |
} |
|
647 |
} |
|
648 |
TRACE_FUNC_EXIT |
|
649 |
} |
|
650 |
||
651 |
// --------------------------------------------------------------------- |
|
652 |
// CBTPairedModel::PairingComplete |
|
653 |
// from MBTEngConnObserver |
|
654 |
// ---------------------------------------------------------------------- |
|
655 |
// |
|
656 |
void CBTPairedModel::PairingComplete(TBTDevAddr& aAddr, TInt aErr) |
|
657 |
{ |
|
658 |
TRACE_FUNC_ENTRY |
|
659 |
||
660 |
TRAPD(err, |
|
661 |
PairingCompleteL(aAddr,aErr); |
|
662 |
); |
|
663 |
||
664 |
if(err!=KErrNone) |
|
665 |
{ |
|
666 |
TBTDevice tmp; |
|
667 |
tmp.iAddr=aAddr; |
|
668 |
tmp.iIndex=GetIndexByAddress(aAddr); |
|
669 |
tmp.iOperation=EOpPair; |
|
670 |
HandleLeave(err,&tmp ); |
|
671 |
||
672 |
delete iPairingDevice; |
|
673 |
iPairingDevice=NULL; |
|
674 |
} |
|
675 |
||
676 |
TRACE_FUNC_EXIT |
|
677 |
} |
|
678 |
||
679 |
// --------------------------------------------------------------------- |
|
680 |
// CBTPairedModel::PairingCompleteL |
|
681 |
// Leaving version of PairingComplete |
|
682 |
// ---------------------------------------------------------------------- |
|
683 |
// |
|
684 |
void CBTPairedModel::PairingCompleteL(TBTDevAddr& aAddr, TInt aErr) |
|
685 |
{ |
|
686 |
TRACE_FUNC_ENTRY |
|
687 |
||
688 |
// The device that was attempted to be paired is |
|
689 |
// different from the the device that the pairing is finnished. |
|
690 |
// This cannot happen, since CBTConnMan will report |
|
691 |
// only pairing started by the listener and the UI |
|
692 |
// does not allow making two pairings at the same time |
|
693 |
__ASSERT_DEBUG(aAddr==iPairingDevice->BDAddr(), |
|
694 |
PANIC(EBTPanicCommandComplettedToDiffrentDeviceThanStarted)); |
|
695 |
(void) aAddr; |
|
696 |
||
697 |
// bail out if the operation queue is not what we expect |
|
698 |
if( iQueue.Count() == 0 |
|
699 |
|| iQueue[0]->iOperation != EOpPair |
|
700 |
|| iQueue[0]->iAddr != aAddr ) |
|
701 |
{ |
|
702 |
if( iQueue.Count()==0 ) |
|
703 |
{ |
|
704 |
TRACE_INFO((_L("op Q is empty"))); |
|
705 |
} |
|
706 |
else |
|
707 |
{ |
|
708 |
TRACE_INFO((_L("unexpected op Q contents, count is %d, op is %d"), iDeviceArray.Count(), iQueue[0]->iOperation)); |
|
709 |
} |
|
710 |
TRACE_FUNC_EXIT |
|
711 |
return; |
|
712 |
} |
|
713 |
||
714 |
iState=EIdleState; |
|
715 |
TBTDevice* tmpDevice=NULL; |
|
716 |
tmpDevice=CreateDeviceL(iPairingDevice, &( iQueue[0]->iNameEntry ) ); |
|
717 |
tmpDevice->iOperation=EOpPair; |
|
718 |
||
719 |
// new paired device must be inserted to the array, since |
|
720 |
// user may be doing trust/ connect operations before |
|
721 |
// it is refreshed from registry |
|
722 |
TBool deleleteTmpDevice=ETrue; |
|
723 |
||
724 |
if( aErr == KErrNone ) |
|
725 |
{ |
|
726 |
SetStatusFlags(tmpDevice->iStatus,EStatusPaired); |
|
727 |
TInt index; |
|
728 |
index=GetIndexByAddress(iPairingDevice->BDAddr()); |
|
729 |
||
730 |
if(index == KErrNotFound) |
|
731 |
{ |
|
732 |
iDeviceArray.InsertInOrderL(tmpDevice,*iSortOrder ); |
|
733 |
||
734 |
RenumberDeviceArray(); |
|
735 |
||
736 |
// iPairingDevice is now owned by iDeviceArray. |
|
737 |
// So it must not be deleted by his function |
|
738 |
deleleteTmpDevice=EFalse; |
|
739 |
||
740 |
SendRefreshIfNoError(aErr,GetIndexByAddress(iPairingDevice->BDAddr())); |
|
741 |
} |
|
742 |
} |
|
743 |
||
744 |
||
745 |
iObserver->NotifyChangeDeviceComplete(aErr, *tmpDevice); |
|
746 |
||
747 |
/* |
|
748 |
* We issue an background refresh in case |
|
749 |
* registry is updated from btnotif |
|
750 |
*/ |
|
751 |
iRegistryObserver->StartIfNotRunning(); |
|
752 |
iRegistryObserver->Refresh(); |
|
753 |
// delete if the ownership has not changed |
|
754 |
if(deleleteTmpDevice ) |
|
755 |
{ |
|
756 |
delete tmpDevice; |
|
757 |
tmpDevice=NULL; |
|
758 |
} |
|
759 |
||
760 |
delete iPairingDevice; |
|
761 |
iPairingDevice=NULL; |
|
762 |
delete iQueue[0]; |
|
763 |
iQueue.Remove(0); |
|
764 |
||
765 |
HandleQueue(); |
|
766 |
||
767 |
TRACE_FUNC_EXIT |
|
768 |
} |
|
769 |
||
770 |
// --------------------------------------------------------------------- |
|
771 |
// BTPairedModel::HandleDevManComplete |
|
772 |
// from MBTEngDevModelBase |
|
773 |
// ---------------------------------------------------------------------- |
|
774 |
// |
|
775 |
void CBTPairedModel::HandleDevManComplete(TInt aErr) |
|
776 |
{ |
|
777 |
TRACE_FUNC_ENTRY |
|
778 |
||
779 |
// if this is handled we can remove this |
|
780 |
if(iDisconnectDevice) |
|
781 |
{ |
|
782 |
delete iDisconnectDevice; |
|
783 |
iDisconnectDevice=NULL; |
|
784 |
} |
|
785 |
||
786 |
if(iPairingDevice) |
|
787 |
{ |
|
788 |
// add the device just deleted |
|
789 |
if(iState==EDeleteDeviceState && (aErr==KErrNone || aErr == KErrNotFound)) |
|
790 |
{ |
|
791 |
iPairingDevice->DeleteLinkKey(); |
|
792 |
TBTDeviceSecurity sec=iPairingDevice->GlobalSecurity(); |
|
793 |
sec.SetBanned(EFalse); |
|
794 |
sec.SetNoAuthorise(EFalse); |
|
795 |
iDevMan->AddDevice(*iPairingDevice); |
|
796 |
iState=EAddDeviceState; |
|
797 |
TRACE_FUNC_EXIT |
|
798 |
return; |
|
799 |
} |
|
800 |
// if the device is added allready, or if deletion failed |
|
801 |
// we will go on with pairing the device |
|
802 |
if(iState==EAddDeviceState||(iState==EDeleteDeviceState&& aErr != KErrNone)) |
|
803 |
{ |
|
804 |
aErr = iConnMan->PairDevice(iPairingDevice->BDAddr(), iPairingDevice->DeviceClass()); |
|
805 |
iState=EPairDeviceState; |
|
806 |
// NOTE: now PairingComplete will be called and not this method. |
|
807 |
TRACE_FUNC_EXIT |
|
808 |
return; |
|
809 |
} |
|
810 |
} |
|
811 |
// these are not handled by superclass |
|
812 |
if(iQueue.Count()>0 && |
|
813 |
( iQueue[0]->iOperation==EOpConnect || |
|
814 |
iQueue[0]->iOperation==EOpDisconnect ) ) |
|
815 |
{ |
|
816 |
iObserver->NotifyChangeDeviceComplete(aErr, *iQueue[0]); |
|
817 |
} |
|
818 |
||
819 |
CBTDevModelBase::HandleDevManComplete(aErr); |
|
820 |
||
821 |
TRACE_FUNC_EXIT |
|
822 |
} |
|
823 |
||
824 |
// --------------------------------------------------------------------- |
|
825 |
// CBTPairedModel::DoPairDevice |
|
826 |
// --------------------------------------------------------------------- |
|
827 |
// |
|
828 |
void CBTPairedModel::DoPairDeviceL() |
|
829 |
{ |
|
830 |
TRACE_FUNC_ENTRY |
|
831 |
||
832 |
// we are starting a new command. Checks that no earlier commands |
|
833 |
// have been executed, but not finished properly. |
|
834 |
__ASSERT_DEBUG(iState==EIdleState,PANIC(EBTPanicDevManQueueIsInIllegalState)); |
|
835 |
// check that there is no other pairing going on. |
|
836 |
__ASSERT_DEBUG(iPairingDevice!=NULL,PANIC(EBTPanicTwoPairingAttemptsAtTheSameTime)); |
|
837 |
||
838 |
iRegistryObserver->Cancel(); |
|
839 |
||
840 |
// devices to be paired are first deleted |
|
841 |
// then added back. Only after that the paring itself is |
|
842 |
// started |
|
843 |
TBTRegistrySearch dele; |
|
844 |
dele.FindAddress(iPairingDevice->BDAddr()); |
|
845 |
TInt err = iDevMan->DeleteDevices(dele); |
|
846 |
||
847 |
iState=EDeleteDeviceState; |
|
848 |
if (err) |
|
849 |
{ |
|
850 |
HandleDevManComplete(err); |
|
851 |
} |
|
852 |
||
853 |
TRACE_FUNC_EXIT |
|
854 |
} |
|
855 |
||
856 |
// --------------------------------------------------------------------- |
|
857 |
// CBTPairedModel::PairDevice |
|
858 |
// |
|
859 |
// Puts the given aPairingDevice to iPairingDevice and |
|
860 |
// adds and empty device with iOperation=EOpPair as placeholder to iQueue. |
|
861 |
// the pairing itself will be handled by DoChangeDevice that |
|
862 |
// cals then |
|
863 |
// --------------------------------------------------------------------- |
|
864 |
// |
|
865 |
TInt CBTPairedModel::PairDeviceL(const CBTDevice* aPairingDevice, |
|
866 |
TNameEntry* aNameEntry) |
|
867 |
{ |
|
868 |
TRACE_FUNC_ENTRY |
|
869 |
||
870 |
// cannot put two pairings to queue. |
|
871 |
// this is not possible since ui does not allow it. |
|
872 |
if(iPairingDevice) |
|
873 |
return KErrInUse; |
|
874 |
||
875 |
TBTDevice* device=new(ELeave) TBTDevice(); |
|
876 |
device->iOperation=EOpPair; |
|
877 |
device->iAddr=aPairingDevice->BDAddr(); |
|
878 |
if ( aNameEntry ) |
|
879 |
{ |
|
880 |
device->iNameEntry = *aNameEntry; |
|
881 |
} |
|
882 |
CleanupStack::PushL(device); |
|
883 |
iPairingDevice=aPairingDevice->CopyL(); |
|
884 |
// put the device to queue directly |
|
885 |
iQueue.AppendL(device); |
|
886 |
TInt err = KErrNone; |
|
887 |
if(iQueue.Count() ==1 ) |
|
888 |
{ |
|
889 |
err = DoChangeDeviceL(*iQueue[0]); |
|
890 |
} |
|
891 |
CleanupStack::Pop(device); |
|
892 |
TRACE_FUNC_EXIT |
|
893 |
return err; |
|
894 |
||
895 |
} |
|
896 |
||
897 |
// --------------------------------------------------------------------- |
|
898 |
// CBTPairedModel::HandleDisconnectCompleteL |
|
899 |
// Disconnection by CBluetoothPhysicalLinks, for those |
|
900 |
// connections not opened by btui. |
|
901 |
// --------------------------------------------------------------------- |
|
902 |
// |
|
903 |
void CBTPairedModel::HandleDisconnectCompleteL(TInt aErr) |
|
904 |
{ |
|
905 |
TRACE_FUNC_ENTRY |
|
906 |
||
907 |
if(iDisconnectDevice) |
|
908 |
{ |
|
909 |
DisconnectComplete(iDisconnectDevice->iAddr,aErr); |
|
910 |
} |
|
911 |
||
912 |
TRACE_FUNC_EXIT |
|
913 |
} |
|
914 |
||
915 |
// --------------------------------------------------------------------- |
|
916 |
// CBTPairedModel::FlagPhysicallyConnectedDevices |
|
917 |
// |
|
918 |
// Marks the EStatusPhysicallyConnected attribute to the devices |
|
919 |
// that have active connection. |
|
920 |
// --------------------------------------------------------------------- |
|
921 |
// |
|
922 |
void CBTPairedModel::FlagPhysicallyConnectedDevices(RDeviceArray &aDeviceArray) |
|
923 |
{ |
|
924 |
TRACE_FUNC_ENTRY |
|
925 |
||
926 |
RBTDevAddrArray a; |
|
927 |
iLinks->Enumerate(a,KMaxCheckedConnections); |
|
928 |
||
929 |
TInt i=0; |
|
930 |
||
931 |
for(i=0;i<aDeviceArray.Count();i++) |
|
932 |
{ |
|
933 |
FlagPhysicallyConnectedDevices( *aDeviceArray[i], a ); |
|
934 |
} |
|
935 |
a.Close(); |
|
936 |
||
937 |
TRACE_FUNC_EXIT |
|
938 |
} |
|
939 |
||
940 |
void CBTPairedModel::FlagPhysicallyConnectedDevices(TBTDevice& aDevice, RBTDevAddrArray& aBTDeviceArray) |
|
941 |
{ |
|
942 |
TRACE_FUNC_ENTRY |
|
943 |
||
944 |
TInt i2=0; |
|
945 |
||
946 |
UnsetStatusFlags( aDevice.iStatus, EStatusPhysicallyConnected ); |
|
947 |
for( i2=0; i2<aBTDeviceArray.Count(); i2++ ) |
|
948 |
{ |
|
949 |
if(aDevice.iAddr == aBTDeviceArray[i2]) |
|
950 |
{ |
|
951 |
SetStatusFlags( aDevice.iStatus,EStatusPhysicallyConnected ); |
|
952 |
break; |
|
953 |
} |
|
954 |
} |
|
955 |
||
956 |
TRACE_FUNC_EXIT |
|
957 |
} |
|
958 |
||
959 |
// --------------------------------------------------------------------- |
|
960 |
// CBTPairedModel::GetDevice |
|
961 |
// |
|
962 |
// Adds the EPhysicallyConnected attribute devices that have any active |
|
963 |
// bluetooth connection. |
|
964 |
// --------------------------------------------------------------------- |
|
965 |
// |
|
966 |
TInt CBTPairedModel::GetDevice(TBTDevice& aDevice) |
|
967 |
{ |
|
968 |
TRACE_FUNC_ENTRY |
|
969 |
||
970 |
TInt rvalue=CBTDevModelBase::GetDevice(aDevice); |
|
971 |
RBTDevAddrArray a; |
|
972 |
iLinks->Enumerate(a,KMaxCheckedConnections); |
|
973 |
FlagPhysicallyConnectedDevices(aDevice, a); |
|
974 |
a.Close(); |
|
975 |
||
976 |
TRACE_FUNC_EXIT |
|
977 |
||
978 |
return rvalue; |
|
979 |
} |
|
980 |
||
981 |
// --------------------------------------------------------------------- |
|
982 |
// CBTPairedModel::HandleLeave |
|
983 |
// from CBTDevModelBase |
|
984 |
// --------------------------------------------------------------------- |
|
985 |
// |
|
986 |
void CBTPairedModel::HandleLeave(TInt aErr,const TBTDevice* aDevice ) |
|
987 |
{ |
|
988 |
TRACE_FUNC_ENTRY |
|
989 |
||
990 |
iConnMan->CancelPairDevice(); |
|
991 |
||
992 |
delete iPairingDevice; |
|
993 |
iPairingDevice=NULL; |
|
994 |
||
995 |
delete iDisconnectDevice; |
|
996 |
iDisconnectDevice=NULL; |
|
997 |
||
998 |
iRegistryObserver->StartIfNotRunning(); |
|
999 |
iRegistryObserver->Refresh(); |
|
1000 |
||
1001 |
iState=EIdleState; |
|
1002 |
||
1003 |
CBTDevModelBase::HandleLeave(aErr,aDevice ); |
|
1004 |
||
1005 |
TRACE_FUNC_EXIT |
|
1006 |
} |