Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1849)

Side by Side Diff: device/bluetooth/bluetooth_device_win.cc

Issue 13416005: Bluetooth: clean up BluetoothDevice (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make GetServices return a copy of the list Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "device/bluetooth/bluetooth_device_win.h" 5 #include "device/bluetooth/bluetooth_device_win.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/hash.h" 10 #include "base/hash.h"
(...skipping 13 matching lines...) Expand all
24 24
25 namespace device { 25 namespace device {
26 26
27 BluetoothDeviceWin::BluetoothDeviceWin( 27 BluetoothDeviceWin::BluetoothDeviceWin(
28 const BluetoothTaskManagerWin::DeviceState& state) 28 const BluetoothTaskManagerWin::DeviceState& state)
29 : BluetoothDevice(), device_fingerprint_(ComputeDeviceFingerprint(state)) { 29 : BluetoothDevice(), device_fingerprint_(ComputeDeviceFingerprint(state)) {
30 name_ = state.name; 30 name_ = state.name;
31 address_ = state.address; 31 address_ = state.address;
32 bluetooth_class_ = state.bluetooth_class; 32 bluetooth_class_ = state.bluetooth_class;
33 connected_ = state.connected; 33 connected_ = state.connected;
34 bonded_ = state.authenticated; 34 paired_ = state.authenticated;
35 35
36 for (ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator 36 for (ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator
37 iter = state.service_record_states.begin(); 37 iter = state.service_record_states.begin();
38 iter != state.service_record_states.end(); 38 iter != state.service_record_states.end();
39 ++iter) { 39 ++iter) {
40 uint8 sdp_bytes_buffer[kSdpBytesBufferSize]; 40 uint8 sdp_bytes_buffer[kSdpBytesBufferSize];
41 std::copy((*iter)->sdp_bytes.begin(), 41 std::copy((*iter)->sdp_bytes.begin(),
42 (*iter)->sdp_bytes.end(), 42 (*iter)->sdp_bytes.end(),
43 sdp_bytes_buffer); 43 sdp_bytes_buffer);
44 BluetoothServiceRecord* service_record = new BluetoothServiceRecordWin( 44 BluetoothServiceRecord* service_record = new BluetoothServiceRecordWin(
45 (*iter)->name, 45 (*iter)->name,
46 (*iter)->address, 46 (*iter)->address,
47 (*iter)->sdp_bytes.size(), 47 (*iter)->sdp_bytes.size(),
48 sdp_bytes_buffer); 48 sdp_bytes_buffer);
49 service_record_list_.push_back(service_record); 49 service_record_list_.push_back(service_record);
50 service_uuids_.push_back(service_record->uuid()); 50 service_uuids_.push_back(service_record->uuid());
51 } 51 }
52 } 52 }
53 53
54 BluetoothDeviceWin::~BluetoothDeviceWin() { 54 BluetoothDeviceWin::~BluetoothDeviceWin() {
55 } 55 }
56 56
57 void BluetoothDeviceWin::SetVisible(bool visible) { 57 uint32 BluetoothDeviceWin::bluetooth_class() const {
58 visible_ = visible; 58 return bluetooth_class_;
59 }
60
61 std::string BluetoothDeviceWin::name() const {
62 return name_;
63 }
64
65 std::string BluetoothDeviceWin::address() const {
66 return address_;
59 } 67 }
60 68
61 bool BluetoothDeviceWin::IsPaired() const { 69 bool BluetoothDeviceWin::IsPaired() const {
70 return paired_;
71 }
72
73 bool BluetoothDeviceWin::IsConnected() const {
74 return connected_;
75 }
76
77 bool BluetoothDeviceWin::IsConnectable() const {
62 return false; 78 return false;
63 } 79 }
64 80
65 const BluetoothDevice::ServiceList& BluetoothDeviceWin::GetServices() const { 81 bool BluetoothDeviceWin::IsConnecting() const {
82 return false;
83 }
84
85 BluetoothDevice::ServiceList BluetoothDeviceWin::GetServices() const {
66 return service_uuids_; 86 return service_uuids_;
67 } 87 }
68 88
69 void BluetoothDeviceWin::GetServiceRecords( 89 void BluetoothDeviceWin::GetServiceRecords(
70 const ServiceRecordsCallback& callback, 90 const ServiceRecordsCallback& callback,
71 const ErrorCallback& error_callback) { 91 const ErrorCallback& error_callback) {
72 callback.Run(service_record_list_); 92 callback.Run(service_record_list_);
73 } 93 }
74 94
75 void BluetoothDeviceWin::ProvidesServiceWithName( 95 void BluetoothDeviceWin::ProvidesServiceWithName(
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 NOTIMPLEMENTED(); 189 NOTIMPLEMENTED();
170 } 190 }
171 191
172 // static 192 // static
173 uint32 BluetoothDeviceWin::ComputeDeviceFingerprint( 193 uint32 BluetoothDeviceWin::ComputeDeviceFingerprint(
174 const BluetoothTaskManagerWin::DeviceState& state) { 194 const BluetoothTaskManagerWin::DeviceState& state) {
175 std::string device_string = base::StringPrintf("%s%s%u%s%s%s", 195 std::string device_string = base::StringPrintf("%s%s%u%s%s%s",
176 state.name.c_str(), 196 state.name.c_str(),
177 state.address.c_str(), 197 state.address.c_str(),
178 state.bluetooth_class, 198 state.bluetooth_class,
179 state.visible ? "true" : "false",
180 state.connected ? "true" : "false", 199 state.connected ? "true" : "false",
181 state.authenticated ? "true" : "false"); 200 state.authenticated ? "true" : "false");
182 for (ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator 201 for (ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator
183 iter = state.service_record_states.begin(); 202 iter = state.service_record_states.begin();
184 iter != state.service_record_states.end(); 203 iter != state.service_record_states.end();
185 ++iter) { 204 ++iter) {
186 base::StringAppendF(&device_string, 205 base::StringAppendF(&device_string,
187 "%s%s%d", 206 "%s%s%d",
188 (*iter)->name.c_str(), 207 (*iter)->name.c_str(),
189 (*iter)->address.c_str(), 208 (*iter)->address.c_str(),
190 (*iter)->sdp_bytes.size()); 209 (*iter)->sdp_bytes.size());
191 } 210 }
192 return base::Hash(device_string); 211 return base::Hash(device_string);
193 } 212 }
194 213
195 } // namespace device 214 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698