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

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: Bump mojo id 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
« no previous file with comments | « components/arc/bluetooth/arc_bluetooth_bridge.h ('k') | 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>
11 11
12 #include <iomanip> 12 #include <iomanip>
13 #include <string> 13 #include <string>
14 #include <utility> 14 #include <utility>
15 15
16 #include "base/bind.h" 16 #include "base/bind.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/posix/eintr_wrapper.h" 18 #include "base/posix/eintr_wrapper.h"
19 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
21 #include "base/threading/thread_task_runner_handle.h" 21 #include "base/threading/thread_task_runner_handle.h"
22 #include "base/time/time.h" 22 #include "base/time/time.h"
23 #include "components/arc/arc_bridge_service.h" 23 #include "components/arc/arc_bridge_service.h"
24 #include "components/arc/bluetooth/bluetooth_type_converters.h" 24 #include "components/arc/bluetooth/bluetooth_type_converters.h"
25 #include "device/bluetooth/bluetooth_adapter_factory.h"
26 #include "device/bluetooth/bluetooth_common.h" 25 #include "device/bluetooth/bluetooth_common.h"
27 #include "device/bluetooth/bluetooth_device.h" 26 #include "device/bluetooth/bluetooth_device.h"
28 #include "device/bluetooth/bluetooth_gatt_connection.h" 27 #include "device/bluetooth/bluetooth_gatt_connection.h"
29 #include "device/bluetooth/bluetooth_gatt_notify_session.h" 28 #include "device/bluetooth/bluetooth_gatt_notify_session.h"
30 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" 29 #include "device/bluetooth/bluetooth_local_gatt_characteristic.h"
31 #include "device/bluetooth/bluetooth_remote_gatt_descriptor.h" 30 #include "device/bluetooth/bluetooth_local_gatt_descriptor.h"
32 #include "device/bluetooth/bluetooth_remote_gatt_service.h"
33 #include "mojo/edk/embedder/embedder.h" 31 #include "mojo/edk/embedder/embedder.h"
34 #include "mojo/edk/embedder/scoped_platform_handle.h" 32 #include "mojo/edk/embedder/scoped_platform_handle.h"
35 33
36 using device::BluetoothAdapter; 34 using device::BluetoothAdapter;
37 using device::BluetoothAdapterFactory; 35 using device::BluetoothAdapterFactory;
38 using device::BluetoothAdvertisement; 36 using device::BluetoothAdvertisement;
39 using device::BluetoothDevice; 37 using device::BluetoothDevice;
40 using device::BluetoothDiscoveryFilter; 38 using device::BluetoothDiscoveryFilter;
41 using device::BluetoothDiscoverySession; 39 using device::BluetoothDiscoverySession;
42 using device::BluetoothGattConnection; 40 using device::BluetoothGattConnection;
43 using device::BluetoothGattNotifySession; 41 using device::BluetoothGattNotifySession;
44 using device::BluetoothGattCharacteristic; 42 using device::BluetoothGattCharacteristic;
45 using device::BluetoothGattDescriptor; 43 using device::BluetoothGattDescriptor;
46 using device::BluetoothGattService; 44 using device::BluetoothGattService;
45 using device::BluetoothLocalGattCharacteristic;
46 using device::BluetoothLocalGattDescriptor;
47 using device::BluetoothLocalGattService;
47 using device::BluetoothRemoteGattCharacteristic; 48 using device::BluetoothRemoteGattCharacteristic;
48 using device::BluetoothRemoteGattDescriptor; 49 using device::BluetoothRemoteGattDescriptor;
49 using device::BluetoothRemoteGattService; 50 using device::BluetoothRemoteGattService;
51 using device::BluetoothTransport;
50 using device::BluetoothUUID; 52 using device::BluetoothUUID;
51 53
52 namespace { 54 namespace {
53 constexpr int32_t kMinBtleVersion = 1; 55 constexpr int32_t kMinBtleVersion = 1;
54 constexpr int32_t kMinBtleNotifyVersion = 2; 56 constexpr int32_t kMinBtleNotifyVersion = 2;
55 constexpr uint32_t kGattReadPermission = 57 constexpr uint32_t kGattReadPermission =
56 BluetoothGattCharacteristic::Permission::PERMISSION_READ | 58 BluetoothGattCharacteristic::Permission::PERMISSION_READ |
57 BluetoothGattCharacteristic::Permission::PERMISSION_READ_ENCRYPTED | 59 BluetoothGattCharacteristic::Permission::PERMISSION_READ_ENCRYPTED |
58 BluetoothGattCharacteristic::Permission:: 60 BluetoothGattCharacteristic::Permission::
59 PERMISSION_READ_ENCRYPTED_AUTHENTICATED; 61 PERMISSION_READ_ENCRYPTED_AUTHENTICATED;
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 true /* is_notify */, mojo::Array<uint8_t>::From(value)); 288 true /* is_notify */, mojo::Array<uint8_t>::From(value));
287 } 289 }
288 290
289 void ArcBluetoothBridge::GattDescriptorValueChanged( 291 void ArcBluetoothBridge::GattDescriptorValueChanged(
290 BluetoothAdapter* adapter, 292 BluetoothAdapter* adapter,
291 BluetoothRemoteGattDescriptor* descriptor, 293 BluetoothRemoteGattDescriptor* descriptor,
292 const std::vector<uint8_t>& value) { 294 const std::vector<uint8_t>& value) {
293 // Placeholder for GATT client functionality 295 // Placeholder for GATT client functionality
294 } 296 }
295 297
298 void ArcBluetoothBridge::OnCharacteristicReadRequest(
299 const BluetoothDevice* device,
300 const BluetoothLocalGattCharacteristic* characteristic,
301 int offset,
302 const ValueCallback& callback,
303 const ErrorCallback& error_callback) {}
304
305 void ArcBluetoothBridge::OnCharacteristicWriteRequest(
306 const BluetoothDevice* device,
307 const BluetoothLocalGattCharacteristic* characteristic,
308 const std::vector<uint8_t>& value,
309 int offset,
310 const base::Closure& callback,
311 const ErrorCallback& error_callback) {}
312
313 void ArcBluetoothBridge::OnDescriptorReadRequest(
314 const BluetoothDevice* device,
315 const BluetoothLocalGattDescriptor* descriptor,
316 int offset,
317 const ValueCallback& callback,
318 const ErrorCallback& error_callback) {}
319
320 void ArcBluetoothBridge::OnDescriptorWriteRequest(
321 const BluetoothDevice* device,
322 const BluetoothLocalGattDescriptor* descriptor,
323 const std::vector<uint8_t>& value,
324 int offset,
325 const base::Closure& callback,
326 const ErrorCallback& error_callback) {}
327
328 void ArcBluetoothBridge::OnNotificationsStart(
329 const BluetoothDevice* device,
330 const BluetoothLocalGattCharacteristic* characteristic) {}
331
332 void ArcBluetoothBridge::OnNotificationsStop(
333 const BluetoothDevice* device,
334 const BluetoothLocalGattCharacteristic* characteristic) {}
335
296 void ArcBluetoothBridge::EnableAdapter(const EnableAdapterCallback& callback) { 336 void ArcBluetoothBridge::EnableAdapter(const EnableAdapterCallback& callback) {
297 DCHECK(bluetooth_adapter_); 337 DCHECK(bluetooth_adapter_);
298 if (!bluetooth_adapter_->IsPowered()) { 338 if (!bluetooth_adapter_->IsPowered()) {
299 bluetooth_adapter_->SetPowered( 339 bluetooth_adapter_->SetPowered(
300 true, base::Bind(&ArcBluetoothBridge::OnPoweredOn, 340 true, base::Bind(&ArcBluetoothBridge::OnPoweredOn,
301 weak_factory_.GetWeakPtr(), callback), 341 weak_factory_.GetWeakPtr(), callback),
302 base::Bind(&ArcBluetoothBridge::OnPoweredError, 342 base::Bind(&ArcBluetoothBridge::OnPoweredError,
303 weak_factory_.GetWeakPtr(), callback)); 343 weak_factory_.GetWeakPtr(), callback));
304 return; 344 return;
305 } 345 }
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 if (wrap_result != MOJO_RESULT_OK) { 1083 if (wrap_result != MOJO_RESULT_OK) {
1044 LOG(ERROR) << "Failed to wrap handles. Closing: " << wrap_result; 1084 LOG(ERROR) << "Failed to wrap handles. Closing: " << wrap_result;
1045 callback.Run(mojo::ScopedHandle()); 1085 callback.Run(mojo::ScopedHandle());
1046 return; 1086 return;
1047 } 1087 }
1048 mojo::ScopedHandle scoped_handle{mojo::Handle(wrapped_handle)}; 1088 mojo::ScopedHandle scoped_handle{mojo::Handle(wrapped_handle)};
1049 1089
1050 callback.Run(std::move(scoped_handle)); 1090 callback.Run(std::move(scoped_handle));
1051 } 1091 }
1052 1092
1093 void ArcBluetoothBridge::AddService(mojom::BluetoothGattServiceIDPtr service_id,
1094 int32_t num_handles,
1095 const AddServiceCallback& callback) {}
1096
1097 void ArcBluetoothBridge::AddCharacteristic(
1098 int32_t service_handle,
1099 mojom::BluetoothUUIDPtr uuid,
1100 int32_t properties,
1101 int32_t permissions,
1102 const AddCharacteristicCallback& callback) {}
1103
1104 void ArcBluetoothBridge::AddDescriptor(int32_t service_handle,
1105 mojom::BluetoothUUIDPtr uuid,
1106 int32_t permissions,
1107 const AddDescriptorCallback& callback) {}
1108
1109 void ArcBluetoothBridge::StartService(int32_t service_handle,
1110 const StartServiceCallback& callback) {}
1111
1112 void ArcBluetoothBridge::StopService(int32_t service_handle,
1113 const StopServiceCallback& callback) {}
1114
1115 void ArcBluetoothBridge::DeleteService(int32_t service_handle,
1116 const DeleteServiceCallback& callback) {}
1117
1118 void ArcBluetoothBridge::SendIndication(
1119 int32_t attribute_handle,
1120 mojom::BluetoothAddressPtr address,
1121 bool confirm,
1122 mojo::Array<uint8_t> value,
1123 const SendIndicationCallback& callback) {}
1124
1053 void ArcBluetoothBridge::OnDiscoveryError() { 1125 void ArcBluetoothBridge::OnDiscoveryError() {
1054 LOG(WARNING) << "failed to change discovery state"; 1126 LOG(WARNING) << "failed to change discovery state";
1055 } 1127 }
1056 1128
1057 void ArcBluetoothBridge::OnPairing(mojom::BluetoothAddressPtr addr) const { 1129 void ArcBluetoothBridge::OnPairing(mojom::BluetoothAddressPtr addr) const {
1058 if (!HasBluetoothInstance()) 1130 if (!HasBluetoothInstance())
1059 return; 1131 return;
1060 1132
1061 arc_bridge_service()->bluetooth()->instance()->OnBondStateChanged( 1133 arc_bridge_service()->bluetooth()->instance()->OnBondStateChanged(
1062 mojom::BluetoothStatus::SUCCESS, std::move(addr), 1134 mojom::BluetoothStatus::SUCCESS, std::move(addr),
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
1381 uint32_t version_need) const { 1453 uint32_t version_need) const {
1382 uint32_t version = arc_bridge_service()->bluetooth()->version(); 1454 uint32_t version = arc_bridge_service()->bluetooth()->version();
1383 if (version >= version_need) 1455 if (version >= version_need)
1384 return true; 1456 return true;
1385 LOG(WARNING) << "Bluetooth instance is too old (version " << version 1457 LOG(WARNING) << "Bluetooth instance is too old (version " << version
1386 << ") need version " << version_need; 1458 << ") need version " << version_need;
1387 return false; 1459 return false;
1388 } 1460 }
1389 1461
1390 } // namespace arc 1462 } // namespace arc
OLDNEW
« no previous file with comments | « components/arc/bluetooth/arc_bluetooth_bridge.h ('k') | components/arc/common/bluetooth.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698