xref: /haiku/src/bin/bt_dev_info.cpp (revision cf095a334804a8a5f52cd77f589026ce269821f9)
1 /*
2  * Copyright 2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
3  *
4  * All rights reserved. Distributed under the terms of the MIT License.
5  *
6  */
7 
8 #include <stdio.h>
9 #include <stdlib.h>
10 
11 #include <bluetooth/LocalDevice.h>
12 #include <bluetooth/bdaddrUtils.h>
13 
14 
15 static void
16 DumpInfo(LocalDevice &device)
17 {
18         printf("[LocalDevice] %s\t%s\n", (device.GetFriendlyName()).String(),
19                                     bdaddrUtils::ToString(device.GetBluetoothAddress()));
20 
21 }
22 
23 static status_t
24 LocalDeviceError(status_t status)
25 {
26     fprintf(stderr,"No Device/s found");
27 
28     return status;
29 }
30 
31 
32 int
33 main(int argc, char *argv[])
34 {
35         if(argc == 2) {
36             // device specified
37             LocalDevice* ld = LocalDevice::GetLocalDevice(atoi(argv[0]));
38             if (ld == NULL)
39                return LocalDeviceError(ENODEV);
40 
41             DumpInfo(*ld);
42 
43         } else if (argc == 1) {
44             // show all devices
45             LocalDevice* ld = NULL;
46 
47             printf("Listing %ld Bluetooth Local Devices ...\n", LocalDevice::GetLocalDeviceCount());
48 
49             for (uint32 index = 0 ; index < LocalDevice::GetLocalDeviceCount() ; index++) {
50 
51                ld = LocalDevice::GetLocalDevice();
52                if (ld == NULL)
53                     return LocalDeviceError(ENODEV);
54                DumpInfo(*ld);
55 
56             }
57 
58             return B_OK;
59 
60         } else {
61                 fprintf(stderr,"Usage: bt_dev_info [device]\n");
62                 return B_ERROR;
63         }
64 }
65