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

Unified Diff: device/bluetooth/device.h

Issue 2448713002: bluetooth: Add Device connection logic and accompanying user interface. (Closed)
Patch Set: Major reorganization of Mojo interface code and DeviceCollection Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/bluetooth/adapter.cc ('k') | device/bluetooth/device.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/device.h
diff --git a/device/bluetooth/device.h b/device/bluetooth/device.h
index c82439e6c283ecb6e851e466061bedf060a18420..8befe94620c43303a5063889cfe9a7dc55b39d3f 100644
--- a/device/bluetooth/device.h
+++ b/device/bluetooth/device.h
@@ -5,13 +5,18 @@
#ifndef DEVICE_BLUETOOTH_DEVICE_H_
#define DEVICE_BLUETOOTH_DEVICE_H_
+#include <memory>
#include <string>
+#include <vector>
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "device/bluetooth/bluetooth_adapter.h"
#include "device/bluetooth/bluetooth_device.h"
+#include "device/bluetooth/bluetooth_gatt_connection.h"
+#include "device/bluetooth/bluetooth_remote_gatt_service.h"
#include "device/bluetooth/public/interfaces/device.mojom.h"
+#include "mojo/public/cpp/bindings/binding.h"
namespace bluetooth {
@@ -19,26 +24,61 @@ namespace bluetooth {
// device/bluetooth/public/interfaces/device.mojom.
// It handles requests to interact with Bluetooth Device.
// Uses the platform abstraction of device/bluetooth.
-class Device : public mojom::Device {
+// Instances of this class are constructed by Adapter and are bound to their
+// MessagePipe and BluetoothGattConnection lifetimes. In the case where either
+// the MessagePipe or BluetoothGattConnection dies, the instance deletes itself.
+class Device : public mojom::Device, public device::BluetoothAdapter::Observer {
public:
- Device(const std::string& address,
- scoped_refptr<device::BluetoothAdapter> adapter);
+ Device(scoped_refptr<device::BluetoothAdapter> adapter,
+ std::unique_ptr<device::BluetoothGattConnection> connection,
+ mojom::DeviceRequest request);
~Device() override;
// Creates a mojom::DeviceInfo using info from the given |device|.
static mojom::DeviceInfoPtr ConstructDeviceInfoStruct(
const device::BluetoothDevice* device);
+ // Registers a handler to receive error notifications.
+ //
+ // The default connection error handler is the Disconnect function. Changing
+ // the connection error handler prevents the Device from destroying itself
+ // after Mojo binding connection errors, so callers of this function should
+ // be prepared to cleanup Device unless the BluetoothGattConnection is
+ // dropped.
+ void set_connection_error_handler(const base::Closure& closure);
+
+ // BluetoothAdapter::Observer overrides:
+ void DeviceChanged(device::BluetoothAdapter* adapter,
+ device::BluetoothDevice* device) override;
+
+ void GattServicesDiscovered(device::BluetoothAdapter* adapter,
+ device::BluetoothDevice* device) override;
+
// mojom::Device overrides:
+ void Disconnect() override;
void GetInfo(const GetInfoCallback& callback) override;
+ void GetServices(const GetServicesCallback& callback) override;
private:
- // The address of the Bluetooth device.
- std::string address_;
+ void GetServicesImpl(const GetServicesCallback& callback);
+
+ mojom::ServiceInfoPtr ConstructServiceInfoStruct(
+ const device::BluetoothRemoteGattService* service);
+
+ std::string GetAddress();
// The current BluetoothAdapter.
scoped_refptr<device::BluetoothAdapter> adapter_;
+ // The GATT connection to this device.
+ std::unique_ptr<device::BluetoothGattConnection> connection_;
+
+ // The services request queue which holds callbacks that are waiting for
+ // services to be discovered for this device.
+ std::vector<base::Closure> pending_services_requests_;
+
+ mojo::Binding<mojom::Device> binding_;
+
DISALLOW_COPY_AND_ASSIGN(Device);
};
« no previous file with comments | « device/bluetooth/adapter.cc ('k') | device/bluetooth/device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698