2 * Copyright 2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
3 * All rights reserved. Distributed under the terms of the MIT License.
9 #include <bluetooth/bdaddrUtils.h>
10 #include <bluetooth/LocalDevice.h>
12 #include <bluetooth/DeviceClass.h>
13 #include <bluetooth/DiscoveryAgent.h>
14 #include <bluetooth/DiscoveryListener.h>
18 class SimpleDiscoveryListener
: public DiscoveryListener
{
22 SimpleDiscoveryListener()
30 DeviceDiscovered(RemoteDevice
* btDevice
, DeviceClass cod
)
34 printf("\t%s: Device %s discovered.\n",__FUNCTION__
,
35 bdaddrUtils::ToString(btDevice
->GetBluetoothAddress()));
37 cod
.GetServiceClass(classString
);
39 cod
.GetMajorDeviceClass(classString
);
41 cod
.GetMinorDeviceClass(classString
);
43 printf("\t\t%s: \n", classString
.String());
48 InquiryCompleted(int discType
)
50 printf("\t%s: Inquiry process has finished ...\n",__FUNCTION__
);
51 (void)send_data(mainThread
, discType
, NULL
, 0);
56 InquiryStarted(status_t status
)
58 printf("\t%s: Inquiry process has started ...\n",__FUNCTION__
);
66 DumpInfo(LocalDevice
* device
)
68 DiscoveryAgent
* dAgent
= device
->GetDiscoveryAgent();
71 printf("DiscoveryAgent could not be located\n");
75 printf("Discovering for [LocalDevice] %s\t%s\n\n",
76 (device
->GetFriendlyName()).String(),
77 bdaddrUtils::ToString(device
->GetBluetoothAddress()));
79 SimpleDiscoveryListener
* dListener
= new SimpleDiscoveryListener();
81 dAgent
->StartInquiry(BT_GIAC
, dListener
);
84 (void)receive_data(&sender
, NULL
, 0);
86 printf("Retrieving names ...\n");
88 for (int32 index
= 0 ; index
< dAgent
->RetrieveDevices(0).CountItems(); index
++ ) {
90 RemoteDevice
* rDevice
= dAgent
->RetrieveDevices(0).ItemAt(index
);
91 printf("\t%s \t@ %s ...\n", rDevice
->GetFriendlyName(true).String(),
92 bdaddrUtils::ToString(rDevice
->GetBluetoothAddress()));
100 LocalDeviceError(status_t status
)
102 fprintf(stderr
,"No Device/s found");
109 main(int argc
, char *argv
[])
111 mainThread
= find_thread(NULL
);
115 LocalDevice
* device
= LocalDevice::GetLocalDevice(atoi(argv
[0]));
117 return LocalDeviceError(ENODEV
);
121 } else if (argc
== 1) {
123 LocalDevice
* device
= NULL
;
125 printf("Performing discovery for %ld Bluetooth Local Devices ...\n",
126 LocalDevice::GetLocalDeviceCount());
128 for (uint32 index
= 0 ; index
< LocalDevice::GetLocalDeviceCount() ; index
++) {
130 device
= LocalDevice::GetLocalDevice();
131 if (device
== NULL
) {
132 LocalDeviceError(ENODEV
);
142 fprintf(stderr
,"Usage: bt_dev_info [device]\n");