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

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

Issue 2248913002: bluetooth: Implement RSSI and Tx Power on macOS and Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-refactor-adv-data
Patch Set: Clean up Created 4 years, 3 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
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.h" 5 #include "device/bluetooth/bluetooth_device.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 304
305 const std::vector<uint8_t>* BluetoothDevice::GetServiceDataForUUID( 305 const std::vector<uint8_t>* BluetoothDevice::GetServiceDataForUUID(
306 const BluetoothUUID& uuid) const { 306 const BluetoothUUID& uuid) const {
307 auto it = service_data_.find(uuid); 307 auto it = service_data_.find(uuid);
308 if (it != service_data_.end()) { 308 if (it != service_data_.end()) {
309 return &it->second; 309 return &it->second;
310 } 310 }
311 return nullptr; 311 return nullptr;
312 } 312 }
313 313
314 base::Optional<int8_t> BluetoothDevice::GetInquiryRSSI() const {
315 return inquiry_rssi_;
316 }
317
318 base::Optional<int8_t> BluetoothDevice::GetInquiryTxPower() const {
319 return inquiry_tx_power_;
320 }
321
314 void BluetoothDevice::CreateGattConnection( 322 void BluetoothDevice::CreateGattConnection(
315 const GattConnectionCallback& callback, 323 const GattConnectionCallback& callback,
316 const ConnectErrorCallback& error_callback) { 324 const ConnectErrorCallback& error_callback) {
317 create_gatt_connection_success_callbacks_.push_back(callback); 325 create_gatt_connection_success_callbacks_.push_back(callback);
318 create_gatt_connection_error_callbacks_.push_back(error_callback); 326 create_gatt_connection_error_callbacks_.push_back(error_callback);
319 327
320 if (IsGattConnected()) 328 if (IsGattConnected())
321 return DidConnectGatt(); 329 return DidConnectGatt();
322 330
323 CreateGattConnectionImpl(); 331 CreateGattConnectionImpl();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 382
375 canonicalized[i] = base::ToUpperASCII(canonicalized[i]); 383 canonicalized[i] = base::ToUpperASCII(canonicalized[i]);
376 } 384 }
377 } 385 }
378 386
379 return canonicalized; 387 return canonicalized;
380 } 388 }
381 389
382 std::string BluetoothDevice::GetIdentifier() const { return GetAddress(); } 390 std::string BluetoothDevice::GetIdentifier() const { return GetAddress(); }
383 391
384 void BluetoothDevice::UpdateAdvertisementData(UUIDList advertised_uuids, 392 void BluetoothDevice::UpdateAdvertisementData(int8_t rssi,
385 ServiceDataMap service_data) { 393 UUIDList advertised_uuids,
394 ServiceDataMap service_data,
395 const int8_t* tx_power) {
386 UpdateTimestamp(); 396 UpdateTimestamp();
397
398 inquiry_rssi_ = rssi;
399
387 device_uuids_.ReplaceAdvertisedUUIDs(std::move(advertised_uuids)); 400 device_uuids_.ReplaceAdvertisedUUIDs(std::move(advertised_uuids));
388 service_data_ = std::move(service_data); 401 service_data_ = std::move(service_data);
402
403 if (tx_power != nullptr) {
404 inquiry_tx_power_ = *tx_power;
405 } else {
406 inquiry_tx_power_ = base::nullopt;
407 }
389 } 408 }
390 409
391 void BluetoothDevice::ClearAdvertisementData() { 410 void BluetoothDevice::ClearAdvertisementData() {
411 inquiry_rssi_ = base::nullopt;
392 device_uuids_.ClearAdvertisedUUIDs(); 412 device_uuids_.ClearAdvertisedUUIDs();
393 service_data_.clear(); 413 service_data_.clear();
414 inquiry_tx_power_ = base::nullopt;
394 GetAdapter()->NotifyDeviceChanged(this); 415 GetAdapter()->NotifyDeviceChanged(this);
395 } 416 }
396 417
397 void BluetoothDevice::DidConnectGatt() { 418 void BluetoothDevice::DidConnectGatt() {
398 for (const auto& callback : create_gatt_connection_success_callbacks_) { 419 for (const auto& callback : create_gatt_connection_success_callbacks_) {
399 callback.Run( 420 callback.Run(
400 base::WrapUnique(new BluetoothGattConnection(adapter_, GetAddress()))); 421 base::WrapUnique(new BluetoothGattConnection(adapter_, GetAddress())));
401 } 422 }
402 create_gatt_connection_success_callbacks_.clear(); 423 create_gatt_connection_success_callbacks_.clear();
403 create_gatt_connection_error_callbacks_.clear(); 424 create_gatt_connection_error_callbacks_.clear();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 void BluetoothDevice::Pair(PairingDelegate* pairing_delegate, 471 void BluetoothDevice::Pair(PairingDelegate* pairing_delegate,
451 const base::Closure& callback, 472 const base::Closure& callback,
452 const ConnectErrorCallback& error_callback) { 473 const ConnectErrorCallback& error_callback) {
453 NOTREACHED(); 474 NOTREACHED();
454 } 475 }
455 476
456 void BluetoothDevice::UpdateTimestamp() { 477 void BluetoothDevice::UpdateTimestamp() {
457 last_update_time_ = base::Time::NowFromSystemTime(); 478 last_update_time_ = base::Time::NowFromSystemTime();
458 } 479 }
459 480
481 // static
482 int8_t BluetoothDevice::ClampPower(int power) {
483 if (power < INT8_MIN) {
Jeffrey Yasskin 2016/08/24 04:32:02 Do you want to let -128 through or restrict this t
ortuno 2016/08/24 21:29:09 I thought it would be weird if someone added -128
484 return INT8_MIN;
485 }
486 if (power > INT8_MAX) {
487 return INT8_MAX;
488 }
489 return static_cast<int8_t>(power);
490 }
491
460 } // namespace device 492 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698