blob: bfd9bc61297e506d7333881e61d87b98cd77766f [file] [log] [blame]
[email protected]0ae97592012-10-22 22:06:051// 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.
[email protected]0ae97592012-10-22 22:06:054
5#include "device/bluetooth/bluetooth_device_win.h"
6
7#include <string>
[email protected]d7ba43752013-02-21 22:27:058
[email protected]0ae97592012-10-22 22:06:059#include "base/basictypes.h"
10#include "base/logging.h"
[email protected]d7ba43752013-02-21 22:27:0511#include "base/memory/scoped_vector.h"
[email protected]0d8db082013-06-11 07:27:0112#include "base/strings/stringprintf.h"
[email protected]0ae97592012-10-22 22:06:0513#include "device/bluetooth/bluetooth_out_of_band_pairing_data.h"
[email protected]e55a50f2013-05-05 03:37:0914#include "device/bluetooth/bluetooth_profile_win.h"
[email protected]d7ba43752013-02-21 22:27:0515#include "device/bluetooth/bluetooth_service_record_win.h"
[email protected]edcaf14a2013-02-25 17:46:3616#include "device/bluetooth/bluetooth_socket_win.h"
17#include "device/bluetooth/bluetooth_task_manager_win.h"
[email protected]d7ba43752013-02-21 22:27:0518
19namespace {
20
21const int kSdpBytesBufferSize = 1024;
22
23} // namespace
[email protected]0ae97592012-10-22 22:06:0524
25namespace device {
26
[email protected]d7ba43752013-02-21 22:27:0527BluetoothDeviceWin::BluetoothDeviceWin(
28 const BluetoothTaskManagerWin::DeviceState& state)
[email protected]e55a50f2013-05-05 03:37:0929 : BluetoothDevice() {
[email protected]d7ba43752013-02-21 22:27:0530 name_ = state.name;
31 address_ = state.address;
32 bluetooth_class_ = state.bluetooth_class;
[email protected]320447d72013-04-05 03:32:2633 visible_ = state.visible;
[email protected]d7ba43752013-02-21 22:27:0534 connected_ = state.connected;
[email protected]320447d72013-04-05 03:32:2635 paired_ = state.authenticated;
[email protected]d7ba43752013-02-21 22:27:0536
37 for (ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator
38 iter = state.service_record_states.begin();
39 iter != state.service_record_states.end();
40 ++iter) {
41 uint8 sdp_bytes_buffer[kSdpBytesBufferSize];
42 std::copy((*iter)->sdp_bytes.begin(),
43 (*iter)->sdp_bytes.end(),
44 sdp_bytes_buffer);
45 BluetoothServiceRecord* service_record = new BluetoothServiceRecordWin(
46 (*iter)->name,
47 (*iter)->address,
48 (*iter)->sdp_bytes.size(),
49 sdp_bytes_buffer);
50 service_record_list_.push_back(service_record);
51 service_uuids_.push_back(service_record->uuid());
52 }
[email protected]0ae97592012-10-22 22:06:0553}
54
55BluetoothDeviceWin::~BluetoothDeviceWin() {
56}
57
[email protected]d7ba43752013-02-21 22:27:0558void BluetoothDeviceWin::SetVisible(bool visible) {
59 visible_ = visible;
60}
61
[email protected]320447d72013-04-05 03:32:2662uint32 BluetoothDeviceWin::GetBluetoothClass() const {
63 return bluetooth_class_;
64}
65
66std::string BluetoothDeviceWin::GetDeviceName() const {
67 return name_;
68}
69
70std::string BluetoothDeviceWin::GetAddress() const {
71 return address_;
72}
73
[email protected]611ae29a2013-04-29 21:32:1974uint16 BluetoothDeviceWin::GetVendorID() const {
75 return 0;
76}
77
78uint16 BluetoothDeviceWin::GetProductID() const {
79 return 0;
80}
81
82uint16 BluetoothDeviceWin::GetDeviceID() const {
83 return 0;
84}
85
[email protected]0ae97592012-10-22 22:06:0586bool BluetoothDeviceWin::IsPaired() const {
[email protected]320447d72013-04-05 03:32:2687 return paired_;
88}
89
90bool BluetoothDeviceWin::IsConnected() const {
91 return connected_;
92}
93
94bool BluetoothDeviceWin::IsConnectable() const {
[email protected]0ae97592012-10-22 22:06:0595 return false;
96}
97
[email protected]320447d72013-04-05 03:32:2698bool BluetoothDeviceWin::IsConnecting() const {
99 return false;
100}
101
102BluetoothDevice::ServiceList BluetoothDeviceWin::GetServices() const {
[email protected]0ae97592012-10-22 22:06:05103 return service_uuids_;
104}
105
106void BluetoothDeviceWin::GetServiceRecords(
107 const ServiceRecordsCallback& callback,
108 const ErrorCallback& error_callback) {
[email protected]edcaf14a2013-02-25 17:46:36109 callback.Run(service_record_list_);
[email protected]0ae97592012-10-22 22:06:05110}
111
112void BluetoothDeviceWin::ProvidesServiceWithName(
113 const std::string& name,
114 const ProvidesServiceCallback& callback) {
[email protected]edcaf14a2013-02-25 17:46:36115 for (ServiceRecordList::const_iterator iter = service_record_list_.begin();
116 iter != service_record_list_.end();
117 ++iter) {
118 if ((*iter)->name() == name) {
119 callback.Run(true);
120 return;
121 }
122 }
123 callback.Run(false);
[email protected]0ae97592012-10-22 22:06:05124}
125
126bool BluetoothDeviceWin::ExpectingPinCode() const {
127 NOTIMPLEMENTED();
128 return false;
129}
130
131bool BluetoothDeviceWin::ExpectingPasskey() const {
132 NOTIMPLEMENTED();
133 return false;
134}
135
136bool BluetoothDeviceWin::ExpectingConfirmation() const {
137 NOTIMPLEMENTED();
138 return false;
139}
140
141void BluetoothDeviceWin::Connect(
142 PairingDelegate* pairing_delegate,
143 const base::Closure& callback,
[email protected]eb72b662012-12-18 06:55:41144 const ConnectErrorCallback& error_callback) {
[email protected]0ae97592012-10-22 22:06:05145 NOTIMPLEMENTED();
146}
147
148void BluetoothDeviceWin::SetPinCode(const std::string& pincode) {
149 NOTIMPLEMENTED();
150}
151
152void BluetoothDeviceWin::SetPasskey(uint32 passkey) {
153 NOTIMPLEMENTED();
154}
155
156void BluetoothDeviceWin::ConfirmPairing() {
157 NOTIMPLEMENTED();
158}
159
160void BluetoothDeviceWin::RejectPairing() {
161 NOTIMPLEMENTED();
162}
163
164void BluetoothDeviceWin::CancelPairing() {
165 NOTIMPLEMENTED();
166}
167
168void BluetoothDeviceWin::Disconnect(
169 const base::Closure& callback,
170 const ErrorCallback& error_callback) {
171 NOTIMPLEMENTED();
172}
173
174void BluetoothDeviceWin::Forget(const ErrorCallback& error_callback) {
175 NOTIMPLEMENTED();
176}
177
178void BluetoothDeviceWin::ConnectToService(
179 const std::string& service_uuid,
180 const SocketCallback& callback) {
[email protected]edcaf14a2013-02-25 17:46:36181 for (ServiceRecordList::const_iterator iter = service_record_list_.begin();
182 iter != service_record_list_.end();
183 ++iter) {
184 if ((*iter)->uuid() == service_uuid) {
185 // If multiple service records are found, use the first one that works.
186 scoped_refptr<BluetoothSocket> socket(
187 BluetoothSocketWin::CreateBluetoothSocket(**iter));
188 if (socket.get() != NULL) {
189 callback.Run(socket);
190 return;
191 }
192 }
193 }
[email protected]0ae97592012-10-22 22:06:05194}
195
[email protected]2862df462013-04-19 21:07:21196void BluetoothDeviceWin::ConnectToProfile(
197 device::BluetoothProfile* profile,
[email protected]476f29d2013-04-24 09:06:51198 const base::Closure& callback,
[email protected]2862df462013-04-19 21:07:21199 const ErrorCallback& error_callback) {
[email protected]e55a50f2013-05-05 03:37:09200 if (static_cast<BluetoothProfileWin*>(profile)->Connect(this))
201 callback.Run();
202 else
203 error_callback.Run();
[email protected]2862df462013-04-19 21:07:21204}
205
[email protected]0ae97592012-10-22 22:06:05206void 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
[email protected]e55a50f2013-05-05 03:37:09219const BluetoothServiceRecord* BluetoothDeviceWin::GetServiceRecord(
220 const std::string& uuid) const {
221 for (ServiceRecordList::const_iterator iter = service_record_list_.begin();
222 iter != service_record_list_.end();
223 ++iter) {
[email protected]69b68382013-07-31 15:49:36224 if ((*iter)->uuid().compare(uuid) == 0)
225 return *iter;
[email protected]d7ba43752013-02-21 22:27:05226 }
[email protected]e55a50f2013-05-05 03:37:09227 return NULL;
[email protected]d7ba43752013-02-21 22:27:05228}
229
[email protected]0ae97592012-10-22 22:06:05230} // namespace device