bluetooth_classic_win_fake.cc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "device/bluetooth/bluetooth_classic_win_fake.h"
  5. #include "base/check_op.h"
  6. #include "base/notreached.h"
  7. #include "base/strings/string_util.h"
  8. namespace device {
  9. namespace win {
  10. BluetoothClassicWrapperFake::BluetoothClassicWrapperFake()
  11. : last_error_(ERROR_SUCCESS) {}
  12. BluetoothClassicWrapperFake::~BluetoothClassicWrapperFake() {}
  13. HBLUETOOTH_RADIO_FIND BluetoothClassicWrapperFake::FindFirstRadio(
  14. const BLUETOOTH_FIND_RADIO_PARAMS* params) {
  15. if (simulated_radios_) {
  16. last_error_ = ERROR_SUCCESS;
  17. return (PVOID)simulated_radios_.get();
  18. }
  19. last_error_ = ERROR_NO_MORE_ITEMS;
  20. return NULL;
  21. }
  22. DWORD BluetoothClassicWrapperFake::GetRadioInfo(
  23. PBLUETOOTH_RADIO_INFO out_radio_info) {
  24. if (simulated_radios_) {
  25. *out_radio_info = simulated_radios_->radio_info;
  26. last_error_ = ERROR_SUCCESS;
  27. return last_error_;
  28. }
  29. last_error_ = ERROR_INVALID_HANDLE;
  30. return last_error_;
  31. }
  32. BOOL BluetoothClassicWrapperFake::FindRadioClose(HBLUETOOTH_RADIO_FIND handle) {
  33. DCHECK_EQ(handle, (PVOID)simulated_radios_.get());
  34. return TRUE;
  35. }
  36. BOOL BluetoothClassicWrapperFake::IsConnectable() {
  37. if (simulated_radios_) {
  38. last_error_ = ERROR_SUCCESS;
  39. return simulated_radios_->is_connectable;
  40. }
  41. last_error_ = ERROR_INVALID_HANDLE;
  42. return FALSE;
  43. }
  44. HBLUETOOTH_DEVICE_FIND BluetoothClassicWrapperFake::FindFirstDevice(
  45. const BLUETOOTH_DEVICE_SEARCH_PARAMS* params,
  46. BLUETOOTH_DEVICE_INFO* out_device_info) {
  47. last_error_ = ERROR_NO_MORE_ITEMS;
  48. return NULL;
  49. }
  50. BOOL BluetoothClassicWrapperFake::FindNextDevice(
  51. HBLUETOOTH_DEVICE_FIND handle,
  52. BLUETOOTH_DEVICE_INFO* out_device_info) {
  53. NOTIMPLEMENTED();
  54. return TRUE;
  55. }
  56. BOOL BluetoothClassicWrapperFake::FindDeviceClose(
  57. HBLUETOOTH_DEVICE_FIND handle) {
  58. return TRUE;
  59. }
  60. BOOL BluetoothClassicWrapperFake::EnableDiscovery(BOOL is_enable) {
  61. return TRUE;
  62. }
  63. BOOL BluetoothClassicWrapperFake::EnableIncomingConnections(BOOL is_enable) {
  64. return TRUE;
  65. }
  66. DWORD BluetoothClassicWrapperFake::LastError() {
  67. return last_error_;
  68. }
  69. bool BluetoothClassicWrapperFake::HasHandle() {
  70. return bool(simulated_radios_);
  71. }
  72. BluetoothRadio* BluetoothClassicWrapperFake::SimulateARadio(
  73. std::u16string name,
  74. BLUETOOTH_ADDRESS address) {
  75. BluetoothRadio* radio = new BluetoothRadio();
  76. radio->is_connectable = true; // set it connectable by default.
  77. size_t length =
  78. ((name.size() > BLUETOOTH_MAX_NAME_SIZE) ? BLUETOOTH_MAX_NAME_SIZE
  79. : name.size());
  80. wcsncpy(radio->radio_info.szName, base::as_wcstr(name), length);
  81. radio->radio_info.address = address;
  82. simulated_radios_.reset(radio);
  83. return radio;
  84. }
  85. } // namespace device
  86. } // namespace win