- Block correcily until the discovery has finished to retrieve the remote names.

- Guidelines fixings



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25007 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Ruiz Dorantes 2008-04-17 19:19:19 +00:00
parent fae5a1d349
commit 3ef106839a

View File

@ -14,14 +14,17 @@
#include <bluetooth/DiscoveryAgent.h> #include <bluetooth/DiscoveryAgent.h>
#include <bluetooth/DiscoveryListener.h> #include <bluetooth/DiscoveryListener.h>
thread_id mainThread;
class simpleDiscoveryListener : public DiscoveryListener { class simpleDiscoveryListener : public DiscoveryListener {
public: public:
simpleDiscoveryListener(LocalDevice *ld) : DiscoveryListener() simpleDiscoveryListener(LocalDevice *device) : DiscoveryListener()
{ {
/* TODO: Should not be needed */ /* TODO: Should not be needed */
SetLocalDeviceOwner(ld); SetLocalDeviceOwner(device);
} }
@ -37,7 +40,8 @@ InquiryCompleted(int discType)
{ {
printf("\t%s: Inquiry process has finished ...\n",__FUNCTION__); printf("\t%s: Inquiry process has finished ...\n",__FUNCTION__);
// send_data(thread, discType, NULL, 0); (void)send_data(mainThread, discType, NULL, 0);
} }
@ -54,9 +58,9 @@ InquiryStarted(status_t status)
void void
DumpInfo(LocalDevice* device) DumpInfo(LocalDevice* device)
{ {
DiscoveryAgent* da = device->GetDiscoveryAgent(); DiscoveryAgent* dAgent = device->GetDiscoveryAgent();
if (da == NULL) { if (dAgent == NULL) {
printf("DiscoveryAgent could not be located\n"); printf("DiscoveryAgent could not be located\n");
return; return;
} }
@ -65,22 +69,21 @@ DumpInfo(LocalDevice* device)
(device->GetFriendlyName()).String(), (device->GetFriendlyName()).String(),
bdaddrUtils::ToString(device->GetBluetoothAddress())); bdaddrUtils::ToString(device->GetBluetoothAddress()));
simpleDiscoveryListener* sdl = new simpleDiscoveryListener(device); simpleDiscoveryListener* dListener = new simpleDiscoveryListener(device);
da->StartInquiry(BT_GIAC, sdl); dAgent->StartInquiry(BT_GIAC, dListener);
printf("Press any key to retrieve names ...\n"); (void)receive_data(NULL, NULL, 0);
getchar();
for (int32 index = 0 ; index < da->RetrieveDevices(0).CountItems(); index++ ) { printf("Retrieving names ...\n");
RemoteDevice* rd = da->RetrieveDevices(0).ItemAt(index); for (int32 index = 0 ; index < dAgent->RetrieveDevices(0).CountItems(); index++ ) {
printf("%s \t@ %s ...\n", rd->GetFriendlyName(false).String(), bdaddrUtils::ToString(rd->GetBluetoothAddress()));
RemoteDevice* rDevice = dAgent->RetrieveDevices(0).ItemAt(index);
printf("\t%s \t@ %s ...\n", rDevice->GetFriendlyName(false).String(), bdaddrUtils::ToString(rDevice->GetBluetoothAddress()));
} }
getchar();
} }
static status_t static status_t
@ -95,28 +98,31 @@ LocalDeviceError(status_t status)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
if(argc == 2) {
mainThread = find_thread(NULL);
if (argc == 2) {
// device specified // device specified
LocalDevice* ld = LocalDevice::GetLocalDevice(atoi(argv[0])); LocalDevice* device = LocalDevice::GetLocalDevice(atoi(argv[0]));
if (ld == NULL) if (device == NULL)
return LocalDeviceError(ENODEV); return LocalDeviceError(ENODEV);
DumpInfo(ld); DumpInfo(device);
} else if (argc == 1) { } else if (argc == 1) {
// show all devices // show all devices
LocalDevice* ld = NULL; LocalDevice* device = NULL;
printf("Performing discovery for %ld Bluetooth Local Devices ...\n", LocalDevice::GetLocalDeviceCount()); printf("Performing discovery for %ld Bluetooth Local Devices ...\n", LocalDevice::GetLocalDeviceCount());
for (uint32 index = 0 ; index < LocalDevice::GetLocalDeviceCount() ; index++) { for (uint32 index = 0 ; index < LocalDevice::GetLocalDeviceCount() ; index++) {
ld = LocalDevice::GetLocalDevice(); device = LocalDevice::GetLocalDevice();
if (ld == NULL) { if (device == NULL) {
LocalDeviceError(ENODEV); LocalDeviceError(ENODEV);
continue; continue;
} }
DumpInfo(ld); DumpInfo(device);
} }