bluetooth_device_win.cc revision 5c02ac1a9c1b504631c0a3d2b6e737b5d738bae1
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.
4
5#include "device/bluetooth/bluetooth_device_win.h"
6
7#include <string>
8
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_win.h"
18#include "device/bluetooth/bluetooth_socket_win.h"
19#include "device/bluetooth/bluetooth_task_manager_win.h"
20
21namespace {
22
23const int kSdpBytesBufferSize = 1024;
24
25}  // namespace
26
27namespace device {
28
29BluetoothDeviceWin::BluetoothDeviceWin(
30    const BluetoothTaskManagerWin::DeviceState& state,
31    scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
32    scoped_refptr<BluetoothSocketThreadWin> socket_thread,
33    net::NetLog* net_log,
34    const net::NetLog::Source& net_log_source)
35    : BluetoothDevice(),
36      ui_task_runner_(ui_task_runner),
37      socket_thread_(socket_thread),
38      net_log_(net_log),
39      net_log_source_(net_log_source) {
40  name_ = state.name;
41  address_ = state.address;
42  bluetooth_class_ = state.bluetooth_class;
43  visible_ = state.visible;
44  connected_ = state.connected;
45  paired_ = state.authenticated;
46
47  for (ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator
48       iter = state.service_record_states.begin();
49       iter != state.service_record_states.end();
50       ++iter) {
51    uint8 sdp_bytes_buffer[kSdpBytesBufferSize];
52    std::copy((*iter)->sdp_bytes.begin(),
53              (*iter)->sdp_bytes.end(),
54              sdp_bytes_buffer);
55    BluetoothServiceRecord* service_record = new BluetoothServiceRecordWin(
56        (*iter)->name,
57        (*iter)->address,
58        (*iter)->sdp_bytes.size(),
59        sdp_bytes_buffer);
60    service_record_list_.push_back(service_record);
61    uuids_.push_back(service_record->uuid());
62  }
63}
64
65BluetoothDeviceWin::~BluetoothDeviceWin() {
66}
67
68void BluetoothDeviceWin::SetVisible(bool visible) {
69  visible_ = visible;
70}
71
72void BluetoothDeviceWin::AddObserver(
73    device::BluetoothDevice::Observer* observer) {
74  DCHECK(observer);
75  observers_.AddObserver(observer);
76}
77
78void BluetoothDeviceWin::RemoveObserver(
79    device::BluetoothDevice::Observer* observer) {
80  DCHECK(observer);
81  observers_.RemoveObserver(observer);
82}
83
84
85uint32 BluetoothDeviceWin::GetBluetoothClass() const {
86  return bluetooth_class_;
87}
88
89std::string BluetoothDeviceWin::GetDeviceName() const {
90  return name_;
91}
92
93std::string BluetoothDeviceWin::GetAddress() const {
94  return address_;
95}
96
97BluetoothDevice::VendorIDSource
98BluetoothDeviceWin::GetVendorIDSource() const {
99  return VENDOR_ID_UNKNOWN;
100}
101
102uint16 BluetoothDeviceWin::GetVendorID() const {
103  return 0;
104}
105
106uint16 BluetoothDeviceWin::GetProductID() const {
107  return 0;
108}
109
110uint16 BluetoothDeviceWin::GetDeviceID() const {
111  return 0;
112}
113
114int BluetoothDeviceWin::GetRSSI() const {
115  NOTIMPLEMENTED();
116  return kUnknownPower;
117}
118
119int BluetoothDeviceWin::GetCurrentHostTransmitPower() const {
120  NOTIMPLEMENTED();
121  return kUnknownPower;
122}
123
124int BluetoothDeviceWin::GetMaximumHostTransmitPower() const {
125  NOTIMPLEMENTED();
126  return kUnknownPower;
127}
128
129bool BluetoothDeviceWin::IsPaired() const {
130  return paired_;
131}
132
133bool BluetoothDeviceWin::IsConnected() const {
134  return connected_;
135}
136
137bool BluetoothDeviceWin::IsConnectable() const {
138  return false;
139}
140
141bool BluetoothDeviceWin::IsConnecting() const {
142  return false;
143}
144
145BluetoothDevice::UUIDList BluetoothDeviceWin::GetUUIDs() const {
146  return uuids_;
147}
148
149bool BluetoothDeviceWin::ExpectingPinCode() const {
150  NOTIMPLEMENTED();
151  return false;
152}
153
154bool BluetoothDeviceWin::ExpectingPasskey() const {
155  NOTIMPLEMENTED();
156  return false;
157}
158
159bool BluetoothDeviceWin::ExpectingConfirmation() const {
160  NOTIMPLEMENTED();
161  return false;
162}
163
164void BluetoothDeviceWin::Connect(
165    PairingDelegate* pairing_delegate,
166    const base::Closure& callback,
167    const ConnectErrorCallback& error_callback) {
168  NOTIMPLEMENTED();
169}
170
171void BluetoothDeviceWin::SetPinCode(const std::string& pincode) {
172  NOTIMPLEMENTED();
173}
174
175void BluetoothDeviceWin::SetPasskey(uint32 passkey) {
176  NOTIMPLEMENTED();
177}
178
179void BluetoothDeviceWin::ConfirmPairing() {
180  NOTIMPLEMENTED();
181}
182
183void BluetoothDeviceWin::RejectPairing() {
184  NOTIMPLEMENTED();
185}
186
187void BluetoothDeviceWin::CancelPairing() {
188  NOTIMPLEMENTED();
189}
190
191void BluetoothDeviceWin::Disconnect(
192    const base::Closure& callback,
193    const ErrorCallback& error_callback) {
194  NOTIMPLEMENTED();
195}
196
197void BluetoothDeviceWin::Forget(const ErrorCallback& error_callback) {
198  NOTIMPLEMENTED();
199}
200
201void BluetoothDeviceWin::ConnectToProfile(
202    device::BluetoothProfile* profile,
203    const base::Closure& callback,
204    const ConnectToProfileErrorCallback& error_callback) {
205  DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
206  static_cast<BluetoothProfileWin*>(profile)->Connect(this,
207                                                      ui_task_runner_,
208                                                      socket_thread_,
209                                                      net_log_,
210                                                      net_log_source_,
211                                                      callback,
212                                                      error_callback);
213}
214
215void BluetoothDeviceWin::SetOutOfBandPairingData(
216    const BluetoothOutOfBandPairingData& data,
217    const base::Closure& callback,
218    const ErrorCallback& error_callback) {
219  NOTIMPLEMENTED();
220}
221
222void BluetoothDeviceWin::ClearOutOfBandPairingData(
223    const base::Closure& callback,
224    const ErrorCallback& error_callback) {
225  NOTIMPLEMENTED();
226}
227
228const BluetoothServiceRecord* BluetoothDeviceWin::GetServiceRecord(
229    const device::BluetoothUUID& uuid) const {
230  for (ServiceRecordList::const_iterator iter = service_record_list_.begin();
231       iter != service_record_list_.end();
232       ++iter) {
233    if ((*iter)->uuid() == uuid)
234      return *iter;
235  }
236  return NULL;
237}
238
239}  // namespace device
240