31
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 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:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
#include "btdelegatedisconnect.h"
|
42
|
18 |
#include "btuiutil.h"
|
|
19 |
#include "btuiiconutil.h"
|
31
|
20 |
#include <QModelIndex>
|
42
|
21 |
#include <hblabel.h>
|
31
|
22 |
#include <btsettingmodel.h>
|
|
23 |
#include <btdevicemodel.h>
|
|
24 |
#include <hbnotificationdialog.h>
|
57
|
25 |
#include <bluetoothuitrace.h>
|
31
|
26 |
|
|
27 |
BtDelegateDisconnect::BtDelegateDisconnect(
|
|
28 |
BtSettingModel* settingModel,
|
|
29 |
BtDeviceModel* deviceModel, QObject *parent) :
|
42
|
30 |
BtAbstractDelegate(settingModel, deviceModel, parent), mBtengConnMan(0), mPhyLinks(0),
|
57
|
31 |
mActiveHandling(false), mAddrArrayIndex(0), mDisconOpt(DisconUnknown)
|
31
|
32 |
{
|
57
|
33 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
34 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
31
|
35 |
}
|
|
36 |
|
|
37 |
BtDelegateDisconnect::~BtDelegateDisconnect()
|
|
38 |
{
|
57
|
39 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
31
|
40 |
delete mBtengConnMan;
|
42
|
41 |
delete mPhyLinks;
|
|
42 |
mSocketServ.Close();
|
57
|
43 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
|
44 |
}
|
|
45 |
|
|
46 |
|
|
47 |
/*!
|
|
48 |
Returns the supported editor types.
|
|
49 |
\return the sum of supported editor types
|
|
50 |
*/
|
|
51 |
int BtDelegateDisconnect::supportedEditorTypes() const
|
|
52 |
{
|
|
53 |
return BtDelegate::DisconnectService
|
|
54 |
| BtDelegate::DisconnectAllConnections;
|
31
|
55 |
}
|
|
56 |
|
57
|
57 |
/*!
|
|
58 |
* disconnects remote device(s) from local device
|
|
59 |
* params of type QList<QVariant>:
|
|
60 |
* 1) DisconnectOption (either ServiceLevel, PhysicalLink or AllOngoingConnections)
|
|
61 |
* 2) remote device address (QString, not needed for AllOngoingConnections)
|
|
62 |
*/
|
31
|
63 |
void BtDelegateDisconnect::exec( const QVariant ¶ms )
|
|
64 |
{
|
57
|
65 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
42
|
66 |
int err;
|
57
|
67 |
|
|
68 |
// check if in use already
|
|
69 |
if ( mActiveHandling ) {
|
|
70 |
emit delegateCompleted(KErrInUse, this);
|
|
71 |
BOstraceFunctionExitExt( DUMMY_DEVLIST, this, KErrInUse);
|
|
72 |
return;
|
|
73 |
}
|
|
74 |
|
|
75 |
// check parameters
|
|
76 |
QList<QVariant> paramList = params.value< QList<QVariant> >();
|
|
77 |
if (!((paramList.count() == 1) || (paramList.count() == 2))) {
|
|
78 |
// wrong parameter count
|
|
79 |
emit delegateCompleted( KErrArgument, this );
|
|
80 |
BOstraceFunctionExitExt( DUMMY_DEVLIST, this, KErrArgument );
|
|
81 |
return;
|
|
82 |
}
|
|
83 |
|
|
84 |
// create btengconnman
|
31
|
85 |
if ( ! mBtengConnMan ){
|
42
|
86 |
TRAP( err, mBtengConnMan = CBTEngConnMan::NewL(this) );
|
|
87 |
}
|
57
|
88 |
if( err ) {
|
|
89 |
emit delegateCompleted(err, this);
|
|
90 |
BOstraceFunctionExitExt( DUMMY_DEVLIST, this, err );
|
42
|
91 |
return;
|
|
92 |
}
|
57
|
93 |
|
|
94 |
mDisconOpt = (DisconnectOption)paramList.at(0).toInt(); // DisconnectOption
|
|
95 |
|
|
96 |
if ( (mDisconOpt == ServiceLevel) || (mDisconOpt == PhysicalLink) ) {
|
|
97 |
// check 2nd parameter is ok
|
|
98 |
if ((paramList.count() != 2) || !paramList.at(1).canConvert<QString>()) {
|
|
99 |
emit delegateCompleted( KErrArgument, this );
|
|
100 |
BOstraceFunctionExitExt( DUMMY_DEVLIST, this, KErrArgument );
|
|
101 |
return;
|
42
|
102 |
}
|
57
|
103 |
QString strBtAddr = paramList.at(1).toString(); // remote device to operate on
|
|
104 |
BtTraceQString1( TRACE_DEBUG, DUMMY_DEVLIST, "device addr=", strBtAddr);
|
|
105 |
addrReadbleStringToSymbian( strBtAddr, mBtEngAddr );
|
42
|
106 |
|
|
107 |
mActiveHandling = true;
|
57
|
108 |
|
|
109 |
if (mDisconOpt == ServiceLevel){
|
|
110 |
disconnectServiceLevel();
|
|
111 |
}
|
|
112 |
else if (mDisconOpt == PhysicalLink){
|
|
113 |
disconnectPhysicalLink();
|
|
114 |
}
|
|
115 |
}
|
|
116 |
else if ( mDisconOpt == AllOngoingConnections ) {
|
|
117 |
err = mBtengConnMan->GetConnectedAddresses(mDevAddrArray);
|
|
118 |
//Added this condition because GetConnectedAddresses returns 0 even if no addresses
|
|
119 |
//are returned.
|
|
120 |
if(err || !(mDevAddrArray.Count())) {
|
|
121 |
emit delegateCompleted(err, this);
|
|
122 |
BOstraceFunctionExitExt( DUMMY_DEVLIST, this, err );
|
|
123 |
return;
|
|
124 |
}
|
42
|
125 |
|
57
|
126 |
mActiveHandling = true;
|
31
|
127 |
|
57
|
128 |
disconnectAllConnections_service();
|
|
129 |
}
|
|
130 |
else {
|
|
131 |
BTUI_ASSERT_X( 0, "BtDelegateDisconnect::exec()", "incorrect parameter" );
|
|
132 |
}
|
|
133 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
42
|
134 |
}
|
|
135 |
|
|
136 |
|
57
|
137 |
void BtDelegateDisconnect::disconnectAllConnections_service()
|
|
138 |
{
|
|
139 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
140 |
QString btStringAddr;
|
|
141 |
addrSymbianToReadbleString( btStringAddr, mDevAddrArray[mAddrArrayIndex] );
|
|
142 |
QModelIndex start = deviceModel()->index(0,0);
|
|
143 |
QModelIndexList indexList = deviceModel()->match(start,BtDeviceModel::ReadableBdaddrRole, btStringAddr);
|
|
144 |
// ToDo: what happens if device not found from the model? error handling needed!
|
|
145 |
QModelIndex index = indexList.at(0);
|
42
|
146 |
|
57
|
147 |
mBtEngAddr = mDevAddrArray[mAddrArrayIndex];
|
|
148 |
|
|
149 |
disconnectServiceLevel();
|
|
150 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
42
|
151 |
}
|
|
152 |
|
57
|
153 |
void BtDelegateDisconnect::disconnectAllConnections_physical()
|
|
154 |
{
|
|
155 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
156 |
QString btStringAddr;
|
|
157 |
addrSymbianToReadbleString( btStringAddr, mDevAddrArray[mAddrArrayIndex] );
|
|
158 |
QModelIndex start = deviceModel()->index(0,0);
|
|
159 |
QModelIndexList indexList = deviceModel()->match(start,BtDeviceModel::ReadableBdaddrRole, btStringAddr);
|
|
160 |
// ToDo: what happens if device not found from the model? error handling needed!
|
|
161 |
QModelIndex index = indexList.at(0);
|
31
|
162 |
|
57
|
163 |
mBtEngAddr = mDevAddrArray[mAddrArrayIndex];
|
|
164 |
|
|
165 |
disconnectPhysicalLink();
|
|
166 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
42
|
167 |
}
|
57
|
168 |
|
|
169 |
void BtDelegateDisconnect::disconnectServiceLevel()
|
|
170 |
{
|
|
171 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
42
|
172 |
int err;
|
|
173 |
TBTEngConnectionStatus connStatus = EBTEngNotConnected;
|
57
|
174 |
BtTraceBtAddr1( TRACE_DEBUG, DUMMY_DEVLIST, "calling btengconnman->isConnected() with device addr=", mBtEngAddr );
|
42
|
175 |
err = mBtengConnMan->IsConnected(mBtEngAddr, connStatus);
|
57
|
176 |
BOstraceExt2( TRACE_DEBUG, DUMMY_DEVLIST, "isConnected() ret = %d, conn status (0/2) = %d", err, connStatus);
|
|
177 |
|
|
178 |
//if ( !err && (connStatus == EBTEngConnected) ) {
|
|
179 |
// asynchronous call, see callback DisconnectComplete()
|
|
180 |
BtTraceBtAddr1( TRACE_DEBUG, DUMMY_DEVLIST, "btengconnman->Disconnect() with param device addr=", mBtEngAddr );
|
|
181 |
err = mBtengConnMan->Disconnect(mBtEngAddr, EBTDiscGraceful);
|
|
182 |
BOstraceExt1( TRACE_DEBUG, DUMMY_DEVLIST, "Disconnect() ret = %d", err);
|
|
183 |
//}
|
|
184 |
if (err) {
|
|
185 |
// handle error
|
|
186 |
disconnectServiceLevelCompleted(err);
|
31
|
187 |
}
|
57
|
188 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
42
|
189 |
}
|
|
190 |
|
57
|
191 |
void BtDelegateDisconnect::disconnectPhysicalLink()
|
|
192 |
{
|
|
193 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
42
|
194 |
int err;
|
|
195 |
if ( !mSocketServ.Handle() ) {
|
|
196 |
err = mSocketServ.Connect();
|
|
197 |
}
|
|
198 |
if ( !err && !mPhyLinks ) {
|
|
199 |
TRAP( err,
|
|
200 |
mPhyLinks = CBluetoothPhysicalLinks::NewL( *this, mSocketServ ) );
|
57
|
201 |
if (err) {
|
|
202 |
disconnectPhysicalLinkCompleted(err); // handle error
|
42
|
203 |
}
|
31
|
204 |
}
|
57
|
205 |
// ToDo: consider using DisconnectAll()
|
|
206 |
BtTraceBtAddr1( TRACE_DEBUG, DUMMY_DEVLIST, "phy->Disconnect() with param device addr=", mBtEngAddr );
|
|
207 |
err = mPhyLinks->Disconnect( mBtEngAddr ); // async call, see callback HandleDisconnectCompleteL()
|
|
208 |
BOstraceExt1( TRACE_DEBUG, DUMMY_DEVLIST, "Phy Disconnect() ret = %d", err);
|
|
209 |
if (err) {
|
|
210 |
disconnectPhysicalLinkCompleted(err); // handle error
|
|
211 |
}
|
|
212 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
31
|
213 |
}
|
|
214 |
|
57
|
215 |
void BtDelegateDisconnect::disconnectServiceLevelCompleted(int err)
|
|
216 |
{
|
|
217 |
BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, err );
|
42
|
218 |
if (mDisconOpt == ServiceLevel){
|
|
219 |
mActiveHandling = false;
|
57
|
220 |
emit delegateCompleted(err, this);
|
42
|
221 |
}
|
|
222 |
else if (mDisconOpt == AllOngoingConnections){
|
|
223 |
if (err){
|
|
224 |
mActiveHandling = false;
|
57
|
225 |
emit delegateCompleted(err, this);
|
42
|
226 |
}
|
|
227 |
else{
|
|
228 |
mAddrArrayIndex++;
|
57
|
229 |
if ( mAddrArrayIndex < mDevAddrArray.Count()) {
|
|
230 |
disconnectAllConnections_service(); // recursive call
|
42
|
231 |
}
|
57
|
232 |
else {
|
42
|
233 |
mDevAddrArray.Reset();
|
57
|
234 |
mAddrArrayIndex = 0;
|
42
|
235 |
err = mBtengConnMan->GetConnectedAddresses(mDevAddrArray);
|
|
236 |
if(err) {
|
57
|
237 |
mActiveHandling = false;
|
|
238 |
emit delegateCompleted(err, this);
|
|
239 |
BOstraceFunctionExitExt( DUMMY_DEVLIST, this, err );
|
42
|
240 |
return;
|
|
241 |
}
|
|
242 |
disconnectAllConnections_physical();
|
|
243 |
}
|
|
244 |
}
|
|
245 |
}
|
57
|
246 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
42
|
247 |
}
|
|
248 |
|
57
|
249 |
void BtDelegateDisconnect::disconnectPhysicalLinkCompleted(int err)
|
|
250 |
{
|
|
251 |
BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, err );
|
42
|
252 |
if (mDisconOpt == PhysicalLink){
|
|
253 |
mActiveHandling = false;
|
57
|
254 |
emit delegateCompleted(err, this);
|
42
|
255 |
}
|
57
|
256 |
else if (mDisconOpt == AllOngoingConnections) {
|
|
257 |
if (err) {
|
42
|
258 |
mActiveHandling = false;
|
57
|
259 |
emit delegateCompleted(err, this);
|
42
|
260 |
}
|
|
261 |
else{
|
|
262 |
mAddrArrayIndex++;
|
57
|
263 |
if ( mAddrArrayIndex < mDevAddrArray.Count()) {
|
|
264 |
disconnectAllConnections_physical(); // recursive call
|
42
|
265 |
}
|
57
|
266 |
else { // DONE!
|
|
267 |
//TODO: check if there is still ongoing connection from BTEngConnMan. and close them again if there is any new
|
42
|
268 |
mActiveHandling = false;
|
57
|
269 |
emit delegateCompleted(KErrNone, this);
|
42
|
270 |
}
|
|
271 |
}
|
|
272 |
}
|
57
|
273 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
42
|
274 |
}
|
57
|
275 |
|
31
|
276 |
void BtDelegateDisconnect::ConnectComplete( TBTDevAddr& aAddr, TInt aErr,
|
|
277 |
RBTDevAddrArray* aConflicts )
|
|
278 |
{
|
57
|
279 |
BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aErr );
|
|
280 |
BtTraceBtAddr1( TRACE_DEBUG, DUMMY_DEVLIST, "device addr=", aAddr );
|
31
|
281 |
Q_UNUSED(aAddr);
|
|
282 |
Q_UNUSED(aConflicts);
|
|
283 |
Q_UNUSED(aErr);
|
57
|
284 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
31
|
285 |
}
|
|
286 |
|
|
287 |
void BtDelegateDisconnect::DisconnectComplete( TBTDevAddr& aAddr, TInt aErr )
|
|
288 |
{
|
57
|
289 |
BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aErr );
|
|
290 |
BtTraceBtAddr1( TRACE_DEBUG, DUMMY_DEVLIST, "device addr=", aAddr );
|
|
291 |
if ( mBtEngAddr != aAddr || !mActiveHandling ) {
|
|
292 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
42
|
293 |
return;
|
|
294 |
}
|
57
|
295 |
disconnectServiceLevelCompleted(aErr);
|
|
296 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
31
|
297 |
}
|
|
298 |
|
|
299 |
|
|
300 |
void BtDelegateDisconnect::cancel()
|
|
301 |
{
|
57
|
302 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
303 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
31
|
304 |
}
|
|
305 |
|
57
|
306 |
void BtDelegateDisconnect::HandleCreateConnectionCompleteL( TInt err )
|
|
307 |
{
|
|
308 |
BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, err );
|
42
|
309 |
Q_UNUSED( err );
|
57
|
310 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
42
|
311 |
}
|
|
312 |
|
57
|
313 |
// callback for CBluetoothPhysicalLinks::Disconnect()
|
|
314 |
void BtDelegateDisconnect::HandleDisconnectCompleteL( TInt err )
|
|
315 |
{
|
|
316 |
BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, err );
|
|
317 |
if ( !mActiveHandling ) {
|
|
318 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
42
|
319 |
return;
|
|
320 |
}
|
|
321 |
disconnectPhysicalLinkCompleted(err);
|
57
|
322 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
42
|
323 |
}
|
|
324 |
|
57
|
325 |
// callback for CBluetoothPhysicalLinks::DisconnectAll()
|
|
326 |
void BtDelegateDisconnect::HandleDisconnectAllCompleteL( TInt err )
|
31
|
327 |
{
|
57
|
328 |
BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, err );
|
|
329 |
Q_UNUSED( err );
|
|
330 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
31
|
331 |
}
|
|
332 |
|
|
333 |
|
57
|
334 |
|
|
335 |
|