 Chromium Code Reviews
 Chromium Code Reviews Issue 2448713002:
  bluetooth: Add Device connection logic and accompanying user interface.  (Closed)
    
  
    Issue 2448713002:
  bluetooth: Add Device connection logic and accompanying user interface.  (Closed) 
  | OLD | NEW | 
|---|---|
| 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 #ifndef DEVICE_BLUETOOTH_DEVICE_H_ | 5 #ifndef DEVICE_BLUETOOTH_DEVICE_H_ | 
| 6 #define DEVICE_BLUETOOTH_DEVICE_H_ | 6 #define DEVICE_BLUETOOTH_DEVICE_H_ | 
| 7 | 7 | 
| 8 #include <memory> | |
| 8 #include <string> | 9 #include <string> | 
| 10 #include <vector> | |
| 9 | 11 | 
| 10 #include "base/macros.h" | 12 #include "base/macros.h" | 
| 11 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" | 
| 12 #include "device/bluetooth/bluetooth_adapter.h" | 14 #include "device/bluetooth/bluetooth_adapter.h" | 
| 13 #include "device/bluetooth/bluetooth_device.h" | 15 #include "device/bluetooth/bluetooth_device.h" | 
| 16 #include "device/bluetooth/bluetooth_gatt_connection.h" | |
| 17 #include "device/bluetooth/bluetooth_remote_gatt_service.h" | |
| 14 #include "device/bluetooth/public/interfaces/device.mojom.h" | 18 #include "device/bluetooth/public/interfaces/device.mojom.h" | 
| 19 #include "mojo/public/cpp/bindings/binding.h" | |
| 15 | 20 | 
| 16 namespace bluetooth { | 21 namespace bluetooth { | 
| 17 | 22 | 
| 18 // Implementation of Mojo Device located in | 23 // Implementation of Mojo Device located in | 
| 19 // device/bluetooth/public/interfaces/device.mojom. | 24 // device/bluetooth/public/interfaces/device.mojom. | 
| 20 // It handles requests to interact with Bluetooth Device. | 25 // It handles requests to interact with Bluetooth Device. | 
| 21 // Uses the platform abstraction of device/bluetooth. | 26 // Uses the platform abstraction of device/bluetooth. | 
| 22 class Device : public mojom::Device { | 27 // Instances of this class are constructed by Adapter and are bound to their | 
| 28 // MessagePipe and BluetoothGattConnection lifetimes. In the case where either | |
| 29 // the MessagePipe or BluetoothGattConnection dies, the instance deletes itself. | |
| 30 class Device : public mojom::Device, public device::BluetoothAdapter::Observer { | |
| 23 public: | 31 public: | 
| 24 Device(const std::string& address, | 32 Device(scoped_refptr<device::BluetoothAdapter> adapter, | 
| 25 scoped_refptr<device::BluetoothAdapter> adapter); | 33 std::unique_ptr<device::BluetoothGattConnection> connection, | 
| 34 mojom::DeviceRequest request); | |
| 26 ~Device() override; | 35 ~Device() override; | 
| 27 | 36 | 
| 28 // Creates a mojom::DeviceInfo using info from the given |device|. | 37 // Creates a mojom::DeviceInfo using info from the given |device|. | 
| 29 static mojom::DeviceInfoPtr ConstructDeviceInfoStruct( | 38 static mojom::DeviceInfoPtr ConstructDeviceInfoStruct( | 
| 30 const device::BluetoothDevice* device); | 39 const device::BluetoothDevice* device); | 
| 31 | 40 | 
| 41 // Registers a handler to receive error notifications. | |
| 42 // | |
| 43 // The default connection error handler is the Disconnect function. Changing | |
| 44 // the connection error handler prevents the Device from destroying itself | |
| 45 // after Mojo binding connection errors, so callers of this function should | |
| 46 // be prepared to cleanup Device unless the BluetoothGattConnection is | |
| 47 // dropped. | |
| 48 void set_connection_error_handler(const base::Closure& closure); | |
| 
ortuno
2016/11/01 06:27:39
Why do you need to expose this? Also since it's on
 
mbrunson
2016/11/02 01:25:46
I was getting segfaults when calling Device functi
 | |
| 49 | |
| 50 // BluetoothAdapter::Observer overrides: | |
| 51 void DeviceChanged(device::BluetoothAdapter* adapter, | |
| 52 device::BluetoothDevice* device) override; | |
| 53 void GattServicesDiscovered(device::BluetoothAdapter* adapter, | |
| 54 device::BluetoothDevice* device) override; | |
| 55 | |
| 32 // mojom::Device overrides: | 56 // mojom::Device overrides: | 
| 57 void Disconnect() override; | |
| 33 void GetInfo(const GetInfoCallback& callback) override; | 58 void GetInfo(const GetInfoCallback& callback) override; | 
| 59 void GetServices(const GetServicesCallback& callback) override; | |
| 34 | 60 | 
| 35 private: | 61 private: | 
| 36 // The address of the Bluetooth device. | 62 void GetServicesImpl(const GetServicesCallback& callback); | 
| 37 std::string address_; | 63 | 
| 64 mojom::ServiceInfoPtr ConstructServiceInfoStruct( | |
| 65 const device::BluetoothRemoteGattService* service); | |
| 66 | |
| 67 std::string GetAddress(); | |
| 
ortuno
2016/11/01 06:27:39
hmm I might be missing something but it seems this
 
mbrunson
2016/11/02 01:25:46
Ah yes. It should be. Done.
 | |
| 38 | 68 | 
| 39 // The current BluetoothAdapter. | 69 // The current BluetoothAdapter. | 
| 40 scoped_refptr<device::BluetoothAdapter> adapter_; | 70 scoped_refptr<device::BluetoothAdapter> adapter_; | 
| 41 | 71 | 
| 72 // The GATT connection to this device. | |
| 73 std::unique_ptr<device::BluetoothGattConnection> connection_; | |
| 74 | |
| 75 // The services request queue which holds callbacks that are waiting for | |
| 76 // services to be discovered for this device. | |
| 77 std::vector<base::Closure> pending_services_requests_; | |
| 78 | |
| 79 mojo::Binding<mojom::Device> binding_; | |
| 80 | |
| 42 DISALLOW_COPY_AND_ASSIGN(Device); | 81 DISALLOW_COPY_AND_ASSIGN(Device); | 
| 43 }; | 82 }; | 
| 44 | 83 | 
| 45 } // namespace bluetooth | 84 } // namespace bluetooth | 
| 46 | 85 | 
| 47 #endif // DEVICE_BLUETOOTH_DEVICE_H_ | 86 #endif // DEVICE_BLUETOOTH_DEVICE_H_ | 
| OLD | NEW |