bluetooth_device_win.cc revision 23730a6e56a168d1879203e4b3819bb36e3d8f1f
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/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" 18 19namespace { 20 21const int kSdpBytesBufferSize = 1024; 22 23} // namespace 24 25namespace device { 26 27BluetoothDeviceWin::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; 36 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 uuids_.push_back(service_record->uuid()); 52 } 53} 54 55BluetoothDeviceWin::~BluetoothDeviceWin() { 56} 57 58void BluetoothDeviceWin::SetVisible(bool visible) { 59 visible_ = visible; 60} 61 62uint32 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 74BluetoothDevice::VendorIDSource 75BluetoothDeviceWin::GetVendorIDSource() const { 76 return VENDOR_ID_UNKNOWN; 77} 78 79uint16 BluetoothDeviceWin::GetVendorID() const { 80 return 0; 81} 82 83uint16 BluetoothDeviceWin::GetProductID() const { 84 return 0; 85} 86 87uint16 BluetoothDeviceWin::GetDeviceID() const { 88 return 0; 89} 90 91bool BluetoothDeviceWin::IsPaired() const { 92 return paired_; 93} 94 95bool BluetoothDeviceWin::IsConnected() const { 96 return connected_; 97} 98 99bool BluetoothDeviceWin::IsConnectable() const { 100 return false; 101} 102 103bool BluetoothDeviceWin::IsConnecting() const { 104 return false; 105} 106 107BluetoothDevice::UUIDList BluetoothDeviceWin::GetUUIDs() const { 108 return uuids_; 109} 110 111bool BluetoothDeviceWin::ExpectingPinCode() const { 112 NOTIMPLEMENTED(); 113 return false; 114} 115 116bool BluetoothDeviceWin::ExpectingPasskey() const { 117 NOTIMPLEMENTED(); 118 return false; 119} 120 121bool BluetoothDeviceWin::ExpectingConfirmation() const { 122 NOTIMPLEMENTED(); 123 return false; 124} 125 126void BluetoothDeviceWin::Connect( 127 PairingDelegate* pairing_delegate, 128 const base::Closure& callback, 129 const ConnectErrorCallback& error_callback) { 130 NOTIMPLEMENTED(); 131} 132 133void BluetoothDeviceWin::SetPinCode(const std::string& pincode) { 134 NOTIMPLEMENTED(); 135} 136 137void BluetoothDeviceWin::SetPasskey(uint32 passkey) { 138 NOTIMPLEMENTED(); 139} 140 141void BluetoothDeviceWin::ConfirmPairing() { 142 NOTIMPLEMENTED(); 143} 144 145void BluetoothDeviceWin::RejectPairing() { 146 NOTIMPLEMENTED(); 147} 148 149void BluetoothDeviceWin::CancelPairing() { 150 NOTIMPLEMENTED(); 151} 152 153void BluetoothDeviceWin::Disconnect( 154 const base::Closure& callback, 155 const ErrorCallback& error_callback) { 156 NOTIMPLEMENTED(); 157} 158 159void BluetoothDeviceWin::Forget(const ErrorCallback& error_callback) { 160 NOTIMPLEMENTED(); 161} 162 163void BluetoothDeviceWin::ConnectToService( 164 const std::string& service_uuid, 165 const SocketCallback& callback) { 166 for (ServiceRecordList::const_iterator iter = service_record_list_.begin(); 167 iter != service_record_list_.end(); 168 ++iter) { 169 if ((*iter)->uuid() == service_uuid) { 170 // If multiple service records are found, use the first one that works. 171 scoped_refptr<BluetoothSocket> socket( 172 BluetoothSocketWin::CreateBluetoothSocket(**iter)); 173 if (socket.get() != NULL) { 174 callback.Run(socket); 175 return; 176 } 177 } 178 } 179} 180 181void BluetoothDeviceWin::ConnectToProfile( 182 device::BluetoothProfile* profile, 183 const base::Closure& callback, 184 const ErrorCallback& error_callback) { 185 if (static_cast<BluetoothProfileWin*>(profile)->Connect(this)) 186 callback.Run(); 187 else 188 error_callback.Run(); 189} 190 191void BluetoothDeviceWin::SetOutOfBandPairingData( 192 const BluetoothOutOfBandPairingData& data, 193 const base::Closure& callback, 194 const ErrorCallback& error_callback) { 195 NOTIMPLEMENTED(); 196} 197 198void BluetoothDeviceWin::ClearOutOfBandPairingData( 199 const base::Closure& callback, 200 const ErrorCallback& error_callback) { 201 NOTIMPLEMENTED(); 202} 203 204const BluetoothServiceRecord* BluetoothDeviceWin::GetServiceRecord( 205 const std::string& uuid) const { 206 for (ServiceRecordList::const_iterator iter = service_record_list_.begin(); 207 iter != service_record_list_.end(); 208 ++iter) { 209 if ((*iter)->uuid().compare(uuid) == 0) 210 return *iter; 211 } 212 return NULL; 213} 214 215} // namespace device 216