Index: device/bluetooth/device.cc |
diff --git a/device/bluetooth/device.cc b/device/bluetooth/device.cc |
index 7e662802eabb5aed91c9859f782903049c866170..b6b493587713cd1852d211c6c7f5f0b64555ac91 100644 |
--- a/device/bluetooth/device.cc |
+++ b/device/bluetooth/device.cc |
@@ -10,9 +10,9 @@ |
namespace bluetooth { |
-Device::Device(const std::string& address, |
- scoped_refptr<device::BluetoothAdapter> adapter) |
- : address_(address), adapter_(std::move(adapter)) {} |
+Device::Device(scoped_refptr<device::BluetoothAdapter> adapter, |
+ std::unique_ptr<device::BluetoothGattConnection> connection) |
+ : adapter_(std::move(adapter)), connection_(std::move(connection)) {} |
ortuno
2016/10/25 10:42:09
You mention that the pipe is tied to the lifetime
mbrunson
2016/10/25 20:03:04
Hmm, ok. More logic would be needed in Adapter to
ortuno
2016/10/26 02:52:21
I don't think you need to add the logic in Adapter
mbrunson
2016/10/28 21:06:47
Oh ok. That makes sense. Done.
|
Device::~Device() {} |
@@ -25,6 +25,7 @@ mojom::DeviceInfoPtr Device::ConstructDeviceInfoStruct( |
device_info->name_for_display = |
base::UTF16ToUTF8(device->GetNameForDisplay()); |
device_info->address = device->GetAddress(); |
+ device_info->connected = device->IsGattConnected(); |
if (device->GetInquiryRSSI()) { |
device_info->rssi = mojom::RSSIWrapper::New(); |
@@ -35,7 +36,8 @@ mojom::DeviceInfoPtr Device::ConstructDeviceInfoStruct( |
} |
void Device::GetInfo(const GetInfoCallback& callback) { |
- device::BluetoothDevice* device = adapter_->GetDevice(address_); |
+ device::BluetoothDevice* device = |
+ adapter_->GetDevice(connection_->GetDeviceAddress()); |
if (device) { |
mojom::DeviceInfoPtr device_info = ConstructDeviceInfoStruct(device); |
callback.Run(std::move(device_info)); |
@@ -44,4 +46,30 @@ void Device::GetInfo(const GetInfoCallback& callback) { |
} |
} |
+void Device::GetServices(const GetServicesCallback& callback) { |
+ device::BluetoothDevice* device = |
+ adapter_->GetDevice(connection_->GetDeviceAddress()); |
+ std::vector<mojom::ServiceInfoPtr> services; |
+ |
+ if (device) { |
+ for (const device::BluetoothRemoteGattService* service : |
+ device->GetGattServices()) { |
ortuno
2016/10/25 10:42:09
To avoid returning services that no longer exist o
mbrunson
2016/10/25 20:03:04
The original pattern I was thinking of would be ha
ortuno
2016/10/26 02:52:21
Do you mean AdapterClient::ServicesDiscovered?
Th
mbrunson
2016/10/28 21:06:47
Queue implemented with tests. Done.
|
+ mojom::ServiceInfoPtr service_info = ConstructServiceInfoStruct(service); |
+ services.push_back(std::move(service_info)); |
+ } |
+ } |
+ |
+ callback.Run(std::move(services)); |
+} |
+ |
+mojom::ServiceInfoPtr Device::ConstructServiceInfoStruct( |
ortuno
2016/10/25 10:42:09
nit: No need for this helper function. The code is
mbrunson
2016/10/25 20:03:04
The ServiceChanged callback in AdapterClient will
|
+ const device::BluetoothRemoteGattService* service) { |
+ mojom::ServiceInfoPtr service_info = mojom::ServiceInfo::New(); |
+ |
+ service_info->uuid = service->GetUUID(); |
+ service_info->primary = service->IsPrimary(); |
+ |
+ return service_info; |
+} |
+ |
} // namespace bluetooth |