bluetooth_device_win.cc revision c5cede9ae108bb15f6b7a8aea21c7e1fefa2834c
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
114bool BluetoothDeviceWin::IsPaired() const {
115  return paired_;
116}
117
118bool BluetoothDeviceWin::IsConnected() const {
119  return connected_;
120}
121
122bool BluetoothDeviceWin::IsConnectable() const {
123  return false;
124}
125
126bool BluetoothDeviceWin::IsConnecting() const {
127  return false;
128}
129
130BluetoothDevice::UUIDList BluetoothDeviceWin::GetUUIDs() const {
131  return uuids_;
132}
133
134bool BluetoothDeviceWin::ExpectingPinCode() const {
135  NOTIMPLEMENTED();
136  return false;
137}
138
139bool BluetoothDeviceWin::ExpectingPasskey() const {
140  NOTIMPLEMENTED();
141  return false;
142}
143
144bool BluetoothDeviceWin::ExpectingConfirmation() const {
145  NOTIMPLEMENTED();
146  return false;
147}
148
149void BluetoothDeviceWin::Connect(
150    PairingDelegate* pairing_delegate,
151    const base::Closure& callback,
152    const ConnectErrorCallback& error_callback) {
153  NOTIMPLEMENTED();
154}
155
156void BluetoothDeviceWin::SetPinCode(const std::string& pincode) {
157  NOTIMPLEMENTED();
158}
159
160void BluetoothDeviceWin::SetPasskey(uint32 passkey) {
161  NOTIMPLEMENTED();
162}
163
164void BluetoothDeviceWin::ConfirmPairing() {
165  NOTIMPLEMENTED();
166}
167
168void BluetoothDeviceWin::RejectPairing() {
169  NOTIMPLEMENTED();
170}
171
172void BluetoothDeviceWin::CancelPairing() {
173  NOTIMPLEMENTED();
174}
175
176void BluetoothDeviceWin::Disconnect(
177    const base::Closure& callback,
178    const ErrorCallback& error_callback) {
179  NOTIMPLEMENTED();
180}
181
182void BluetoothDeviceWin::Forget(const ErrorCallback& error_callback) {
183  NOTIMPLEMENTED();
184}
185
186void BluetoothDeviceWin::ConnectToService(
187    const device::BluetoothUUID& service_uuid,
188    const SocketCallback& callback) {
189  NOTIMPLEMENTED();
190}
191
192void BluetoothDeviceWin::ConnectToProfile(
193    device::BluetoothProfile* profile,
194    const base::Closure& callback,
195    const ConnectToProfileErrorCallback& error_callback) {
196  DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
197  static_cast<BluetoothProfileWin*>(profile)->Connect(this,
198                                                      ui_task_runner_,
199                                                      socket_thread_,
200                                                      net_log_,
201                                                      net_log_source_,
202                                                      callback,
203                                                      error_callback);
204}
205
206void BluetoothDeviceWin::SetOutOfBandPairingData(
207    const BluetoothOutOfBandPairingData& data,
208    const base::Closure& callback,
209    const ErrorCallback& error_callback) {
210  NOTIMPLEMENTED();
211}
212
213void BluetoothDeviceWin::ClearOutOfBandPairingData(
214    const base::Closure& callback,
215    const ErrorCallback& error_callback) {
216  NOTIMPLEMENTED();
217}
218
219const BluetoothServiceRecord* BluetoothDeviceWin::GetServiceRecord(
220    const device::BluetoothUUID& uuid) const {
221  for (ServiceRecordList::const_iterator iter = service_record_list_.begin();
222       iter != service_record_list_.end();
223       ++iter) {
224    if ((*iter)->uuid() == uuid)
225      return *iter;
226  }
227  return NULL;
228}
229
230}  // namespace device
231