Chromium Code Reviews| Index: components/arc/bluetooth/arc_bluetooth_bridge.cc |
| diff --git a/components/arc/bluetooth/arc_bluetooth_bridge.cc b/components/arc/bluetooth/arc_bluetooth_bridge.cc |
| index 5ba17cc2dcdd91aee6c212d06c266d3a27e92605..62a2abf34a81b1ee869cd05abe1fa6c648a66134 100644 |
| --- a/components/arc/bluetooth/arc_bluetooth_bridge.cc |
| +++ b/components/arc/bluetooth/arc_bluetooth_bridge.cc |
| @@ -27,6 +27,7 @@ |
| #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" |
| #include "device/bluetooth/bluetooth_remote_gatt_descriptor.h" |
| #include "device/bluetooth/bluetooth_remote_gatt_service.h" |
| +#include "device/bluetooth/bluez/bluetooth_device_bluez.h" |
| using device::BluetoothAdapter; |
| using device::BluetoothAdapterFactory; |
| @@ -963,6 +964,91 @@ void ArcBluetoothBridge::OnGattNotifyStopDone( |
| callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS); |
| } |
| +void ArcBluetoothBridge::OnGetServiceRecordsDone( |
|
Luis Héctor Chávez
2016/07/14 23:13:14
This function doesn't seem to need any members fro
Miao
2016/07/15 08:39:21
Done.
|
| + const GetSdpRecordsCallback& callback, |
| + const std::vector<bluez::BluetoothServiceRecordBlueZ>& records) const { |
| + arc::mojom::BluetoothGetSdpRecordsResultPtr result = |
| + arc::mojom::BluetoothGetSdpRecordsResult::New(); |
| + |
| + result->status = mojom::BluetoothStatus::SUCCESS; |
| + |
| + if (records.empty()) { |
| + callback.Run(std::move(result)); |
| + return; |
| + } |
|
puthik_chromium
2016/07/14 01:32:34
Remove line 975-978?
This codes does not change an
Miao
2016/07/15 08:39:21
Done.
|
| + |
| + for (auto& rcd : records) |
|
Luis Héctor Chávez
2016/07/14 23:13:14
braces are required if the only statement is line-
Miao
2016/07/15 08:39:21
Done.
|
| + result->records.push_back( |
| + std::move(mojo::ConvertTo<arc::mojom::BluetoothSdpRecordPtr>(rcd))); |
| + |
| + callback.Run(std::move(result)); |
| +} |
| + |
| +void ArcBluetoothBridge::OnGetServiceRecordsError( |
| + const GetSdpRecordsCallback& callback, |
| + bluez::BluetoothServiceRecordBlueZ::ErrorCode error_code) const { |
| + arc::mojom::BluetoothGetSdpRecordsResultPtr result = |
| + arc::mojom::BluetoothGetSdpRecordsResult::New(); |
| + |
| + switch(error_code) { |
| + case bluez::BluetoothServiceRecordBlueZ::ErrorCode::ERROR_ADAPTER_NOT_READY: |
| + result->status = mojom::BluetoothStatus::NOT_READY; |
| + break; |
| + case bluez::BluetoothServiceRecordBlueZ::ErrorCode:: |
| + ERROR_DEVICE_DISCONNECTED: |
| + result->status = mojom::BluetoothStatus::RMT_DEV_DOWN; |
| + break; |
| + default: |
| + result->status = mojom::BluetoothStatus::FAIL; |
| + break; |
| + } |
| + |
| + callback.Run(std::move(result)); |
| +} |
| + |
| +void ArcBluetoothBridge::OnCreateSdpRecordDone( |
| + const CreateSdpRecordCallback& callback, |
| + uint32_t service_handle) const { |
| + arc::mojom::BluetoothCreateSdpRecordResultPtr result = |
| + arc::mojom::BluetoothCreateSdpRecordResult::New(); |
| + result->status = mojom::BluetoothStatus::SUCCESS; |
| + result->service_handle = service_handle; |
| + |
| + callback.Run(std::move(result)); |
| +} |
| + |
| +void ArcBluetoothBridge::OnCreateSdpRecordError( |
| + const CreateSdpRecordCallback& callback, |
| + bluez::BluetoothServiceRecordBlueZ::ErrorCode error_code) const { |
| + arc::mojom::BluetoothCreateSdpRecordResultPtr result = |
| + arc::mojom::BluetoothCreateSdpRecordResult::New(); |
| + if (error_code == |
| + bluez::BluetoothServiceRecordBlueZ::ErrorCode::ERROR_ADAPTER_NOT_READY) |
| + result->status = mojom::BluetoothStatus::NOT_READY; |
| + else |
| + result->status = mojom::BluetoothStatus::FAIL; |
| + |
| + callback.Run(std::move(result)); |
| +} |
| + |
| +void ArcBluetoothBridge::OnRemoveSdpRecordDone( |
| + const RemoveSdpRecordCallback& callback) const { |
| + callback.Run(mojom::BluetoothStatus::SUCCESS); |
| +} |
| + |
| +void ArcBluetoothBridge::OnRemoveSdpRecordError( |
| + const RemoveSdpRecordCallback& callback, |
| + bluez::BluetoothServiceRecordBlueZ::ErrorCode error_code) const { |
| + arc::mojom::BluetoothStatus status; |
| + if (error_code == |
| + bluez::BluetoothServiceRecordBlueZ::ErrorCode::ERROR_ADAPTER_NOT_READY) |
| + status = mojom::BluetoothStatus::NOT_READY; |
| + else |
| + status = mojom::BluetoothStatus::FAIL; |
| + |
| + callback.Run(status); |
| +} |
| + |
| void ArcBluetoothBridge::RegisterForGattNotification( |
| mojom::BluetoothAddressPtr remote_addr, |
| mojom::BluetoothGattServiceIDPtr service_id, |
| @@ -1024,6 +1110,67 @@ void ArcBluetoothBridge::ReadRemoteRssi( |
| callback.Run(rssi); |
| } |
| +void ArcBluetoothBridge::GetSdpRecords( |
| + arc::mojom::BluetoothAddressPtr remote_addr, |
| + const GetSdpRecordsCallback& callback) { |
| + BluetoothDevice* device = |
| + bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); |
| + |
| + // Do an early return if there is no device with |remote_addr|. |
| + if (!device) { |
| + arc::mojom::BluetoothGetSdpRecordsResultPtr result = |
| + arc::mojom::BluetoothGetSdpRecordsResult::New(); |
| + result->status = arc::mojom::BluetoothStatus::SUCCESS; |
|
puthik_chromium
2016/07/14 01:32:34
Why success if there is no device?
Miao
2016/07/15 08:39:21
This should be FAIL instead.
|
| + callback.Run(std::move(result)); |
| + return; |
| + } |
| + |
| + bluez::BluetoothDeviceBlueZ* device_bluez = |
| + static_cast<bluez::BluetoothDeviceBlueZ*>(device); |
| + |
| + device_bluez->GetServiceRecords( |
| + base::Bind(&ArcBluetoothBridge::OnGetServiceRecordsDone, |
| + weak_factory_.GetWeakPtr(), callback), |
| + base::Bind(&ArcBluetoothBridge::OnGetServiceRecordsError, |
| + weak_factory_.GetWeakPtr(), callback)); |
| +} |
| + |
| +void ArcBluetoothBridge::CreateSdpRecord( |
| + arc::mojom::BluetoothSdpRecordPtr record, |
| + const CreateSdpRecordCallback& callback) { |
| + bluez::BluetoothServiceRecordBlueZ rcd_bluez( |
| + mojo::ConvertTo<bluez::BluetoothServiceRecordBlueZ>(record)); |
| + |
| + std::vector<uint16_t> v = rcd_bluez.GetAttributeIds(); |
| + std::set<uint16_t> ids (v.begin(), v.end()); |
|
puthik_chromium
2016/07/14 01:32:34
Why do we need both vector and set?
Luis Héctor Chávez
2016/07/14 23:13:14
Prefer std::unordered_set if you are searching for
Miao
2016/07/15 08:39:21
Removed set and find the element in the vector ins
|
| + |
| + // Check if ServiceClassIDList attribute (attribute ID 0x0001) is included |
| + // after type conversion, since it is mandatory for creating a service record. |
| + if (ids.find(0x0001) == ids.end()) { |
|
puthik_chromium
2016/07/14 01:32:34
Add constexpr in anonymouse namespace above for 0x
Miao
2016/07/15 08:39:21
Done.
|
| + arc::mojom::BluetoothCreateSdpRecordResultPtr result = |
| + mojom::BluetoothCreateSdpRecordResult::New(); |
| + result->status = arc::mojom::BluetoothStatus::FAIL; |
| + callback.Run(std::move(result)); |
| + return; |
| + } |
| + |
| + bluetooth_adapter_->CreateServiceRecord( |
| + rcd_bluez, base::Bind(&ArcBluetoothBridge::OnCreateSdpRecordDone, |
| + weak_factory_.GetWeakPtr(), callback), |
| + base::Bind(&ArcBluetoothBridge::OnCreateSdpRecordError, |
| + weak_factory_.GetWeakPtr(), callback)); |
| +} |
| + |
| +void ArcBluetoothBridge::RemoveSdpRecord( |
| + uint32_t service_handle, |
| + const RemoveSdpRecordCallback& callback) { |
| + bluetooth_adapter_->RemoveServiceRecord( |
| + service_handle, base::Bind(&ArcBluetoothBridge::OnRemoveSdpRecordDone, |
| + weak_factory_.GetWeakPtr(), callback), |
| + base::Bind(&ArcBluetoothBridge::OnRemoveSdpRecordError, |
| + weak_factory_.GetWeakPtr(), callback)); |
| +} |
| + |
| void ArcBluetoothBridge::OnDiscoveryError() { |
| LOG(WARNING) << "failed to change discovery state"; |
| } |