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

Side by Side Diff: components/arc/bluetooth/arc_bluetooth_bridge.cc

Issue 2228953003: bluetooth: Change GetInquiryTxPower and GetInquiryRSSI to return optional. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: TIL value_or Created 4 years, 4 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
« no previous file with comments | « no previous file | components/arc/common/bluetooth.mojom » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/arc/bluetooth/arc_bluetooth_bridge.h" 5 #include "components/arc/bluetooth/arc_bluetooth_bridge.h"
6 6
7 #include <bluetooth/bluetooth.h> 7 #include <bluetooth/bluetooth.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <sys/socket.h> 10 #include <sys/socket.h>
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); 242 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device);
243 243
244 arc_bridge_service()->bluetooth()->instance()->OnDeviceFound( 244 arc_bridge_service()->bluetooth()->instance()->OnDeviceFound(
245 std::move(properties)); 245 std::move(properties));
246 246
247 if (!CheckBluetoothInstanceVersion(kMinBtleVersion)) 247 if (!CheckBluetoothInstanceVersion(kMinBtleVersion))
248 return; 248 return;
249 249
250 mojom::BluetoothAddressPtr addr = 250 mojom::BluetoothAddressPtr addr =
251 mojom::BluetoothAddress::From(device->GetAddress()); 251 mojom::BluetoothAddress::From(device->GetAddress());
252 int rssi = device->GetInquiryRSSI(); 252 base::Optional<int8_t> rssi = device->GetInquiryRSSI();
253 mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = 253 mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data =
254 GetAdvertisingData(device); 254 GetAdvertisingData(device);
255 arc_bridge_service()->bluetooth()->instance()->OnLEDeviceFound( 255 arc_bridge_service()->bluetooth()->instance()->OnLEDeviceFound(
256 std::move(addr), rssi, std::move(adv_data)); 256 std::move(addr), rssi.value_or(mojom::kUnknownPower),
257 std::move(adv_data));
257 } 258 }
258 259
259 void ArcBluetoothBridge::DeviceChanged(BluetoothAdapter* adapter, 260 void ArcBluetoothBridge::DeviceChanged(BluetoothAdapter* adapter,
260 BluetoothDevice* device) { 261 BluetoothDevice* device) {
261 // TODO(smbarber): device properties changed; inform the container. 262 // TODO(smbarber): device properties changed; inform the container.
262 } 263 }
263 264
264 void ArcBluetoothBridge::DeviceAddressChanged(BluetoothAdapter* adapter, 265 void ArcBluetoothBridge::DeviceAddressChanged(BluetoothAdapter* adapter,
265 BluetoothDevice* device, 266 BluetoothDevice* device,
266 const std::string& old_address) { 267 const std::string& old_address) {
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 std::move(notification_session_[char_id_str]); 1127 std::move(notification_session_[char_id_str]);
1127 notification_session_.erase(char_id_str); 1128 notification_session_.erase(char_id_str);
1128 notify->Stop(base::Bind(&OnGattOperationDone, callback)); 1129 notify->Stop(base::Bind(&OnGattOperationDone, callback));
1129 } 1130 }
1130 1131
1131 void ArcBluetoothBridge::ReadRemoteRssi( 1132 void ArcBluetoothBridge::ReadRemoteRssi(
1132 mojom::BluetoothAddressPtr remote_addr, 1133 mojom::BluetoothAddressPtr remote_addr,
1133 const ReadRemoteRssiCallback& callback) { 1134 const ReadRemoteRssiCallback& callback) {
1134 BluetoothDevice* device = 1135 BluetoothDevice* device =
1135 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); 1136 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>());
1136 int rssi = device->GetInquiryRSSI(); 1137 base::Optional<int8_t> rssi = device->GetInquiryRSSI();
1137 callback.Run(rssi); 1138 callback.Run(rssi.value_or(mojom::kUnknownPower));
1138 } 1139 }
1139 1140
1140 void ArcBluetoothBridge::OpenBluetoothSocket( 1141 void ArcBluetoothBridge::OpenBluetoothSocket(
1141 const OpenBluetoothSocketCallback& callback) { 1142 const OpenBluetoothSocketCallback& callback) {
1142 base::ScopedFD sock(socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)); 1143 base::ScopedFD sock(socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM));
1143 if (!sock.is_valid()) { 1144 if (!sock.is_valid()) {
1144 LOG(ERROR) << "Failed to open socket."; 1145 LOG(ERROR) << "Failed to open socket.";
1145 callback.Run(mojo::ScopedHandle()); 1146 callback.Run(mojo::ScopedHandle());
1146 return; 1147 return;
1147 } 1148 }
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1413 if (type == mojom::BluetoothPropertyType::ALL || 1414 if (type == mojom::BluetoothPropertyType::ALL ||
1414 type == mojom::BluetoothPropertyType::REMOTE_FRIENDLY_NAME) { 1415 type == mojom::BluetoothPropertyType::REMOTE_FRIENDLY_NAME) {
1415 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); 1416 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New();
1416 btp->set_remote_friendly_name( 1417 btp->set_remote_friendly_name(
1417 mojo::String::From(base::UTF16ToUTF8(device->GetNameForDisplay()))); 1418 mojo::String::From(base::UTF16ToUTF8(device->GetNameForDisplay())));
1418 properties.push_back(std::move(btp)); 1419 properties.push_back(std::move(btp));
1419 } 1420 }
1420 if (type == mojom::BluetoothPropertyType::ALL || 1421 if (type == mojom::BluetoothPropertyType::ALL ||
1421 type == mojom::BluetoothPropertyType::REMOTE_RSSI) { 1422 type == mojom::BluetoothPropertyType::REMOTE_RSSI) {
1422 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New(); 1423 mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New();
1423 btp->set_remote_rssi(device->GetInquiryRSSI()); 1424 base::Optional<int8_t> rssi = device->GetInquiryRSSI();
1425 btp->set_remote_rssi(rssi.value_or(mojom::kUnknownPower));
1424 properties.push_back(std::move(btp)); 1426 properties.push_back(std::move(btp));
1425 } 1427 }
1426 // TODO(smbarber): Add remote version info 1428 // TODO(smbarber): Add remote version info
1427 1429
1428 return properties; 1430 return properties;
1429 } 1431 }
1430 1432
1431 mojo::Array<mojom::BluetoothPropertyPtr> 1433 mojo::Array<mojom::BluetoothPropertyPtr>
1432 ArcBluetoothBridge::GetAdapterProperties( 1434 ArcBluetoothBridge::GetAdapterProperties(
1433 mojom::BluetoothPropertyType type) const { 1435 mojom::BluetoothPropertyType type) const {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1570 1572
1571 mojo::Array<mojom::BluetoothPropertyPtr> properties = 1573 mojo::Array<mojom::BluetoothPropertyPtr> properties =
1572 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); 1574 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device);
1573 1575
1574 arc_bridge_service()->bluetooth()->instance()->OnDeviceFound( 1576 arc_bridge_service()->bluetooth()->instance()->OnDeviceFound(
1575 std::move(properties)); 1577 std::move(properties));
1576 1578
1577 if (arc_bridge_service()->bluetooth()->version() >= kMinBtleVersion) { 1579 if (arc_bridge_service()->bluetooth()->version() >= kMinBtleVersion) {
1578 mojom::BluetoothAddressPtr addr = 1580 mojom::BluetoothAddressPtr addr =
1579 mojom::BluetoothAddress::From(device->GetAddress()); 1581 mojom::BluetoothAddress::From(device->GetAddress());
1580 int rssi = device->GetInquiryRSSI(); 1582 base::Optional<int8_t> rssi = device->GetInquiryRSSI();
1581 mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = 1583 mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data =
1582 GetAdvertisingData(device); 1584 GetAdvertisingData(device);
1583 arc_bridge_service()->bluetooth()->instance()->OnLEDeviceFound( 1585 arc_bridge_service()->bluetooth()->instance()->OnLEDeviceFound(
1584 std::move(addr), rssi, std::move(adv_data)); 1586 std::move(addr), rssi.value_or(mojom::kUnknownPower),
1587 std::move(adv_data));
1585 } 1588 }
1586 } 1589 }
1587 } 1590 }
1588 1591
1589 bool ArcBluetoothBridge::HasBluetoothInstance() const { 1592 bool ArcBluetoothBridge::HasBluetoothInstance() const {
1590 if (!arc_bridge_service()->bluetooth()->instance()) { 1593 if (!arc_bridge_service()->bluetooth()->instance()) {
1591 LOG(WARNING) << "no Bluetooth instance available"; 1594 LOG(WARNING) << "no Bluetooth instance available";
1592 return false; 1595 return false;
1593 } 1596 }
1594 1597
(...skipping 13 matching lines...) Expand all
1608 mojo::Array<mojom::BluetoothPropertyPtr> properties = 1611 mojo::Array<mojom::BluetoothPropertyPtr> properties =
1609 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); 1612 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device);
1610 1613
1611 arc_bridge_service()->bluetooth()->instance()->OnDeviceFound( 1614 arc_bridge_service()->bluetooth()->instance()->OnDeviceFound(
1612 std::move(properties)); 1615 std::move(properties));
1613 1616
1614 mojom::BluetoothAddressPtr addr = 1617 mojom::BluetoothAddressPtr addr =
1615 mojom::BluetoothAddress::From(device->GetAddress()); 1618 mojom::BluetoothAddress::From(device->GetAddress());
1616 1619
1617 if (arc_bridge_service()->bluetooth()->version() >= kMinBtleVersion) { 1620 if (arc_bridge_service()->bluetooth()->version() >= kMinBtleVersion) {
1618 int rssi = device->GetInquiryRSSI(); 1621 base::Optional<int8_t> rssi = device->GetInquiryRSSI();
1619 mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = 1622 mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data =
1620 GetAdvertisingData(device); 1623 GetAdvertisingData(device);
1621 arc_bridge_service()->bluetooth()->instance()->OnLEDeviceFound( 1624 arc_bridge_service()->bluetooth()->instance()->OnLEDeviceFound(
1622 addr->Clone(), rssi, std::move(adv_data)); 1625 addr->Clone(), rssi.value_or(mojom::kUnknownPower),
1626 std::move(adv_data));
1623 } 1627 }
1624 1628
1625 // OnBondStateChanged must be called with mojom::BluetoothBondState::BONDING 1629 // OnBondStateChanged must be called with mojom::BluetoothBondState::BONDING
1626 // to 1630 // to
1627 // make sure the bond state machine on Android is ready to take the 1631 // make sure the bond state machine on Android is ready to take the
1628 // pair-done event. Otherwise the pair-done event will be dropped as an 1632 // pair-done event. Otherwise the pair-done event will be dropped as an
1629 // invalid change of paired status. 1633 // invalid change of paired status.
1630 OnPairing(addr->Clone()); 1634 OnPairing(addr->Clone());
1631 OnPairedDone(std::move(addr)); 1635 OnPairedDone(std::move(addr));
1632 } 1636 }
1633 } 1637 }
1634 1638
1635 bool ArcBluetoothBridge::CheckBluetoothInstanceVersion( 1639 bool ArcBluetoothBridge::CheckBluetoothInstanceVersion(
1636 uint32_t version_need) const { 1640 uint32_t version_need) const {
1637 uint32_t version = arc_bridge_service()->bluetooth()->version(); 1641 uint32_t version = arc_bridge_service()->bluetooth()->version();
1638 if (version >= version_need) 1642 if (version >= version_need)
1639 return true; 1643 return true;
1640 LOG(WARNING) << "Bluetooth instance is too old (version " << version 1644 LOG(WARNING) << "Bluetooth instance is too old (version " << version
1641 << ") need version " << version_need; 1645 << ") need version " << version_need;
1642 return false; 1646 return false;
1643 } 1647 }
1644 1648
1645 bool ArcBluetoothBridge::CalledOnValidThread() { 1649 bool ArcBluetoothBridge::CalledOnValidThread() {
1646 return thread_checker_.CalledOnValidThread(); 1650 return thread_checker_.CalledOnValidThread();
1647 } 1651 }
1648 1652
1649 } // namespace arc 1653 } // namespace arc
OLDNEW
« no previous file with comments | « no previous file | components/arc/common/bluetooth.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698