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_service_record_win.h"
15 #include "device/bluetooth/bluetooth_socket_thread.h"
16 #include "device/bluetooth/bluetooth_socket_win.h"
17 #include "device/bluetooth/bluetooth_task_manager_win.h"
18 #include "device/bluetooth/bluetooth_uuid.h"
22 const int kSdpBytesBufferSize
= 1024;
28 BluetoothDeviceWin::BluetoothDeviceWin(
29 const BluetoothTaskManagerWin::DeviceState
& state
,
30 scoped_refptr
<base::SequencedTaskRunner
> ui_task_runner
,
31 scoped_refptr
<BluetoothSocketThread
> socket_thread
,
33 const net::NetLog::Source
& net_log_source
)
35 ui_task_runner_(ui_task_runner
),
36 socket_thread_(socket_thread
),
38 net_log_source_(net_log_source
) {
40 address_
= CanonicalizeAddress(state
.address
);
41 bluetooth_class_
= state
.bluetooth_class
;
42 visible_
= state
.visible
;
43 connected_
= state
.connected
;
44 paired_
= state
.authenticated
;
46 for (ScopedVector
<BluetoothTaskManagerWin::ServiceRecordState
>::const_iterator
47 iter
= state
.service_record_states
.begin();
48 iter
!= state
.service_record_states
.end();
50 uint8 sdp_bytes_buffer
[kSdpBytesBufferSize
];
51 std::copy((*iter
)->sdp_bytes
.begin(),
52 (*iter
)->sdp_bytes
.end(),
54 BluetoothServiceRecordWin
* service_record
= new BluetoothServiceRecordWin(
57 (*iter
)->sdp_bytes
.size(),
59 service_record_list_
.push_back(service_record
);
60 uuids_
.push_back(service_record
->uuid());
64 BluetoothDeviceWin::~BluetoothDeviceWin() {
67 void BluetoothDeviceWin::SetVisible(bool visible
) {
71 void BluetoothDeviceWin::AddObserver(
72 device::BluetoothDevice::Observer
* observer
) {
74 observers_
.AddObserver(observer
);
77 void BluetoothDeviceWin::RemoveObserver(
78 device::BluetoothDevice::Observer
* observer
) {
80 observers_
.RemoveObserver(observer
);
84 uint32
BluetoothDeviceWin::GetBluetoothClass() const {
85 return bluetooth_class_
;
88 std::string
BluetoothDeviceWin::GetDeviceName() const {
92 std::string
BluetoothDeviceWin::GetAddress() const {
96 BluetoothDevice::VendorIDSource
97 BluetoothDeviceWin::GetVendorIDSource() const {
98 return VENDOR_ID_UNKNOWN
;
101 uint16
BluetoothDeviceWin::GetVendorID() const {
105 uint16
BluetoothDeviceWin::GetProductID() const {
109 uint16
BluetoothDeviceWin::GetDeviceID() const {
113 int BluetoothDeviceWin::GetRSSI() const {
115 return kUnknownPower
;
118 int BluetoothDeviceWin::GetCurrentHostTransmitPower() const {
120 return kUnknownPower
;
123 int BluetoothDeviceWin::GetMaximumHostTransmitPower() const {
125 return kUnknownPower
;
128 bool BluetoothDeviceWin::IsPaired() const {
132 bool BluetoothDeviceWin::IsConnected() const {
136 bool BluetoothDeviceWin::IsConnectable() const {
140 bool BluetoothDeviceWin::IsConnecting() const {
144 BluetoothDevice::UUIDList
BluetoothDeviceWin::GetUUIDs() const {
148 bool BluetoothDeviceWin::ExpectingPinCode() const {
153 bool BluetoothDeviceWin::ExpectingPasskey() const {
158 bool BluetoothDeviceWin::ExpectingConfirmation() const {
163 void BluetoothDeviceWin::Connect(
164 PairingDelegate
* pairing_delegate
,
165 const base::Closure
& callback
,
166 const ConnectErrorCallback
& error_callback
) {
170 void BluetoothDeviceWin::SetPinCode(const std::string
& pincode
) {
174 void BluetoothDeviceWin::SetPasskey(uint32 passkey
) {
178 void BluetoothDeviceWin::ConfirmPairing() {
182 void BluetoothDeviceWin::RejectPairing() {
186 void BluetoothDeviceWin::CancelPairing() {
190 void BluetoothDeviceWin::Disconnect(
191 const base::Closure
& callback
,
192 const ErrorCallback
& error_callback
) {
196 void BluetoothDeviceWin::Forget(const ErrorCallback
& error_callback
) {
200 void BluetoothDeviceWin::ConnectToService(
201 const BluetoothUUID
& uuid
,
202 const ConnectToServiceCallback
& callback
,
203 const ConnectToServiceErrorCallback
& error_callback
) {
204 scoped_refptr
<BluetoothSocketWin
> socket(
205 BluetoothSocketWin::CreateBluetoothSocket(
206 ui_task_runner_
, socket_thread_
, NULL
, net::NetLog::Source()));
207 socket
->Connect(this, uuid
, base::Bind(callback
, socket
), error_callback
);
210 void BluetoothDeviceWin::CreateGattConnection(
211 const GattConnectionCallback
& callback
,
212 const ConnectErrorCallback
& error_callback
) {
213 // TODO(armansito): Implement.
214 error_callback
.Run(ERROR_UNSUPPORTED_DEVICE
);
217 void BluetoothDeviceWin::StartConnectionMonitor(
218 const base::Closure
& callback
,
219 const ErrorCallback
& error_callback
) {
223 const BluetoothServiceRecordWin
* BluetoothDeviceWin::GetServiceRecord(
224 const device::BluetoothUUID
& uuid
) const {
225 for (ServiceRecordList::const_iterator iter
= service_record_list_
.begin();
226 iter
!= service_record_list_
.end();
228 if ((*iter
)->uuid() == uuid
)
234 } // namespace device