Add BluetoothDevice::VendorIDSource()
[chromium-blink-merge.git] / device / bluetooth / bluetooth_device_win.cc
blob3f95efd9b1d87e3713a63a79b81b839a3298ef24
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"
7 #include <string>
9 #include "base/basictypes.h"
10 #include "base/logging.h"
11 #include "base/memory/scoped_vector.h"
12 #include "base/strings/stringprintf.h"
13 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h"
14 #include "device/bluetooth/bluetooth_profile_win.h"
15 #include "device/bluetooth/bluetooth_service_record_win.h"
16 #include "device/bluetooth/bluetooth_socket_win.h"
17 #include "device/bluetooth/bluetooth_task_manager_win.h"
19 namespace {
21 const int kSdpBytesBufferSize = 1024;
23 } // namespace
25 namespace device {
27 BluetoothDeviceWin::BluetoothDeviceWin(
28 const BluetoothTaskManagerWin::DeviceState& state)
29 : BluetoothDevice() {
30 name_ = state.name;
31 address_ = state.address;
32 bluetooth_class_ = state.bluetooth_class;
33 visible_ = state.visible;
34 connected_ = state.connected;
35 paired_ = state.authenticated;
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());
55 BluetoothDeviceWin::~BluetoothDeviceWin() {
58 void BluetoothDeviceWin::SetVisible(bool visible) {
59 visible_ = visible;
62 uint32 BluetoothDeviceWin::GetBluetoothClass() const {
63 return bluetooth_class_;
66 std::string BluetoothDeviceWin::GetDeviceName() const {
67 return name_;
70 std::string BluetoothDeviceWin::GetAddress() const {
71 return address_;
74 BluetoothDevice::VendorIDSource
75 BluetoothDeviceWin::GetVendorIDSource() const {
76 return VENDOR_ID_UNKNOWN;
79 uint16 BluetoothDeviceWin::GetVendorID() const {
80 return 0;
83 uint16 BluetoothDeviceWin::GetProductID() const {
84 return 0;
87 uint16 BluetoothDeviceWin::GetDeviceID() const {
88 return 0;
91 bool BluetoothDeviceWin::IsPaired() const {
92 return paired_;
95 bool BluetoothDeviceWin::IsConnected() const {
96 return connected_;
99 bool BluetoothDeviceWin::IsConnectable() const {
100 return false;
103 bool BluetoothDeviceWin::IsConnecting() const {
104 return false;
107 BluetoothDevice::ServiceList BluetoothDeviceWin::GetServices() const {
108 return service_uuids_;
111 void BluetoothDeviceWin::GetServiceRecords(
112 const ServiceRecordsCallback& callback,
113 const ErrorCallback& error_callback) {
114 callback.Run(service_record_list_);
117 void BluetoothDeviceWin::ProvidesServiceWithName(
118 const std::string& name,
119 const ProvidesServiceCallback& callback) {
120 for (ServiceRecordList::const_iterator iter = service_record_list_.begin();
121 iter != service_record_list_.end();
122 ++iter) {
123 if ((*iter)->name() == name) {
124 callback.Run(true);
125 return;
128 callback.Run(false);
131 bool BluetoothDeviceWin::ExpectingPinCode() const {
132 NOTIMPLEMENTED();
133 return false;
136 bool BluetoothDeviceWin::ExpectingPasskey() const {
137 NOTIMPLEMENTED();
138 return false;
141 bool BluetoothDeviceWin::ExpectingConfirmation() const {
142 NOTIMPLEMENTED();
143 return false;
146 void BluetoothDeviceWin::Connect(
147 PairingDelegate* pairing_delegate,
148 const base::Closure& callback,
149 const ConnectErrorCallback& error_callback) {
150 NOTIMPLEMENTED();
153 void BluetoothDeviceWin::SetPinCode(const std::string& pincode) {
154 NOTIMPLEMENTED();
157 void BluetoothDeviceWin::SetPasskey(uint32 passkey) {
158 NOTIMPLEMENTED();
161 void BluetoothDeviceWin::ConfirmPairing() {
162 NOTIMPLEMENTED();
165 void BluetoothDeviceWin::RejectPairing() {
166 NOTIMPLEMENTED();
169 void BluetoothDeviceWin::CancelPairing() {
170 NOTIMPLEMENTED();
173 void BluetoothDeviceWin::Disconnect(
174 const base::Closure& callback,
175 const ErrorCallback& error_callback) {
176 NOTIMPLEMENTED();
179 void BluetoothDeviceWin::Forget(const ErrorCallback& error_callback) {
180 NOTIMPLEMENTED();
183 void BluetoothDeviceWin::ConnectToService(
184 const std::string& service_uuid,
185 const SocketCallback& callback) {
186 for (ServiceRecordList::const_iterator iter = service_record_list_.begin();
187 iter != service_record_list_.end();
188 ++iter) {
189 if ((*iter)->uuid() == service_uuid) {
190 // If multiple service records are found, use the first one that works.
191 scoped_refptr<BluetoothSocket> socket(
192 BluetoothSocketWin::CreateBluetoothSocket(**iter));
193 if (socket.get() != NULL) {
194 callback.Run(socket);
195 return;
201 void BluetoothDeviceWin::ConnectToProfile(
202 device::BluetoothProfile* profile,
203 const base::Closure& callback,
204 const ErrorCallback& error_callback) {
205 if (static_cast<BluetoothProfileWin*>(profile)->Connect(this))
206 callback.Run();
207 else
208 error_callback.Run();
211 void BluetoothDeviceWin::SetOutOfBandPairingData(
212 const BluetoothOutOfBandPairingData& data,
213 const base::Closure& callback,
214 const ErrorCallback& error_callback) {
215 NOTIMPLEMENTED();
218 void BluetoothDeviceWin::ClearOutOfBandPairingData(
219 const base::Closure& callback,
220 const ErrorCallback& error_callback) {
221 NOTIMPLEMENTED();
224 const BluetoothServiceRecord* BluetoothDeviceWin::GetServiceRecord(
225 const std::string& uuid) const {
226 for (ServiceRecordList::const_iterator iter = service_record_list_.begin();
227 iter != service_record_list_.end();
228 ++iter) {
229 if ((*iter)->uuid().compare(uuid) == 0)
230 return *iter;
232 return NULL;
235 } // namespace device