From b0410a2221177cbe63ddc1b5873d5eef7098f9d6 Mon Sep 17 00:00:00 2001 From: Oliver Ruiz Dorantes Date: Wed, 16 Apr 2008 22:15:20 +0000 Subject: [PATCH] - Implement a filter for devices that are repling multiple times. - Fix the creation of the RemoteDevicesList git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24990 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/bluetooth/DiscoveryListener.cpp | 53 +++++++++++++++++------- 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/src/kits/bluetooth/DiscoveryListener.cpp b/src/kits/bluetooth/DiscoveryListener.cpp index 3b50eb6143..722c4a96e0 100644 --- a/src/kits/bluetooth/DiscoveryListener.cpp +++ b/src/kits/bluetooth/DiscoveryListener.cpp @@ -5,9 +5,11 @@ * */ +#include #include #include #include +#include #include @@ -19,28 +21,28 @@ namespace Bluetooth { /* hooks */ -void +void DiscoveryListener::DeviceDiscovered(RemoteDevice* btDevice, DeviceClass cod) -{ +{ } -void +void DiscoveryListener::InquiryStarted(status_t status) { } -void +void DiscoveryListener::InquiryCompleted(int discType) { } -/* private */ +/* private */ /* A LocalDevice is always referenced in any request to the Bluetooth server therefore is going to be needed in any */ @@ -68,25 +70,46 @@ DiscoveryListener::MessageReceived(BMessage* message) case BT_MSG_INQUIRY_DEVICE: { const struct inquiry_info* inquiryInfo; - ssize_t size; - + ssize_t size; + RemoteDevice* rd = NULL; + bool duplicatedFound = false; + if (message->FindData("info", B_ANY_TYPE, 0, (const void**)&inquiryInfo, &size) == B_OK ) - { - RemoteDevice* rd = new RemoteDevice(inquiryInfo->bdaddr); - // DeviceClass(inquiryInfo->dev_class[0] | inquiryInfo->dev_class[1]<<8 | inquiryInfo->dev_class[2]<<16 ) - // fRemoteDevicesList.AddItem(rd); - rd->SetLocalDeviceOwner(fLocalDevice); - DeviceDiscovered( rd, DeviceClass(inquiryInfo->dev_class[0] | inquiryInfo->dev_class[1]<<8 | inquiryInfo->dev_class[2]<<16 )); + { + // Skip duplicated replies + for (int32 index = 0 ; index < fRemoteDevicesList.CountItems(); index++) { + + bdaddr_t b1 = fRemoteDevicesList.ItemAt(index)->GetBluetoothAddress(); + + if (bdaddrUtils::Compare( (bdaddr_t*) &inquiryInfo->bdaddr, &b1 )) { + + duplicatedFound = true; + break; + } + + } + + if (!duplicatedFound) { + + // DeviceClass(inquiryInfo->dev_class[0] | inquiryInfo->dev_class[1]<<8 | inquiryInfo->dev_class[2]<<16 ) + rd = new RemoteDevice(inquiryInfo->bdaddr); + fRemoteDevicesList.AddItem(rd); + rd->SetLocalDeviceOwner(fLocalDevice); + DeviceDiscovered( rd, DeviceClass(inquiryInfo->dev_class[0] | + inquiryInfo->dev_class[1]<<8 | + inquiryInfo->dev_class[2]<<16 )); + } } } break; case BT_MSG_INQUIRY_STARTED: if (message->FindInt8("status", &status) == B_OK){ + fRemoteDevicesList.MakeEmpty(); InquiryStarted(status); } - + break; case BT_MSG_INQUIRY_COMPLETED: @@ -116,7 +139,7 @@ DiscoveryListener::MessageReceived(BMessage* message) } -DiscoveryListener::DiscoveryListener() : BLooper() +DiscoveryListener::DiscoveryListener() : BLooper() , fRemoteDevicesList(BT_MAX_RESPONSES) { // TODO: Make a better handling of the running not running state Run();