172 // --------------------------------------------------------------------------- |
171 // --------------------------------------------------------------------------- |
173 // |
172 // |
174 void CBTNotifDeviceSelector::MBRDataReceived( CHbSymbianVariantMap& aData ) |
173 void CBTNotifDeviceSelector::MBRDataReceived( CHbSymbianVariantMap& aData ) |
175 { |
174 { |
176 TInt err = KErrCancel; |
175 TInt err = KErrCancel; |
177 if(aData.Keys().MdcaPoint(0).Compare(_L("selectedindex"))==KErrNone) |
176 if(aData.Keys().MdcaPoint(aData.Keys().MdcaCount()-1).Compare(_L("selectedindex"))==KErrNone) |
178 { |
177 { |
179 TInt val = *(static_cast<TInt*>(aData.Get(_L("selectedindex"))->Data())); |
178 TInt val = *(static_cast<TInt*>(aData.Get(_L("selectedindex"))->Data())); |
180 BOstrace1( TRACE_DEBUG, TNAME_DEVLIST_2, "MBRDataReceived, val %d", val ); |
179 BOstrace1( TRACE_DEBUG, TNAME_DEVLIST_2, "MBRDataReceived, val %d", val ); |
181 |
180 |
182 if ( !iMessage.IsNull() ) |
181 if ( !iMessage.IsNull() ) |
183 { |
182 { |
184 // TInt sel = val;// - TBluetoothDialogParams::EDialogExt; |
183 // TInt sel = val;// - TBluetoothDialogParams::EDialogExt; |
185 TBTDeviceResponseParamsPckg devParams; |
184 TBTDeviceResponseParamsPckg devParams; |
186 if ( val > -1 && val < iDevices.Count() ) |
185 if ( val > -1 && val < iDevices.Count() ) |
187 { |
186 { |
188 devParams().SetDeviceAddress( iDevices[val]->Addr() ); |
187 TRAP(err,SendSelectedDeviceL(aData)); |
|
188 /* devParams().SetDeviceAddress( iDevices[val]->Addr() ); |
189 devParams().SetDeviceClass(iDevices[val]->Device().DeviceClass()); |
189 devParams().SetDeviceClass(iDevices[val]->Device().DeviceClass()); |
190 devParams().SetDeviceName(iDevices[val]->Alias()); |
190 devParams().SetDeviceName(iDevices[val]->Alias()); |
191 err = iMessage.Write( EBTNotifSrvReplySlot, devParams ); |
191 err = iMessage.Write( EBTNotifSrvReplySlot, devParams );*/ |
192 iNotification->RemoveObserver(); |
192 iNotification->RemoveObserver(); |
193 iNotification->Close(); // Also dequeues the notification from the queue. |
193 iNotification->Close(); // Also dequeues the notification from the queue. |
194 iNotification = NULL; |
194 iNotification = NULL; |
195 } |
195 } |
196 iMessage.Complete( err ); |
196 iMessage.Complete( err ); |
240 // |
240 // |
241 void CBTNotifDeviceSelector::HandleNextDiscoveryResultL( |
241 void CBTNotifDeviceSelector::HandleNextDiscoveryResultL( |
242 const TInquirySockAddr& aAddr, const TDesC& aName ) |
242 const TInquirySockAddr& aAddr, const TDesC& aName ) |
243 { |
243 { |
244 // Todo: look for this device in repository before creating it. |
244 // Todo: look for this device in repository before creating it. |
245 CBtDevExtension* devext = CBtDevExtension::NewLC( aAddr, aName ); |
245 TBuf<KBTDevAddrSize * 2> addr; |
|
246 |
|
247 |
|
248 |
|
249 CBtDevExtension* devext = GetDeviceFromRepositoryL(aAddr.BTAddr()); |
|
250 |
|
251 if(!devext) |
|
252 { |
|
253 devext = CBtDevExtension::NewLC( aAddr, aName ); |
|
254 } |
|
255 else |
|
256 { |
|
257 CleanupStack::PushL(devext); |
|
258 } |
246 iDevices.AppendL( devext ); |
259 iDevices.AppendL( devext ); |
247 CleanupStack::Pop( devext ); |
260 CleanupStack::Pop( devext ); |
248 |
261 |
249 if(iNotification) |
262 if(iNotification) |
250 {// conditional check required as CAdvanceDevDiscoverer sends discovered devices at times |
263 {// conditional check required as CAdvanceDevDiscoverer sends discovered devices at times |
251 // even after canceldiscovery is issued and notification is set to NULL |
264 // even after canceldiscovery is issued and notification is set to NULL |
252 // this causes EExcDataAbort |
265 // this causes EExcDataAbort |
253 CHbSymbianVariantMap* map = iNotification->Data(); |
266 CHbSymbianVariantMap* map = iNotification->Data(); |
254 TBuf<KMaxKeyDesCLength> keyStr; |
267 /* TBuf<KMaxKeyDesCLength> keyStr; |
255 CHbSymbianVariant* devEntry; |
268 CHbSymbianVariant* devEntry; |
256 |
269 |
257 keyStr.Num( TBluetoothDialogParams::EDialogExt + iDevices.Count() - 1 ); |
270 keyStr.Num( TBluetoothDialogParams::EDialogExt + iDevices.Count() - 1 ); |
258 devEntry = CHbSymbianVariant::NewL( (TAny*) &(devext->Alias()), |
271 devEntry = CHbSymbianVariant::NewL( (TAny*) &(devext->Alias()), |
259 CHbSymbianVariant::EDes ); |
272 CHbSymbianVariant::EDes ); |
260 map->Add( keyStr, devEntry ); |
273 map->Add( keyStr, devEntry );*/ |
|
274 |
|
275 User::LeaveIfError(iNotification->SetData(TBluetoothDeviceDialog::EDeviceName, |
|
276 devext->Alias())); |
|
277 |
|
278 devext->Addr().GetReadable(addr); |
|
279 User::LeaveIfError(iNotification->SetData(TBluetoothDialogParams::EAddress,addr)); |
|
280 |
|
281 TInt classOfDevice; |
|
282 classOfDevice = devext->Device().DeviceClass().DeviceClass(); |
|
283 User::LeaveIfError(iNotification->SetData(TBluetoothDeviceDialog::EDeviceClass,classOfDevice)); |
|
284 |
|
285 TBool status; |
|
286 status = isBonded( devext->Device()); |
|
287 |
|
288 // setMajorProperty(majorProperty, _L("Bonded"), isBonded( devArray[i]->Device() )); |
|
289 AddDataL(map,_L("Bonded"),&status,CHbSymbianVariant::EBool); |
|
290 status = devext->Device().GlobalSecurity().Banned(); |
|
291 AddDataL(map,_L("Blocked"),&status, |
|
292 CHbSymbianVariant::EBool); |
|
293 status = devext->Device().GlobalSecurity().NoAuthorise(); |
|
294 AddDataL(map,_L("Trusted"),&status, |
|
295 CHbSymbianVariant::EBool); |
|
296 status = devext->ServiceConnectionStatus() == EBTEngConnected; |
|
297 AddDataL(map,_L("Connected"),&status, |
|
298 CHbSymbianVariant::EBool); |
|
299 |
261 iNotification->Update(); |
300 iNotification->Update(); |
262 } |
301 } |
263 } |
302 } |
264 |
303 |
265 // --------------------------------------------------------------------------- |
304 // --------------------------------------------------------------------------- |
369 } |
408 } |
370 |
409 |
371 void CBTNotifDeviceSelector::LoadUsedDevicesL() |
410 void CBTNotifDeviceSelector::LoadUsedDevicesL() |
372 { |
411 { |
373 const RDevExtensionArray& devArray= iServer.DevRepository().AllDevices(); |
412 const RDevExtensionArray& devArray= iServer.DevRepository().AllDevices(); |
|
413 TBuf<KBTDevAddrSize * 2> addr; |
374 for(TInt i=0; i< devArray.Count(); i++ ) |
414 for(TInt i=0; i< devArray.Count(); i++ ) |
375 { |
415 { |
376 const TTime& usedTime = devArray[i]->Device().Used(); |
416 const TTime& usedTime = devArray[i]->Device().Used(); |
377 TTime monthBack; |
417 TTime monthBack; |
378 monthBack.HomeTime(); |
418 monthBack.HomeTime(); |
379 monthBack -= TTimeIntervalDays(30); |
419 monthBack -= TTimeIntervalDays(30); |
380 if(usedTime >= monthBack) |
420 if(usedTime >= monthBack) |
381 { |
421 { |
382 iDevices.AppendL( devArray[i]->CopyL() ); |
422 iDevices.AppendL( devArray[i]->CopyL() ); |
383 CHbSymbianVariantMap* map = iNotification->Data(); |
423 CHbSymbianVariantMap* map = iNotification->Data(); |
384 TBuf<KMaxKeyDesCLength> keyStr; |
424 // TBuf<KMaxKeyDesCLength> keyStr; |
385 CHbSymbianVariant* devEntry; |
425 // CHbSymbianVariant* devEntry; |
386 |
426 |
387 keyStr.Num( TBluetoothDialogParams::EDialogExt + iDevices.Count() - 1 ); |
427 // keyStr.Num( TBluetoothDialogParams::EDialogExt + iDevices.Count() - 1 ); |
388 devEntry = CHbSymbianVariant::NewL( (TAny*) &(devArray[i]->Alias()), |
428 // devEntry = CHbSymbianVariant::NewL( (TAny*) &(devArray[i]->Alias()), |
389 CHbSymbianVariant::EDes ); |
429 // CHbSymbianVariant::EDes ); |
390 map->Add( keyStr, devEntry ); |
430 // map->Add( keyStr, devEntry, ); |
|
431 User::LeaveIfError(iNotification->SetData(TBluetoothDeviceDialog::EDeviceName, |
|
432 devArray[i]->Alias())); |
|
433 // AddDataL(map,keyStr,&(devArray[i]->Alias()),CHbSymbianVariant::EDes); |
|
434 devArray[i]->Addr().GetReadable(addr); |
|
435 User::LeaveIfError(iNotification->SetData(TBluetoothDialogParams::EAddress,addr)); |
|
436 addr.Zero(); |
|
437 TInt classOfDevice; |
|
438 classOfDevice = devArray[i]->Device().DeviceClass().DeviceClass(); |
|
439 User::LeaveIfError(iNotification->SetData(TBluetoothDeviceDialog::EDeviceClass,classOfDevice)); |
|
440 |
|
441 TBool status; |
|
442 status = isBonded( devArray[i]->Device()); |
|
443 |
|
444 // setMajorProperty(majorProperty, _L("Bonded"), isBonded( devArray[i]->Device() )); |
|
445 AddDataL(map,_L("Bonded"),&status,CHbSymbianVariant::EBool); |
|
446 status = devArray[i]->Device().GlobalSecurity().Banned(); |
|
447 AddDataL(map,_L("Blocked"),&status, |
|
448 CHbSymbianVariant::EBool); |
|
449 status = devArray[i]->Device().GlobalSecurity().NoAuthorise(); |
|
450 AddDataL(map,_L("Trusted"),&status, |
|
451 CHbSymbianVariant::EBool); |
|
452 status = devArray[i]->ServiceConnectionStatus() == EBTEngConnected; |
|
453 AddDataL(map,_L("Connected"),&status, |
|
454 CHbSymbianVariant::EBool); |
|
455 // set blocked status: |
|
456 /* setMajorProperty(majorProperty, BtuiDevProperty::Blocked, |
|
457 devArray[i]->Device().GlobalSecurity().Banned() ); |
|
458 // set trusted status: |
|
459 setMajorProperty(majorProperty, BtuiDevProperty::Trusted, |
|
460 devArray[i]->Device().GlobalSecurity().NoAuthorise() ); |
|
461 // set connected status: |
|
462 // EBTEngConnecting is an intermediate state between connected and not-connected, |
|
463 // we do not treat it as connected: |
|
464 setMajorProperty(majorProperty, BtuiDevProperty::Connected, devArray[i]->ServiceConnectionStatus() == EBTEngConnected); |
|
465 |
|
466 */ |
|
467 |
|
468 // AddDataL(map,keyStr,&(devArray[i]->Alias()),CHbSymbianVariant::EDes); |
391 iNotification->Update(); |
469 iNotification->Update(); |
392 } |
470 } |
393 } |
471 } |
394 } |
472 } |
|
473 |
|
474 |
|
475 |
|
476 /*! |
|
477 Tells if the given device is bonded. |
|
478 */ |
|
479 TBool CBTNotifDeviceSelector::isBonded( const CBTDevice &dev ) |
|
480 { |
|
481 // todo: this has not addresses Just Works pairing mode yet. |
|
482 return dev.IsValidPaired() && dev.IsPaired() && |
|
483 dev.LinkKeyType() != ELinkKeyUnauthenticatedUpgradable; |
|
484 } |
|
485 |
|
486 void CBTNotifDeviceSelector::AddDataL(CHbSymbianVariantMap* aMap, const TDesC& aKey, |
|
487 const TAny* aData, CHbSymbianVariant::TType aDataType) |
|
488 { |
|
489 CHbSymbianVariant* value = CHbSymbianVariant::NewL(aData, aDataType); |
|
490 CleanupStack::PushL( value ); |
|
491 User::LeaveIfError( aMap->Add( aKey, value ) ); // aMap takes the ownership of value |
|
492 CleanupStack::Pop( value ); |
|
493 } |
|
494 |
|
495 // --------------------------------------------------------------------------- |
|
496 // Tells if these two instances are for the same remote device |
|
497 // --------------------------------------------------------------------------- |
|
498 // |
|
499 TBool MatchDeviceAddress(const TBTDevAddr* aAddr, const CBtDevExtension& aDev) |
|
500 { |
|
501 return *aAddr == aDev.Device().BDAddr(); |
|
502 } |
|
503 |
|
504 |
|
505 CBtDevExtension* CBTNotifDeviceSelector::GetDeviceFromRepositoryL( const TBTDevAddr& aAddr ) |
|
506 { |
|
507 const RDevExtensionArray& devArray= iServer.DevRepository().AllDevices(); |
|
508 |
|
509 TInt pos = devArray.Find( aAddr, MatchDeviceAddress); |
|
510 if(pos > -1) |
|
511 { |
|
512 return devArray[pos]->CopyL(); |
|
513 } |
|
514 return NULL; |
|
515 /* addrSymbianToReadbleString( addrStr, addr ); |
|
516 for (int i = 0; i < mData.count(); ++i ) { |
|
517 if ( mData.at( i ).value( BtDeviceModel::ReadableBdaddrRole ) |
|
518 == addrStr ) { |
|
519 return i; |
|
520 } |
|
521 } |
|
522 return -1;*/ |
|
523 } |
|
524 |
|
525 |
|
526 void CBTNotifDeviceSelector::SendSelectedDeviceL( CHbSymbianVariantMap& aData ) |
|
527 { |
|
528 TInt err; |
|
529 TBTDeviceResponseParamsPckg devParams; |
|
530 TBTDevAddr address; |
|
531 User::LeaveIfError(address.SetReadable( |
|
532 *(static_cast<TDesC*>(aData.Get(_L("deviceaddress"))->Data())))); |
|
533 devParams().SetDeviceAddress( address ); |
|
534 devParams().SetDeviceClass(*(static_cast<TUint32*>(aData.Get(_L("deviceclass"))->Data()))); |
|
535 devParams().SetDeviceName(*(static_cast<TDesC*>(aData.Get(_L("devicename"))->Data()))); |
|
536 User::LeaveIfError(iMessage.Write( EBTNotifSrvReplySlot, devParams )); |
|
537 } |
|
538 |