diff options
Diffstat (limited to 'device/bluetooth/bluetooth_device_win.cc')
-rw-r--r-- | device/bluetooth/bluetooth_device_win.cc | 65 |
1 files changed, 63 insertions, 2 deletions
diff --git a/device/bluetooth/bluetooth_device_win.cc b/device/bluetooth/bluetooth_device_win.cc index 14fe785..a083f09 100644 --- a/device/bluetooth/bluetooth_device_win.cc +++ b/device/bluetooth/bluetooth_device_win.cc @@ -7,20 +7,58 @@ #include "device/bluetooth/bluetooth_device_win.h" #include <string> + #include "base/basictypes.h" +#include "base/hash.h" #include "base/logging.h" +#include "base/memory/scoped_vector.h" +#include "base/stringprintf.h" #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" +#include "device/bluetooth/bluetooth_service_record_win.h" + +namespace { + +const int kSdpBytesBufferSize = 1024; + +} // namespace namespace device { -BluetoothDeviceWin::BluetoothDeviceWin() : BluetoothDevice() { +BluetoothDeviceWin::BluetoothDeviceWin( + const BluetoothTaskManagerWin::DeviceState& state) + : BluetoothDevice(), device_fingerprint_(ComputeDeviceFingerprint(state)) { + name_ = state.name; + address_ = state.address; + bluetooth_class_ = state.bluetooth_class; + connected_ = state.connected; + bonded_ = state.authenticated; + + for (ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator + iter = state.service_record_states.begin(); + iter != state.service_record_states.end(); + ++iter) { + uint8 sdp_bytes_buffer[kSdpBytesBufferSize]; + std::copy((*iter)->sdp_bytes.begin(), + (*iter)->sdp_bytes.end(), + sdp_bytes_buffer); + BluetoothServiceRecord* service_record = new BluetoothServiceRecordWin( + (*iter)->name, + (*iter)->address, + (*iter)->sdp_bytes.size(), + sdp_bytes_buffer); + service_record_list_.push_back(service_record); + service_uuids_.push_back(service_record->uuid()); + } } BluetoothDeviceWin::~BluetoothDeviceWin() { } +void BluetoothDeviceWin::SetVisible(bool visible) { + visible_ = visible; +} + bool BluetoothDeviceWin::IsPaired() const { - NOTIMPLEMENTED(); return false; } @@ -118,4 +156,27 @@ void BluetoothDeviceWin::ClearOutOfBandPairingData( NOTIMPLEMENTED(); } +// static +uint32 BluetoothDeviceWin::ComputeDeviceFingerprint( + const BluetoothTaskManagerWin::DeviceState& state) { + std::string device_string = base::StringPrintf("%s%s%u%s%s%s", + state.name.c_str(), + state.address.c_str(), + state.bluetooth_class, + state.visible ? "true" : "false", + state.connected ? "true" : "false", + state.authenticated ? "true" : "false"); + for (ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator + iter = state.service_record_states.begin(); + iter != state.service_record_states.end(); + ++iter) { + base::StringAppendF(&device_string, + "%s%s%d", + (*iter)->name.c_str(), + (*iter)->address.c_str(), + (*iter)->sdp_bytes.size()); + } + return base::Hash(device_string); +} + } // namespace device |