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

Side by Side Diff: device/bluetooth/device.cc

Issue 2448713002: bluetooth: Add Device connection logic and accompanying user interface. (Closed)
Patch Set: Renaming mojom, ConnectErrorCode changes Created 4 years, 1 month 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 <utility> 5 #include <utility>
6 #include <vector>
6 7
7 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
8 #include "device/bluetooth/device.h" 9 #include "device/bluetooth/device.h"
9 #include "mojo/public/cpp/bindings/strong_binding.h" 10 #include "mojo/public/cpp/bindings/strong_binding.h"
10 11
11 namespace bluetooth { 12 namespace bluetooth {
12 13
13 Device::Device(const std::string& address, 14 Device::Device(scoped_refptr<device::BluetoothAdapter> adapter,
14 scoped_refptr<device::BluetoothAdapter> adapter) 15 std::unique_ptr<device::BluetoothGattConnection> connection)
15 : address_(address), adapter_(std::move(adapter)) {} 16 : adapter_(std::move(adapter)), connection_(std::move(connection)) {}
16 17
17 Device::~Device() {} 18 Device::~Device() {}
18 19
19 // static 20 // static
20 mojom::DeviceInfoPtr Device::ConstructDeviceInfoStruct( 21 mojom::DeviceInfoPtr Device::ConstructDeviceInfoStruct(
21 const device::BluetoothDevice* device) { 22 const device::BluetoothDevice* device) {
22 mojom::DeviceInfoPtr device_info = mojom::DeviceInfo::New(); 23 mojom::DeviceInfoPtr device_info = mojom::DeviceInfo::New();
23 24
24 device_info->name = device->GetName(); 25 device_info->name = device->GetName();
25 device_info->name_for_display = 26 device_info->name_for_display =
26 base::UTF16ToUTF8(device->GetNameForDisplay()); 27 base::UTF16ToUTF8(device->GetNameForDisplay());
27 device_info->address = device->GetAddress(); 28 device_info->address = device->GetAddress();
29 device_info->is_gatt_connected = device->IsGattConnected();
28 30
29 if (device->GetInquiryRSSI()) { 31 if (device->GetInquiryRSSI()) {
30 device_info->rssi = mojom::RSSIWrapper::New(); 32 device_info->rssi = mojom::RSSIWrapper::New();
31 device_info->rssi->value = device->GetInquiryRSSI().value(); 33 device_info->rssi->value = device->GetInquiryRSSI().value();
32 } 34 }
33 35
34 return device_info; 36 return device_info;
35 } 37 }
36 38
37 void Device::GetInfo(const GetInfoCallback& callback) { 39 void Device::GetInfo(const GetInfoCallback& callback) {
38 device::BluetoothDevice* device = adapter_->GetDevice(address_); 40 device::BluetoothDevice* device =
41 adapter_->GetDevice(connection_->GetDeviceAddress());
ortuno 2016/10/26 02:52:21 nit: Add a GetAddress() helper to avoid writing th
mbrunson 2016/10/28 21:06:47 Done.
39 if (device) { 42 if (device) {
40 mojom::DeviceInfoPtr device_info = ConstructDeviceInfoStruct(device); 43 mojom::DeviceInfoPtr device_info = ConstructDeviceInfoStruct(device);
41 callback.Run(std::move(device_info)); 44 callback.Run(std::move(device_info));
42 } else { 45 } else {
43 callback.Run(nullptr); 46 callback.Run(nullptr);
44 } 47 }
45 } 48 }
46 49
50 void Device::GetServices(const GetServicesCallback& callback) {
51 device::BluetoothDevice* device =
52 adapter_->GetDevice(connection_->GetDeviceAddress());
53 std::vector<mojom::ServiceInfoPtr> services;
54
55 if (device) {
56 for (const device::BluetoothRemoteGattService* service :
57 device->GetGattServices()) {
58 mojom::ServiceInfoPtr service_info = ConstructServiceInfoStruct(service);
59 services.push_back(std::move(service_info));
60 }
61 }
62
63 callback.Run(std::move(services));
64 }
65
66 mojom::ServiceInfoPtr Device::ConstructServiceInfoStruct(
67 const device::BluetoothRemoteGattService* service) {
68 mojom::ServiceInfoPtr service_info = mojom::ServiceInfo::New();
69
70 service_info->uuid = service->GetUUID();
71 service_info->is_primary = service->IsPrimary();
72
73 return service_info;
74 }
75
47 } // namespace bluetooth 76 } // namespace bluetooth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698