OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "device/bluetooth/bluetooth_task_manager_win.h" | 5 #include "device/bluetooth/bluetooth_task_manager_win.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <winsock2.h> | 8 #include <winsock2.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
436 device_search_params.fIssueInquiry = (search_cached_devices_only ? 0 : 1); | 436 device_search_params.fIssueInquiry = (search_cached_devices_only ? 0 : 1); |
437 device_search_params.cTimeoutMultiplier = timeout_multiplier; | 437 device_search_params.cTimeoutMultiplier = timeout_multiplier; |
438 | 438 |
439 BLUETOOTH_DEVICE_INFO device_info; | 439 BLUETOOTH_DEVICE_INFO device_info; |
440 ZeroMemory(&device_info, sizeof(device_info)); | 440 ZeroMemory(&device_info, sizeof(device_info)); |
441 device_info.dwSize = sizeof(BLUETOOTH_DEVICE_INFO); | 441 device_info.dwSize = sizeof(BLUETOOTH_DEVICE_INFO); |
442 HBLUETOOTH_DEVICE_FIND handle = | 442 HBLUETOOTH_DEVICE_FIND handle = |
443 win::BluetoothClassicWrapper::GetInstance()->FindFirstDevice( | 443 win::BluetoothClassicWrapper::GetInstance()->FindFirstDevice( |
444 &device_search_params, &device_info); | 444 &device_search_params, &device_info); |
445 if (!handle) { | 445 if (!handle) { |
446 int last_error = GetLastError(); | 446 int last_error = win::BluetoothClassicWrapper::GetInstance()->LastError(); |
scheib
2016/02/07 02:24:08
BTW, looking at how often ::GetInstance is being c
gogerald1
2016/02/08 19:23:51
Acknowledged.
| |
447 if (last_error == ERROR_NO_MORE_ITEMS) { | 447 if (last_error == ERROR_NO_MORE_ITEMS) { |
448 return true; // No devices is not an error. | 448 return true; // No devices is not an error. |
449 } | 449 } |
450 LogPollingError("Error calling BluetoothFindFirstDevice", last_error); | 450 LogPollingError("Error calling BluetoothFindFirstDevice", last_error); |
451 return false; | 451 return false; |
452 } | 452 } |
453 | 453 |
454 while (true) { | 454 while (true) { |
455 DeviceState* device_state = new DeviceState(); | 455 DeviceState* device_state = new DeviceState(); |
456 GetDeviceState(device_info, device_state); | 456 GetDeviceState(device_info, device_state); |
457 device_list->push_back(device_state); | 457 device_list->push_back(device_state); |
458 | 458 |
459 // Reset device info before next call (as a safety precaution). | 459 // Reset device info before next call (as a safety precaution). |
460 ZeroMemory(&device_info, sizeof(device_info)); | 460 ZeroMemory(&device_info, sizeof(device_info)); |
461 device_info.dwSize = sizeof(BLUETOOTH_DEVICE_INFO); | 461 device_info.dwSize = sizeof(BLUETOOTH_DEVICE_INFO); |
462 if (!win::BluetoothClassicWrapper::GetInstance()->FindNextDevice( | 462 if (!win::BluetoothClassicWrapper::GetInstance()->FindNextDevice( |
463 handle, &device_info)) { | 463 handle, &device_info)) { |
464 int last_error = GetLastError(); | 464 int last_error = win::BluetoothClassicWrapper::GetInstance()->LastError(); |
465 if (last_error == ERROR_NO_MORE_ITEMS) { | 465 if (last_error == ERROR_NO_MORE_ITEMS) { |
466 break; // No more items is expected error when done enumerating. | 466 break; // No more items is expected error when done enumerating. |
467 } | 467 } |
468 LogPollingError("Error calling BluetoothFindNextDevice", last_error); | 468 LogPollingError("Error calling BluetoothFindNextDevice", last_error); |
469 win::BluetoothClassicWrapper::GetInstance()->FindDeviceClose(handle); | 469 win::BluetoothClassicWrapper::GetInstance()->FindDeviceClose(handle); |
470 return false; | 470 return false; |
471 } | 471 } |
472 } | 472 } |
473 | 473 |
474 if (!win::BluetoothClassicWrapper::GetInstance()->FindDeviceClose(handle)) { | 474 if (!win::BluetoothClassicWrapper::GetInstance()->FindDeviceClose(handle)) { |
475 LogPollingError("Error calling BluetoothFindDeviceClose", GetLastError()); | 475 LogPollingError("Error calling BluetoothFindDeviceClose", |
476 win::BluetoothClassicWrapper::GetInstance()->LastError()); | |
476 return false; | 477 return false; |
477 } | 478 } |
478 return true; | 479 return true; |
479 } | 480 } |
480 | 481 |
481 bool BluetoothTaskManagerWin::SearchLowEnergyDevices( | 482 bool BluetoothTaskManagerWin::SearchLowEnergyDevices( |
482 ScopedVector<DeviceState>* device_list) { | 483 ScopedVector<DeviceState>* device_list) { |
483 if (!win::IsBluetoothLowEnergySupported()) | 484 if (!win::IsBluetoothLowEnergySupported()) |
484 return true; // Bluetooth LE not supported is not an error. | 485 return true; // Bluetooth LE not supported is not an error. |
485 | 486 |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
717 break; | 718 break; |
718 } | 719 } |
719 } | 720 } |
720 } | 721 } |
721 } | 722 } |
722 | 723 |
723 return true; | 724 return true; |
724 } | 725 } |
725 | 726 |
726 } // namespace device | 727 } // namespace device |
OLD | NEW |