bluetooth_device_win.cc revision 010d83a9304c5a91596085d917d248abff47903a
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "device/bluetooth/bluetooth_device_win.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_vector.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/sequenced_task_runner.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/strings/stringprintf.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "device/bluetooth/bluetooth_out_of_band_pairing_data.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "device/bluetooth/bluetooth_profile_win.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "device/bluetooth/bluetooth_service_record_win.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "device/bluetooth/bluetooth_socket_thread.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "device/bluetooth/bluetooth_socket_win.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "device/bluetooth/bluetooth_task_manager_win.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "device/bluetooth/bluetooth_uuid.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int kSdpBytesBufferSize = 1024;
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace device {
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)BluetoothDeviceWin::BluetoothDeviceWin(
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const BluetoothTaskManagerWin::DeviceState& state,
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    scoped_refptr<BluetoothSocketThread> socket_thread,
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    net::NetLog* net_log,
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const net::NetLog::Source& net_log_source)
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : BluetoothDevice(),
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      ui_task_runner_(ui_task_runner),
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      socket_thread_(socket_thread),
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      net_log_(net_log),
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      net_log_source_(net_log_source) {
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  name_ = state.name;
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  address_ = state.address;
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bluetooth_class_ = state.bluetooth_class;
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  visible_ = state.visible;
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  connected_ = state.connected;
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  paired_ = state.authenticated;
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)       iter = state.service_record_states.begin();
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)       iter != state.service_record_states.end();
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)       ++iter) {
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    uint8 sdp_bytes_buffer[kSdpBytesBufferSize];
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    std::copy((*iter)->sdp_bytes.begin(),
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)              (*iter)->sdp_bytes.end(),
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)              sdp_bytes_buffer);
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    BluetoothServiceRecord* service_record = new BluetoothServiceRecordWin(
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        (*iter)->name,
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        (*iter)->address,
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        (*iter)->sdp_bytes.size(),
60        sdp_bytes_buffer);
61    service_record_list_.push_back(service_record);
62    uuids_.push_back(service_record->uuid());
63  }
64}
65
66BluetoothDeviceWin::~BluetoothDeviceWin() {
67}
68
69void BluetoothDeviceWin::SetVisible(bool visible) {
70  visible_ = visible;
71}
72
73void BluetoothDeviceWin::AddObserver(
74    device::BluetoothDevice::Observer* observer) {
75  DCHECK(observer);
76  observers_.AddObserver(observer);
77}
78
79void BluetoothDeviceWin::RemoveObserver(
80    device::BluetoothDevice::Observer* observer) {
81  DCHECK(observer);
82  observers_.RemoveObserver(observer);
83}
84
85
86uint32 BluetoothDeviceWin::GetBluetoothClass() const {
87  return bluetooth_class_;
88}
89
90std::string BluetoothDeviceWin::GetDeviceName() const {
91  return name_;
92}
93
94std::string BluetoothDeviceWin::GetAddress() const {
95  return address_;
96}
97
98BluetoothDevice::VendorIDSource
99BluetoothDeviceWin::GetVendorIDSource() const {
100  return VENDOR_ID_UNKNOWN;
101}
102
103uint16 BluetoothDeviceWin::GetVendorID() const {
104  return 0;
105}
106
107uint16 BluetoothDeviceWin::GetProductID() const {
108  return 0;
109}
110
111uint16 BluetoothDeviceWin::GetDeviceID() const {
112  return 0;
113}
114
115int BluetoothDeviceWin::GetRSSI() const {
116  NOTIMPLEMENTED();
117  return kUnknownPower;
118}
119
120int BluetoothDeviceWin::GetCurrentHostTransmitPower() const {
121  NOTIMPLEMENTED();
122  return kUnknownPower;
123}
124
125int BluetoothDeviceWin::GetMaximumHostTransmitPower() const {
126  NOTIMPLEMENTED();
127  return kUnknownPower;
128}
129
130bool BluetoothDeviceWin::IsPaired() const {
131  return paired_;
132}
133
134bool BluetoothDeviceWin::IsConnected() const {
135  return connected_;
136}
137
138bool BluetoothDeviceWin::IsConnectable() const {
139  return false;
140}
141
142bool BluetoothDeviceWin::IsConnecting() const {
143  return false;
144}
145
146BluetoothDevice::UUIDList BluetoothDeviceWin::GetUUIDs() const {
147  return uuids_;
148}
149
150bool BluetoothDeviceWin::ExpectingPinCode() const {
151  NOTIMPLEMENTED();
152  return false;
153}
154
155bool BluetoothDeviceWin::ExpectingPasskey() const {
156  NOTIMPLEMENTED();
157  return false;
158}
159
160bool BluetoothDeviceWin::ExpectingConfirmation() const {
161  NOTIMPLEMENTED();
162  return false;
163}
164
165void BluetoothDeviceWin::Connect(
166    PairingDelegate* pairing_delegate,
167    const base::Closure& callback,
168    const ConnectErrorCallback& error_callback) {
169  NOTIMPLEMENTED();
170}
171
172void BluetoothDeviceWin::SetPinCode(const std::string& pincode) {
173  NOTIMPLEMENTED();
174}
175
176void BluetoothDeviceWin::SetPasskey(uint32 passkey) {
177  NOTIMPLEMENTED();
178}
179
180void BluetoothDeviceWin::ConfirmPairing() {
181  NOTIMPLEMENTED();
182}
183
184void BluetoothDeviceWin::RejectPairing() {
185  NOTIMPLEMENTED();
186}
187
188void BluetoothDeviceWin::CancelPairing() {
189  NOTIMPLEMENTED();
190}
191
192void BluetoothDeviceWin::Disconnect(
193    const base::Closure& callback,
194    const ErrorCallback& error_callback) {
195  NOTIMPLEMENTED();
196}
197
198void BluetoothDeviceWin::Forget(const ErrorCallback& error_callback) {
199  NOTIMPLEMENTED();
200}
201
202void 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,
208                                                      ui_task_runner_,
209                                                      socket_thread_,
210                                                      net_log_,
211                                                      net_log_source_,
212                                                      callback,
213                                                      error_callback);
214}
215
216void BluetoothDeviceWin::ConnectToService(
217    const BluetoothUUID& uuid,
218    const ConnectToServiceCallback& callback,
219    const ConnectToServiceErrorCallback& error_callback) {
220  // TODO(keybuk): implement
221  NOTIMPLEMENTED();
222}
223
224void BluetoothDeviceWin::SetOutOfBandPairingData(
225    const BluetoothOutOfBandPairingData& data,
226    const base::Closure& callback,
227    const ErrorCallback& error_callback) {
228  NOTIMPLEMENTED();
229}
230
231void BluetoothDeviceWin::ClearOutOfBandPairingData(
232    const base::Closure& callback,
233    const ErrorCallback& error_callback) {
234  NOTIMPLEMENTED();
235}
236
237const BluetoothServiceRecord* BluetoothDeviceWin::GetServiceRecord(
238    const device::BluetoothUUID& uuid) const {
239  for (ServiceRecordList::const_iterator iter = service_record_list_.begin();
240       iter != service_record_list_.end();
241       ++iter) {
242    if ((*iter)->uuid() == uuid)
243      return *iter;
244  }
245  return NULL;
246}
247
248}  // namespace device
249