Fix a type mismatch on Windows caused by r201738.
[chromium-blink-merge.git] / device / bluetooth / bluetooth_device_win.cc
blob11dc52904153037d3e621ae3372882e537b88d18
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/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 uint16 BluetoothDeviceWin::GetVendorID() const {
75 return 0;
78 uint16 BluetoothDeviceWin::GetProductID() const {
79 return 0;
82 uint16 BluetoothDeviceWin::GetDeviceID() const {
83 return 0;
86 bool BluetoothDeviceWin::IsPaired() const {
87 return paired_;
90 bool BluetoothDeviceWin::IsConnected() const {
91 return connected_;
94 bool BluetoothDeviceWin::IsConnectable() const {
95 return false;
98 bool BluetoothDeviceWin::IsConnecting() const {
99 return false;
102 BluetoothDevice::ServiceList BluetoothDeviceWin::GetServices() const {
103 return service_uuids_;
106 void BluetoothDeviceWin::GetServiceRecords(
107 const ServiceRecordsCallback& callback,
108 const ErrorCallback& error_callback) {
109 callback.Run(service_record_list_);
112 void BluetoothDeviceWin::ProvidesServiceWithName(
113 const std::string& name,
114 const ProvidesServiceCallback& callback) {
115 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;
123 callback.Run(false);
126 bool BluetoothDeviceWin::ExpectingPinCode() const {
127 NOTIMPLEMENTED();
128 return false;
131 bool BluetoothDeviceWin::ExpectingPasskey() const {
132 NOTIMPLEMENTED();
133 return false;
136 bool BluetoothDeviceWin::ExpectingConfirmation() const {
137 NOTIMPLEMENTED();
138 return false;
141 void BluetoothDeviceWin::Connect(
142 PairingDelegate* pairing_delegate,
143 const base::Closure& callback,
144 const ConnectErrorCallback& error_callback) {
145 NOTIMPLEMENTED();
148 void BluetoothDeviceWin::SetPinCode(const std::string& pincode) {
149 NOTIMPLEMENTED();
152 void BluetoothDeviceWin::SetPasskey(uint32 passkey) {
153 NOTIMPLEMENTED();
156 void BluetoothDeviceWin::ConfirmPairing() {
157 NOTIMPLEMENTED();
160 void BluetoothDeviceWin::RejectPairing() {
161 NOTIMPLEMENTED();
164 void BluetoothDeviceWin::CancelPairing() {
165 NOTIMPLEMENTED();
168 void BluetoothDeviceWin::Disconnect(
169 const base::Closure& callback,
170 const ErrorCallback& error_callback) {
171 NOTIMPLEMENTED();
174 void BluetoothDeviceWin::Forget(const ErrorCallback& error_callback) {
175 NOTIMPLEMENTED();
178 void BluetoothDeviceWin::ConnectToService(
179 const std::string& service_uuid,
180 const SocketCallback& callback) {
181 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;
196 void BluetoothDeviceWin::ConnectToProfile(
197 device::BluetoothProfile* profile,
198 const base::Closure& callback,
199 const ErrorCallback& error_callback) {
200 if (static_cast<BluetoothProfileWin*>(profile)->Connect(this))
201 callback.Run();
202 else
203 error_callback.Run();
206 void BluetoothDeviceWin::SetOutOfBandPairingData(
207 const BluetoothOutOfBandPairingData& data,
208 const base::Closure& callback,
209 const ErrorCallback& error_callback) {
210 NOTIMPLEMENTED();
213 void BluetoothDeviceWin::ClearOutOfBandPairingData(
214 const base::Closure& callback,
215 const ErrorCallback& error_callback) {
216 NOTIMPLEMENTED();
219 const 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) {
224 return *iter;
226 return NULL;
229 } // namespace device