OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_bluez.h" | 5 #include "device/bluetooth/bluetooth_device_bluez.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 UMA_PAIRING_RESULT_AUTH_TIMEOUT, | 45 UMA_PAIRING_RESULT_AUTH_TIMEOUT, |
46 UMA_PAIRING_RESULT_UNSUPPORTED_DEVICE, | 46 UMA_PAIRING_RESULT_UNSUPPORTED_DEVICE, |
47 UMA_PAIRING_RESULT_UNKNOWN_ERROR, | 47 UMA_PAIRING_RESULT_UNKNOWN_ERROR, |
48 // NOTE: Add new pairing results immediately above this line. Make sure to | 48 // NOTE: Add new pairing results immediately above this line. Make sure to |
49 // update the enum list in tools/histogram/histograms.xml accordinly. | 49 // update the enum list in tools/histogram/histograms.xml accordinly. |
50 UMA_PAIRING_RESULT_COUNT | 50 UMA_PAIRING_RESULT_COUNT |
51 }; | 51 }; |
52 | 52 |
53 void ParseModalias(const dbus::ObjectPath& object_path, | 53 void ParseModalias(const dbus::ObjectPath& object_path, |
54 BluetoothDevice::VendorIDSource* vendor_id_source, | 54 BluetoothDevice::VendorIDSource* vendor_id_source, |
55 uint16* vendor_id, | 55 uint16_t* vendor_id, |
56 uint16* product_id, | 56 uint16_t* product_id, |
57 uint16* device_id) { | 57 uint16_t* device_id) { |
58 bluez::BluetoothDeviceClient::Properties* properties = | 58 bluez::BluetoothDeviceClient::Properties* properties = |
59 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( | 59 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
60 object_path); | 60 object_path); |
61 DCHECK(properties); | 61 DCHECK(properties); |
62 | 62 |
63 std::string modalias = properties->modalias.value(); | 63 std::string modalias = properties->modalias.value(); |
64 BluetoothDevice::VendorIDSource source_value; | 64 BluetoothDevice::VendorIDSource source_value; |
65 int vendor_value, product_value, device_value; | 65 int vendor_value, product_value, device_value; |
66 | 66 |
67 if (sscanf(modalias.c_str(), "bluetooth:v%04xp%04xd%04x", &vendor_value, | 67 if (sscanf(modalias.c_str(), "bluetooth:v%04xp%04xd%04x", &vendor_value, |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 // send GattServiceRemoved(), GetGattServices() returns no services. | 174 // send GattServiceRemoved(), GetGattServices() returns no services. |
175 GattServiceMap gatt_services_swapped; | 175 GattServiceMap gatt_services_swapped; |
176 gatt_services_swapped.swap(gatt_services_); | 176 gatt_services_swapped.swap(gatt_services_); |
177 for (const auto& iter : gatt_services_swapped) { | 177 for (const auto& iter : gatt_services_swapped) { |
178 DCHECK(adapter_); | 178 DCHECK(adapter_); |
179 adapter()->NotifyGattServiceRemoved( | 179 adapter()->NotifyGattServiceRemoved( |
180 static_cast<BluetoothRemoteGattServiceBlueZ*>(iter.second)); | 180 static_cast<BluetoothRemoteGattServiceBlueZ*>(iter.second)); |
181 } | 181 } |
182 } | 182 } |
183 | 183 |
184 uint32 BluetoothDeviceBlueZ::GetBluetoothClass() const { | 184 uint32_t BluetoothDeviceBlueZ::GetBluetoothClass() const { |
185 bluez::BluetoothDeviceClient::Properties* properties = | 185 bluez::BluetoothDeviceClient::Properties* properties = |
186 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( | 186 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
187 object_path_); | 187 object_path_); |
188 DCHECK(properties); | 188 DCHECK(properties); |
189 | 189 |
190 return properties->bluetooth_class.value(); | 190 return properties->bluetooth_class.value(); |
191 } | 191 } |
192 | 192 |
193 std::string BluetoothDeviceBlueZ::GetDeviceName() const { | 193 std::string BluetoothDeviceBlueZ::GetDeviceName() const { |
194 bluez::BluetoothDeviceClient::Properties* properties = | 194 bluez::BluetoothDeviceClient::Properties* properties = |
(...skipping 25 matching lines...) Expand all Loading... |
220 return CanonicalizeAddress(properties->address.value()); | 220 return CanonicalizeAddress(properties->address.value()); |
221 } | 221 } |
222 | 222 |
223 BluetoothDevice::VendorIDSource BluetoothDeviceBlueZ::GetVendorIDSource() | 223 BluetoothDevice::VendorIDSource BluetoothDeviceBlueZ::GetVendorIDSource() |
224 const { | 224 const { |
225 VendorIDSource vendor_id_source = VENDOR_ID_UNKNOWN; | 225 VendorIDSource vendor_id_source = VENDOR_ID_UNKNOWN; |
226 ParseModalias(object_path_, &vendor_id_source, NULL, NULL, NULL); | 226 ParseModalias(object_path_, &vendor_id_source, NULL, NULL, NULL); |
227 return vendor_id_source; | 227 return vendor_id_source; |
228 } | 228 } |
229 | 229 |
230 uint16 BluetoothDeviceBlueZ::GetVendorID() const { | 230 uint16_t BluetoothDeviceBlueZ::GetVendorID() const { |
231 uint16 vendor_id = 0; | 231 uint16_t vendor_id = 0; |
232 ParseModalias(object_path_, NULL, &vendor_id, NULL, NULL); | 232 ParseModalias(object_path_, NULL, &vendor_id, NULL, NULL); |
233 return vendor_id; | 233 return vendor_id; |
234 } | 234 } |
235 | 235 |
236 uint16 BluetoothDeviceBlueZ::GetProductID() const { | 236 uint16_t BluetoothDeviceBlueZ::GetProductID() const { |
237 uint16 product_id = 0; | 237 uint16_t product_id = 0; |
238 ParseModalias(object_path_, NULL, NULL, &product_id, NULL); | 238 ParseModalias(object_path_, NULL, NULL, &product_id, NULL); |
239 return product_id; | 239 return product_id; |
240 } | 240 } |
241 | 241 |
242 uint16 BluetoothDeviceBlueZ::GetDeviceID() const { | 242 uint16_t BluetoothDeviceBlueZ::GetDeviceID() const { |
243 uint16 device_id = 0; | 243 uint16_t device_id = 0; |
244 ParseModalias(object_path_, NULL, NULL, NULL, &device_id); | 244 ParseModalias(object_path_, NULL, NULL, NULL, &device_id); |
245 return device_id; | 245 return device_id; |
246 } | 246 } |
247 | 247 |
248 bool BluetoothDeviceBlueZ::IsPaired() const { | 248 bool BluetoothDeviceBlueZ::IsPaired() const { |
249 bluez::BluetoothDeviceClient::Properties* properties = | 249 bluez::BluetoothDeviceClient::Properties* properties = |
250 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( | 250 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
251 object_path_); | 251 object_path_); |
252 DCHECK(properties); | 252 DCHECK(properties); |
253 | 253 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 const std::vector<std::string>& dbus_uuids = properties->uuids.value(); | 297 const std::vector<std::string>& dbus_uuids = properties->uuids.value(); |
298 for (std::vector<std::string>::const_iterator iter = dbus_uuids.begin(); | 298 for (std::vector<std::string>::const_iterator iter = dbus_uuids.begin(); |
299 iter != dbus_uuids.end(); ++iter) { | 299 iter != dbus_uuids.end(); ++iter) { |
300 device::BluetoothUUID uuid(*iter); | 300 device::BluetoothUUID uuid(*iter); |
301 DCHECK(uuid.IsValid()); | 301 DCHECK(uuid.IsValid()); |
302 uuids.push_back(uuid); | 302 uuids.push_back(uuid); |
303 } | 303 } |
304 return uuids; | 304 return uuids; |
305 } | 305 } |
306 | 306 |
307 int16 BluetoothDeviceBlueZ::GetInquiryRSSI() const { | 307 int16_t BluetoothDeviceBlueZ::GetInquiryRSSI() const { |
308 bluez::BluetoothDeviceClient::Properties* properties = | 308 bluez::BluetoothDeviceClient::Properties* properties = |
309 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( | 309 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
310 object_path_); | 310 object_path_); |
311 DCHECK(properties); | 311 DCHECK(properties); |
312 | 312 |
313 if (!properties->rssi.is_valid()) | 313 if (!properties->rssi.is_valid()) |
314 return kUnknownPower; | 314 return kUnknownPower; |
315 | 315 |
316 return properties->rssi.value(); | 316 return properties->rssi.value(); |
317 } | 317 } |
318 | 318 |
319 int16 BluetoothDeviceBlueZ::GetInquiryTxPower() const { | 319 int16_t BluetoothDeviceBlueZ::GetInquiryTxPower() const { |
320 bluez::BluetoothDeviceClient::Properties* properties = | 320 bluez::BluetoothDeviceClient::Properties* properties = |
321 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( | 321 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
322 object_path_); | 322 object_path_); |
323 DCHECK(properties); | 323 DCHECK(properties); |
324 | 324 |
325 if (!properties->tx_power.is_valid()) | 325 if (!properties->tx_power.is_valid()) |
326 return kUnknownPower; | 326 return kUnknownPower; |
327 | 327 |
328 return properties->tx_power.value(); | 328 return properties->tx_power.value(); |
329 } | 329 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 391 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
392 } | 392 } |
393 | 393 |
394 void BluetoothDeviceBlueZ::SetPinCode(const std::string& pincode) { | 394 void BluetoothDeviceBlueZ::SetPinCode(const std::string& pincode) { |
395 if (!pairing_.get()) | 395 if (!pairing_.get()) |
396 return; | 396 return; |
397 | 397 |
398 pairing_->SetPinCode(pincode); | 398 pairing_->SetPinCode(pincode); |
399 } | 399 } |
400 | 400 |
401 void BluetoothDeviceBlueZ::SetPasskey(uint32 passkey) { | 401 void BluetoothDeviceBlueZ::SetPasskey(uint32_t passkey) { |
402 if (!pairing_.get()) | 402 if (!pairing_.get()) |
403 return; | 403 return; |
404 | 404 |
405 pairing_->SetPasskey(passkey); | 405 pairing_->SetPasskey(passkey); |
406 } | 406 } |
407 | 407 |
408 void BluetoothDeviceBlueZ::ConfirmPairing() { | 408 void BluetoothDeviceBlueZ::ConfirmPairing() { |
409 if (!pairing_.get()) | 409 if (!pairing_.get()) |
410 return; | 410 return; |
411 | 411 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 | 576 |
577 DCHECK(service->object_path() == object_path); | 577 DCHECK(service->object_path() == object_path); |
578 scoped_ptr<BluetoothGattService> scoped_service = | 578 scoped_ptr<BluetoothGattService> scoped_service = |
579 gatt_services_.take_and_erase(iter->first); | 579 gatt_services_.take_and_erase(iter->first); |
580 | 580 |
581 DCHECK(adapter_); | 581 DCHECK(adapter_); |
582 adapter()->NotifyGattServiceRemoved(service); | 582 adapter()->NotifyGattServiceRemoved(service); |
583 } | 583 } |
584 | 584 |
585 void BluetoothDeviceBlueZ::OnGetConnInfo(const ConnectionInfoCallback& callback, | 585 void BluetoothDeviceBlueZ::OnGetConnInfo(const ConnectionInfoCallback& callback, |
586 int16 rssi, | 586 int16_t rssi, |
587 int16 transmit_power, | 587 int16_t transmit_power, |
588 int16 max_transmit_power) { | 588 int16_t max_transmit_power) { |
589 callback.Run(ConnectionInfo(rssi, transmit_power, max_transmit_power)); | 589 callback.Run(ConnectionInfo(rssi, transmit_power, max_transmit_power)); |
590 } | 590 } |
591 | 591 |
592 void BluetoothDeviceBlueZ::OnGetConnInfoError( | 592 void BluetoothDeviceBlueZ::OnGetConnInfoError( |
593 const ConnectionInfoCallback& callback, | 593 const ConnectionInfoCallback& callback, |
594 const std::string& error_name, | 594 const std::string& error_name, |
595 const std::string& error_message) { | 595 const std::string& error_message) { |
596 LOG(WARNING) << object_path_.value() | 596 LOG(WARNING) << object_path_.value() |
597 << ": Failed to get connection info: " << error_name << ": " | 597 << ": Failed to get connection info: " << error_name << ": " |
598 << error_message; | 598 << error_message; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 void BluetoothDeviceBlueZ::OnForgetError(const ErrorCallback& error_callback, | 764 void BluetoothDeviceBlueZ::OnForgetError(const ErrorCallback& error_callback, |
765 const std::string& error_name, | 765 const std::string& error_name, |
766 const std::string& error_message) { | 766 const std::string& error_message) { |
767 LOG(WARNING) << object_path_.value() | 767 LOG(WARNING) << object_path_.value() |
768 << ": Failed to remove device: " << error_name << ": " | 768 << ": Failed to remove device: " << error_name << ": " |
769 << error_message; | 769 << error_message; |
770 error_callback.Run(); | 770 error_callback.Run(); |
771 } | 771 } |
772 | 772 |
773 } // namespace bluez | 773 } // namespace bluez |
OLD | NEW |