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

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: fix patch#2 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"
rkc 2016/07/01 21:28:27 Nit: Already included in header.
puthik_chromium 2016/07/14 19:01:31 Done.
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;
51 using device::BluetoothTransport;
45 using device::BluetoothUUID; 52 using device::BluetoothUUID;
46 53
47 namespace { 54 namespace {
48 constexpr int32_t kMinBtleVersion = 1; 55 constexpr int32_t kMinBtleVersion = 1;
49 constexpr int32_t kMinBtleNotifyVersion = 2; 56 constexpr int32_t kMinBtleNotifyVersion = 2;
50 constexpr uint32_t kGattReadPermission = 57 constexpr uint32_t kGattReadPermission =
51 BluetoothGattCharacteristic::Permission::PERMISSION_READ | 58 BluetoothGattCharacteristic::Permission::PERMISSION_READ |
52 BluetoothGattCharacteristic::Permission::PERMISSION_READ_ENCRYPTED | 59 BluetoothGattCharacteristic::Permission::PERMISSION_READ_ENCRYPTED |
53 BluetoothGattCharacteristic::Permission:: 60 BluetoothGattCharacteristic::Permission::
54 PERMISSION_READ_ENCRYPTED_AUTHENTICATED; 61 PERMISSION_READ_ENCRYPTED_AUTHENTICATED;
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 true /* is_notify */, mojo::Array<uint8_t>::From(value)); 290 true /* is_notify */, mojo::Array<uint8_t>::From(value));
284 } 291 }
285 292
286 void ArcBluetoothBridge::GattDescriptorValueChanged( 293 void ArcBluetoothBridge::GattDescriptorValueChanged(
287 BluetoothAdapter* adapter, 294 BluetoothAdapter* adapter,
288 BluetoothRemoteGattDescriptor* descriptor, 295 BluetoothRemoteGattDescriptor* descriptor,
289 const std::vector<uint8_t>& value) { 296 const std::vector<uint8_t>& value) {
290 // Placeholder for GATT client functionality 297 // Placeholder for GATT client functionality
291 } 298 }
292 299
300 void ArcBluetoothBridge::OnCharacteristicReadRequest(
301 const BluetoothDevice* device,
302 const BluetoothLocalGattCharacteristic* characteristic,
303 int offset,
304 const ValueCallback& callback,
305 const ErrorCallback& error_callback) {}
306
307 void ArcBluetoothBridge::OnCharacteristicWriteRequest(
308 const BluetoothDevice* device,
309 const BluetoothLocalGattCharacteristic* characteristic,
310 const std::vector<uint8_t>& value,
311 int offset,
312 const base::Closure& callback,
313 const ErrorCallback& error_callback) {}
314
315 void ArcBluetoothBridge::OnDescriptorReadRequest(
316 const BluetoothDevice* device,
317 const BluetoothLocalGattDescriptor* descriptor,
318 int offset,
319 const ValueCallback& callback,
320 const ErrorCallback& error_callback) {}
321
322 void ArcBluetoothBridge::OnDescriptorWriteRequest(
323 const BluetoothDevice* device,
324 const BluetoothLocalGattDescriptor* descriptor,
325 const std::vector<uint8_t>& value,
326 int offset,
327 const base::Closure& callback,
328 const ErrorCallback& error_callback) {}
329
330 void ArcBluetoothBridge::OnNotificationsStart(
331 const BluetoothDevice* device,
332 const BluetoothLocalGattCharacteristic* characteristic) {}
333
334 void ArcBluetoothBridge::OnNotificationsStop(
335 const BluetoothDevice* device,
336 const BluetoothLocalGattCharacteristic* characteristic) {}
337
293 void ArcBluetoothBridge::EnableAdapter(const EnableAdapterCallback& callback) { 338 void ArcBluetoothBridge::EnableAdapter(const EnableAdapterCallback& callback) {
294 DCHECK(bluetooth_adapter_); 339 DCHECK(bluetooth_adapter_);
295 if (!bluetooth_adapter_->IsPowered()) { 340 if (!bluetooth_adapter_->IsPowered()) {
296 bluetooth_adapter_->SetPowered( 341 bluetooth_adapter_->SetPowered(
297 true, base::Bind(&ArcBluetoothBridge::OnPoweredOn, 342 true, base::Bind(&ArcBluetoothBridge::OnPoweredOn,
298 weak_factory_.GetWeakPtr(), callback), 343 weak_factory_.GetWeakPtr(), callback),
299 base::Bind(&ArcBluetoothBridge::OnPoweredError, 344 base::Bind(&ArcBluetoothBridge::OnPoweredError,
300 weak_factory_.GetWeakPtr(), callback)); 345 weak_factory_.GetWeakPtr(), callback));
301 return; 346 return;
302 } 347 }
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 1062
1018 void ArcBluetoothBridge::ReadRemoteRssi( 1063 void ArcBluetoothBridge::ReadRemoteRssi(
1019 mojom::BluetoothAddressPtr remote_addr, 1064 mojom::BluetoothAddressPtr remote_addr,
1020 const ReadRemoteRssiCallback& callback) { 1065 const ReadRemoteRssiCallback& callback) {
1021 BluetoothDevice* device = 1066 BluetoothDevice* device =
1022 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); 1067 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>());
1023 int rssi = device->GetInquiryRSSI(); 1068 int rssi = device->GetInquiryRSSI();
1024 callback.Run(rssi); 1069 callback.Run(rssi);
1025 } 1070 }
1026 1071
1072 void ArcBluetoothBridge::AddService(mojom::BluetoothGattServiceIDPtr service_id,
1073 int32_t num_handles,
1074 const AddServiceCallback& callback) {}
1075
1076 void ArcBluetoothBridge::AddCharacteristic(
1077 int32_t service_handle,
1078 mojom::BluetoothUUIDPtr uuid,
1079 int32_t properties,
1080 int32_t permissions,
1081 const AddCharacteristicCallback& callback) {}
1082
1083 void ArcBluetoothBridge::AddDescriptor(int32_t service_handle,
1084 mojom::BluetoothUUIDPtr uuid,
1085 int32_t permissions,
1086 const AddDescriptorCallback& callback) {}
1087
1088 void ArcBluetoothBridge::StartService(int32_t service_handle,
1089 BluetoothTransport device_type,
1090 const StartServiceCallback& callback) {}
1091
1092 void ArcBluetoothBridge::StopService(int32_t service_handle,
1093 const StopServiceCallback& callback) {}
1094
1095 void ArcBluetoothBridge::DeleteService(int32_t service_handle,
1096 const DeleteServiceCallback& callback) {}
1097
1098 void ArcBluetoothBridge::SendIndication(
1099 int32_t attribute_handle,
1100 mojom::BluetoothAddressPtr address,
1101 bool confirm,
1102 mojo::Array<uint8_t> value,
1103 const SendIndicationCallback& callback) {}
1104
1105 void ArcBluetoothBridge::SendResponse(int32_t trans_id,
1106 int32_t status,
1107 mojo::Array<uint8_t> value,
1108 const SendResponseCallback& callback) {}
1109
1027 void ArcBluetoothBridge::OnDiscoveryError() { 1110 void ArcBluetoothBridge::OnDiscoveryError() {
1028 LOG(WARNING) << "failed to change discovery state"; 1111 LOG(WARNING) << "failed to change discovery state";
1029 } 1112 }
1030 1113
1031 void ArcBluetoothBridge::OnPairing(mojom::BluetoothAddressPtr addr) const { 1114 void ArcBluetoothBridge::OnPairing(mojom::BluetoothAddressPtr addr) const {
1032 if (!HasBluetoothInstance()) 1115 if (!HasBluetoothInstance())
1033 return; 1116 return;
1034 1117
1035 arc_bridge_service()->bluetooth_instance()->OnBondStateChanged( 1118 arc_bridge_service()->bluetooth_instance()->OnBondStateChanged(
1036 mojom::BluetoothStatus::SUCCESS, std::move(addr), 1119 mojom::BluetoothStatus::SUCCESS, std::move(addr),
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 int32_t version_need) const { 1438 int32_t version_need) const {
1356 int32_t version = arc_bridge_service()->bluetooth_version(); 1439 int32_t version = arc_bridge_service()->bluetooth_version();
1357 if (version >= version_need) 1440 if (version >= version_need)
1358 return true; 1441 return true;
1359 LOG(WARNING) << "Bluetooth instance is too old (version " << version 1442 LOG(WARNING) << "Bluetooth instance is too old (version " << version
1360 << ") need version " << version_need; 1443 << ") need version " << version_need;
1361 return false; 1444 return false;
1362 } 1445 }
1363 1446
1364 } // namespace arc 1447 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698