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

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

Powered by Google App Engine
This is Rietveld 408576698