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
3 // found in the LICENSE file.
5 #include "device/bluetooth/bluetooth_device_win.h"
9 #include "base/basictypes.h"
10 #include "base/logging.h"
11 #include "base/memory/scoped_vector.h"
12 #include "base/sequenced_task_runner.h"
13 #include "base/strings/stringprintf.h"
14 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h"
15 #include "device/bluetooth/bluetooth_profile_win.h"
16 #include "device/bluetooth/bluetooth_service_record_win.h"
17 #include "device/bluetooth/bluetooth_socket_thread.h"
18 #include "device/bluetooth/bluetooth_socket_win.h"
19 #include "device/bluetooth/bluetooth_task_manager_win.h"
20 #include "device/bluetooth/bluetooth_uuid.h"
24 const int kSdpBytesBufferSize = 1024;
30 BluetoothDeviceWin::BluetoothDeviceWin(
31 const BluetoothTaskManagerWin::DeviceState& state,
32 scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
33 scoped_refptr<BluetoothSocketThread> socket_thread,
35 const net::NetLog::Source& net_log_source)
37 ui_task_runner_(ui_task_runner),
38 socket_thread_(socket_thread),
40 net_log_source_(net_log_source) {
42 address_ = state.address;
43 bluetooth_class_ = state.bluetooth_class;
44 visible_ = state.visible;
45 connected_ = state.connected;
46 paired_ = state.authenticated;
48 for (ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator
49 iter = state.service_record_states.begin();
50 iter != state.service_record_states.end();
52 uint8 sdp_bytes_buffer[kSdpBytesBufferSize];
53 std::copy((*iter)->sdp_bytes.begin(),
54 (*iter)->sdp_bytes.end(),
56 BluetoothServiceRecord* service_record = new BluetoothServiceRecordWin(
59 (*iter)->sdp_bytes.size(),
61 service_record_list_.push_back(service_record);
62 uuids_.push_back(service_record->uuid());
66 BluetoothDeviceWin::~BluetoothDeviceWin() {
69 void BluetoothDeviceWin::SetVisible(bool visible) {
73 void BluetoothDeviceWin::AddObserver(
74 device::BluetoothDevice::Observer* observer) {
76 observers_.AddObserver(observer);
79 void BluetoothDeviceWin::RemoveObserver(
80 device::BluetoothDevice::Observer* observer) {
82 observers_.RemoveObserver(observer);
86 uint32 BluetoothDeviceWin::GetBluetoothClass() const {
87 return bluetooth_class_;
90 std::string BluetoothDeviceWin::GetDeviceName() const {
94 std::string BluetoothDeviceWin::GetAddress() const {
98 BluetoothDevice::VendorIDSource
99 BluetoothDeviceWin::GetVendorIDSource() const {
100 return VENDOR_ID_UNKNOWN;
103 uint16 BluetoothDeviceWin::GetVendorID() const {
107 uint16 BluetoothDeviceWin::GetProductID() const {
111 uint16 BluetoothDeviceWin::GetDeviceID() const {
115 int BluetoothDeviceWin::GetRSSI() const {
117 return kUnknownPower;
120 int BluetoothDeviceWin::GetCurrentHostTransmitPower() const {
122 return kUnknownPower;
125 int BluetoothDeviceWin::GetMaximumHostTransmitPower() const {
127 return kUnknownPower;
130 bool BluetoothDeviceWin::IsPaired() const {
134 bool BluetoothDeviceWin::IsConnected() const {
138 bool BluetoothDeviceWin::IsConnectable() const {
142 bool BluetoothDeviceWin::IsConnecting() const {
146 BluetoothDevice::UUIDList BluetoothDeviceWin::GetUUIDs() const {
150 bool BluetoothDeviceWin::ExpectingPinCode() const {
155 bool BluetoothDeviceWin::ExpectingPasskey() const {
160 bool BluetoothDeviceWin::ExpectingConfirmation() const {
165 void BluetoothDeviceWin::Connect(
166 PairingDelegate* pairing_delegate,
167 const base::Closure& callback,
168 const ConnectErrorCallback& error_callback) {
172 void BluetoothDeviceWin::SetPinCode(const std::string& pincode) {
176 void BluetoothDeviceWin::SetPasskey(uint32 passkey) {
180 void BluetoothDeviceWin::ConfirmPairing() {
184 void BluetoothDeviceWin::RejectPairing() {
188 void BluetoothDeviceWin::CancelPairing() {
192 void BluetoothDeviceWin::Disconnect(
193 const base::Closure& callback,
194 const ErrorCallback& error_callback) {
198 void BluetoothDeviceWin::Forget(const ErrorCallback& error_callback) {
202 void BluetoothDeviceWin::ConnectToProfile(
203 device::BluetoothProfile* profile,
204 const base::Closure& callback,
205 const ConnectToProfileErrorCallback& error_callback) {
206 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
207 static_cast<BluetoothProfileWin*>(profile)->Connect(this,
216 void BluetoothDeviceWin::ConnectToService(
217 const BluetoothUUID& uuid,
218 const ConnectToServiceCallback& callback,
219 const ConnectToServiceErrorCallback& error_callback) {
220 // TODO(keybuk): implement
224 void BluetoothDeviceWin::SetOutOfBandPairingData(
225 const BluetoothOutOfBandPairingData& data,
226 const base::Closure& callback,
227 const ErrorCallback& error_callback) {
231 void BluetoothDeviceWin::ClearOutOfBandPairingData(
232 const base::Closure& callback,
233 const ErrorCallback& error_callback) {
237 void BluetoothDeviceWin::StartConnectionMonitor(
238 const base::Closure& callback,
239 const ErrorCallback& error_callback) {
243 const BluetoothServiceRecord* BluetoothDeviceWin::GetServiceRecord(
244 const device::BluetoothUUID& uuid) const {
245 for (ServiceRecordList::const_iterator iter = service_record_list_.begin();
246 iter != service_record_list_.end();
248 if ((*iter)->uuid() == uuid)
254 } // namespace device