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

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

Issue 2104023002: arc: bluetooth: Add Gatt server mojo API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 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 <fcntl.h> 7 #include <fcntl.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <iomanip> 10 #include <iomanip>
11 #include <string> 11 #include <string>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/posix/eintr_wrapper.h" 15 #include "base/posix/eintr_wrapper.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "base/threading/thread_task_runner_handle.h" 18 #include "base/threading/thread_task_runner_handle.h"
19 #include "base/time/time.h" 19 #include "base/time/time.h"
20 #include "components/arc/arc_bridge_service.h" 20 #include "components/arc/arc_bridge_service.h"
21 #include "components/arc/bluetooth/bluetooth_type_converters.h" 21 #include "components/arc/bluetooth/bluetooth_type_converters.h"
22 #include "device/bluetooth/bluetooth_adapter_factory.h" 22 #include "device/bluetooth/bluetooth_adapter_factory.h"
23 #include "device/bluetooth/bluetooth_common.h" 23 #include "device/bluetooth/bluetooth_common.h"
24 #include "device/bluetooth/bluetooth_device.h" 24 #include "device/bluetooth/bluetooth_device.h"
25 #include "device/bluetooth/bluetooth_gatt_connection.h" 25 #include "device/bluetooth/bluetooth_gatt_connection.h"
26 #include "device/bluetooth/bluetooth_gatt_notify_session.h" 26 #include "device/bluetooth/bluetooth_gatt_notify_session.h"
27 #include "device/bluetooth/bluetooth_local_gatt_characteristic.h"
28 #include "device/bluetooth/bluetooth_local_gatt_descriptor.h"
29 #include "device/bluetooth/bluetooth_local_gatt_service.h"
27 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" 30 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
28 #include "device/bluetooth/bluetooth_remote_gatt_descriptor.h" 31 #include "device/bluetooth/bluetooth_remote_gatt_descriptor.h"
29 #include "device/bluetooth/bluetooth_remote_gatt_service.h" 32 #include "device/bluetooth/bluetooth_remote_gatt_service.h"
30 33
31 using device::BluetoothAdapter; 34 using device::BluetoothAdapter;
32 using device::BluetoothAdapterFactory; 35 using device::BluetoothAdapterFactory;
33 using device::BluetoothAdvertisement; 36 using device::BluetoothAdvertisement;
34 using device::BluetoothDevice; 37 using device::BluetoothDevice;
35 using device::BluetoothDiscoveryFilter; 38 using device::BluetoothDiscoveryFilter;
36 using device::BluetoothDiscoverySession; 39 using device::BluetoothDiscoverySession;
37 using device::BluetoothGattConnection; 40 using device::BluetoothGattConnection;
38 using device::BluetoothGattNotifySession; 41 using device::BluetoothGattNotifySession;
39 using device::BluetoothGattCharacteristic; 42 using device::BluetoothGattCharacteristic;
40 using device::BluetoothGattDescriptor; 43 using device::BluetoothGattDescriptor;
41 using device::BluetoothGattService; 44 using device::BluetoothGattService;
45 using device::BluetoothLocalGattCharacteristic;
46 using device::BluetoothLocalGattDescriptor;
47 using device::BluetoothLocalGattService;
42 using device::BluetoothRemoteGattCharacteristic; 48 using device::BluetoothRemoteGattCharacteristic;
43 using device::BluetoothRemoteGattDescriptor; 49 using device::BluetoothRemoteGattDescriptor;
44 using device::BluetoothRemoteGattService; 50 using device::BluetoothRemoteGattService;
45 using device::BluetoothUUID; 51 using device::BluetoothUUID;
46 52
47 namespace { 53 namespace {
48 constexpr int32_t kMinBtleVersion = 1; 54 constexpr int32_t kMinBtleVersion = 1;
49 constexpr int32_t kMinBtleNotifyVersion = 2; 55 constexpr int32_t kMinBtleNotifyVersion = 2;
50 constexpr uint32_t kGattReadPermission = 56 constexpr uint32_t kGattReadPermission =
51 BluetoothGattCharacteristic::Permission::PERMISSION_READ | 57 BluetoothGattCharacteristic::Permission::PERMISSION_READ |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 true /* is_notify */, mojo::Array<uint8_t>::From(value)); 289 true /* is_notify */, mojo::Array<uint8_t>::From(value));
284 } 290 }
285 291
286 void ArcBluetoothBridge::GattDescriptorValueChanged( 292 void ArcBluetoothBridge::GattDescriptorValueChanged(
287 BluetoothAdapter* adapter, 293 BluetoothAdapter* adapter,
288 BluetoothRemoteGattDescriptor* descriptor, 294 BluetoothRemoteGattDescriptor* descriptor,
289 const std::vector<uint8_t>& value) { 295 const std::vector<uint8_t>& value) {
290 // Placeholder for GATT client functionality 296 // Placeholder for GATT client functionality
291 } 297 }
292 298
299 void ArcBluetoothBridge::OnCharacteristicReadRequest(
300 const BluetoothDevice* device,
301 const BluetoothLocalGattCharacteristic* characteristic,
302 int offset,
303 const ValueCallback& callback,
304 const ErrorCallback& error_callback) {}
305
306 void ArcBluetoothBridge::OnCharacteristicWriteRequest(
307 const BluetoothDevice* device,
308 const BluetoothLocalGattCharacteristic* characteristic,
309 const std::vector<uint8_t>& value,
310 int offset,
311 const base::Closure& callback,
312 const ErrorCallback& error_callback) {}
313
314 void ArcBluetoothBridge::OnDescriptorReadRequest(
315 const BluetoothDevice* device,
316 const BluetoothLocalGattDescriptor* descriptor,
317 int offset,
318 const ValueCallback& callback,
319 const ErrorCallback& error_callback) {}
320
321 void ArcBluetoothBridge::OnDescriptorWriteRequest(
322 const BluetoothDevice* device,
323 const BluetoothLocalGattDescriptor* descriptor,
324 const std::vector<uint8_t>& value,
325 int offset,
326 const base::Closure& callback,
327 const ErrorCallback& error_callback) {}
328
329 void ArcBluetoothBridge::OnNotificationsStart(
330 const BluetoothDevice* device,
331 const BluetoothLocalGattCharacteristic* characteristic) {}
332
333 void ArcBluetoothBridge::OnNotificationsStop(
334 const BluetoothDevice* device,
335 const BluetoothLocalGattCharacteristic* characteristic) {}
336
293 void ArcBluetoothBridge::EnableAdapter(const EnableAdapterCallback& callback) { 337 void ArcBluetoothBridge::EnableAdapter(const EnableAdapterCallback& callback) {
294 DCHECK(bluetooth_adapter_); 338 DCHECK(bluetooth_adapter_);
295 if (!bluetooth_adapter_->IsPowered()) { 339 if (!bluetooth_adapter_->IsPowered()) {
296 bluetooth_adapter_->SetPowered( 340 bluetooth_adapter_->SetPowered(
297 true, base::Bind(&ArcBluetoothBridge::OnPoweredOn, 341 true, base::Bind(&ArcBluetoothBridge::OnPoweredOn,
298 weak_factory_.GetWeakPtr(), callback), 342 weak_factory_.GetWeakPtr(), callback),
299 base::Bind(&ArcBluetoothBridge::OnPoweredError, 343 base::Bind(&ArcBluetoothBridge::OnPoweredError,
300 weak_factory_.GetWeakPtr(), callback)); 344 weak_factory_.GetWeakPtr(), callback));
301 return; 345 return;
302 } 346 }
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 1061
1018 void ArcBluetoothBridge::ReadRemoteRssi( 1062 void ArcBluetoothBridge::ReadRemoteRssi(
1019 mojom::BluetoothAddressPtr remote_addr, 1063 mojom::BluetoothAddressPtr remote_addr,
1020 const ReadRemoteRssiCallback& callback) { 1064 const ReadRemoteRssiCallback& callback) {
1021 BluetoothDevice* device = 1065 BluetoothDevice* device =
1022 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); 1066 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>());
1023 int rssi = device->GetInquiryRSSI(); 1067 int rssi = device->GetInquiryRSSI();
1024 callback.Run(rssi); 1068 callback.Run(rssi);
1025 } 1069 }
1026 1070
1071 void ArcBluetoothBridge::AddService(mojom::BluetoothGattServiceIDPtr service_id,
1072 int32_t num_handles,
1073 const AddServiceCallback& callback) {}
1074
1075 void ArcBluetoothBridge::AddCharacteristic(
1076 int32_t service_handle,
1077 mojom::BluetoothUUIDPtr uuid,
1078 int32_t properties,
1079 int32_t permissions,
1080 const AddCharacteristicCallback& callback) {}
1081
1082 void ArcBluetoothBridge::AddDescriptor(int32_t service_handle,
1083 mojom::BluetoothUUIDPtr uuid,
1084 int32_t permissions,
1085 const AddDescriptorCallback& callback) {}
1086
1087 void ArcBluetoothBridge::StartService(int32_t service_handle,
1088 int32_t transport,
1089 const StartServiceCallback& callback) {}
1090
1091 void ArcBluetoothBridge::StopService(int32_t service_handle,
1092 const StopServiceCallback& callback) {}
1093
1094 void ArcBluetoothBridge::DeleteService(int32_t service_handle,
1095 const DeleteServiceCallback& callback) {}
1096
1097 void ArcBluetoothBridge::SendIndication(
1098 int32_t attribute_handle,
1099 mojom::BluetoothAddressPtr address,
1100 int32_t confirm,
1101 mojo::Array<uint8_t> value,
1102 const SendIndicationCallback& callback) {}
1103
1104 void ArcBluetoothBridge::SendResponse(int32_t trans_id,
1105 int32_t status,
1106 mojo::Array<uint8_t> value,
1107 const SendResponseCallback& callback) {}
1108
1027 void ArcBluetoothBridge::OnDiscoveryError() { 1109 void ArcBluetoothBridge::OnDiscoveryError() {
1028 LOG(WARNING) << "failed to change discovery state"; 1110 LOG(WARNING) << "failed to change discovery state";
1029 } 1111 }
1030 1112
1031 void ArcBluetoothBridge::OnPairing(mojom::BluetoothAddressPtr addr) const { 1113 void ArcBluetoothBridge::OnPairing(mojom::BluetoothAddressPtr addr) const {
1032 if (!HasBluetoothInstance()) 1114 if (!HasBluetoothInstance())
1033 return; 1115 return;
1034 1116
1035 arc_bridge_service()->bluetooth_instance()->OnBondStateChanged( 1117 arc_bridge_service()->bluetooth_instance()->OnBondStateChanged(
1036 mojom::BluetoothStatus::SUCCESS, std::move(addr), 1118 mojom::BluetoothStatus::SUCCESS, std::move(addr),
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 int32_t version_need) const { 1437 int32_t version_need) const {
1356 int32_t version = arc_bridge_service()->bluetooth_version(); 1438 int32_t version = arc_bridge_service()->bluetooth_version();
1357 if (version >= version_need) 1439 if (version >= version_need)
1358 return true; 1440 return true;
1359 LOG(WARNING) << "Bluetooth instance is too old (version " << version 1441 LOG(WARNING) << "Bluetooth instance is too old (version " << version
1360 << ") need version " << version_need; 1442 << ") need version " << version_need;
1361 return false; 1443 return false;
1362 } 1444 }
1363 1445
1364 } // namespace arc 1446 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698