Chromium Code Reviews| 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_BLUETOOTH_LOCAL_GATT_CHARACTERISTIC_BLUEZ_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_LOCAL_GATT_CHARACTERISTIC_H_ |
| 6 #define DEVICE_BLUETOOTH_BLUETOOTH_LOCAL_GATT_CHARACTERISTIC_BLUEZ_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_LOCAL_GATT_CHARACTERISTIC_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback_forward.h" | |
| 12 #include "base/macros.h" | 11 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" | 12 #include "device/bluetooth/bluetooth_export.h" |
| 14 #include "dbus/object_path.h" | 13 #include "device/bluetooth/bluetooth_gatt_characteristic.h" |
| 15 #include "device/bluetooth/bluetooth_gatt_characteristic_bluez.h" | 14 #include "device/bluetooth/bluetooth_local_gatt_service.h" |
| 16 #include "device/bluetooth/bluetooth_uuid.h" | 15 #include "device/bluetooth/bluetooth_uuid.h" |
| 17 | 16 |
| 18 namespace device { | 17 namespace device { |
| 19 | 18 |
| 20 class BluetoothGattDescriptor; | 19 // BluetoothLocalGattCharacteristic represents a local GATT characteristic. This |
| 21 class BluetoothGattService; | 20 // class is used to represent GATT characteristics that belong to a locally |
| 21 // hosted service. To achieve this, users need to specify the instance of the | |
| 22 // GATT service that contains this characteristic during construction. | |
| 23 // | |
|
scheib
2016/04/20 01:23:30
Maybe chime in on lifetime management. The Service
rkc
2016/04/20 16:31:54
In a later CL, these objects are now refcounted. I
| |
| 24 // Note: We use virtual inheritance on the GATT characteristic since it will be | |
| 25 // inherited by platform specific versions of the GATT characteristic classes | |
| 26 // also. The platform specific remote GATT characteristic classes will inherit | |
| 27 // both this class and their GATT characteristic class, hence causing an | |
| 28 // inheritance diamond. | |
| 29 class DEVICE_BLUETOOTH_EXPORT BluetoothLocalGattCharacteristic | |
| 30 : public virtual BluetoothGattCharacteristic { | |
| 31 public: | |
| 32 // Constructs a BluetoothLocalGattCharacteristic associated with a local GATT | |
| 33 // service when the adapter is in the peripheral role. | |
| 34 // | |
| 35 // This method constructs a characteristic with UUID |uuid|, initial cached | |
| 36 // value |value|, properties |properties|, and permissions |permissions|. | |
| 37 // |value| will be cached and returned for read requests and automatically set | |
| 38 // for write requests by default, unless an instance of | |
| 39 // BluetoothRemoteGattService::Delegate has been provided to the associated | |
| 40 // BluetoothRemoteGattService instance, in which case the delegate will handle | |
| 41 // read | |
|
scheib
2016/04/20 01:23:30
wrapping
rkc
2016/04/20 16:31:54
Done.
| |
| 42 // and write requests. The service instance will contain this characteristic. | |
| 43 // TODO(rkc): Investigate how to handle |PROPERTY_EXTENDED_PROPERTIES| | |
| 44 // correctly. | |
| 45 static BluetoothLocalGattCharacteristic* Create( | |
| 46 const BluetoothUUID& uuid, | |
| 47 const std::vector<uint8_t>& value, | |
| 48 Properties properties, | |
| 49 Permissions permissions, | |
| 50 BluetoothLocalGattService* service); | |
| 51 | |
| 52 protected: | |
| 53 BluetoothLocalGattCharacteristic(); | |
| 54 ~BluetoothLocalGattCharacteristic() override; | |
| 55 | |
| 56 private: | |
| 57 DISALLOW_COPY_AND_ASSIGN(BluetoothLocalGattCharacteristic); | |
| 58 }; | |
| 22 | 59 |
| 23 } // namespace device | 60 } // namespace device |
| 24 | 61 |
| 25 namespace bluez { | 62 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOCAL_GATT_CHARACTERISTIC_H_ |
| 26 | |
| 27 class BluetoothLocalGattDescriptorBlueZ; | |
| 28 class BluetoothLocalGattServiceBlueZ; | |
| 29 | |
| 30 // The BluetoothLocalGattCharacteristicBlueZ class implements | |
| 31 // BluetoothGattCharacteristic for remote GATT characteristics for platforms | |
| 32 // that use BlueZ. | |
| 33 class BluetoothLocalGattCharacteristicBlueZ | |
| 34 : public BluetoothGattCharacteristicBlueZ { | |
| 35 public: | |
| 36 // device::BluetoothGattCharacteristic overrides. | |
| 37 device::BluetoothUUID GetUUID() const override; | |
| 38 bool IsLocal() const override; | |
| 39 const std::vector<uint8_t>& GetValue() const override; | |
| 40 Properties GetProperties() const override; | |
| 41 bool IsNotifying() const override; | |
| 42 bool AddDescriptor(device::BluetoothGattDescriptor* descriptor) override; | |
| 43 bool UpdateValue(const std::vector<uint8_t>& value) override; | |
| 44 void StartNotifySession(const NotifySessionCallback& callback, | |
| 45 const ErrorCallback& error_callback) override; | |
| 46 void ReadRemoteCharacteristic(const ValueCallback& callback, | |
| 47 const ErrorCallback& error_callback) override; | |
| 48 void WriteRemoteCharacteristic(const std::vector<uint8_t>& new_value, | |
| 49 const base::Closure& callback, | |
| 50 const ErrorCallback& error_callback) override; | |
| 51 | |
| 52 private: | |
| 53 friend class BluetoothLocalGattServiceBlueZ; | |
| 54 | |
| 55 BluetoothLocalGattCharacteristicBlueZ(BluetoothLocalGattServiceBlueZ* service, | |
| 56 const dbus::ObjectPath& object_path); | |
| 57 ~BluetoothLocalGattCharacteristicBlueZ() override; | |
| 58 | |
| 59 // Note: This should remain the last member so it'll be destroyed and | |
| 60 // invalidate its weak pointers before any other members are destroyed. | |
| 61 base::WeakPtrFactory<BluetoothLocalGattCharacteristicBlueZ> weak_ptr_factory_; | |
| 62 | |
| 63 DISALLOW_COPY_AND_ASSIGN(BluetoothLocalGattCharacteristicBlueZ); | |
| 64 }; | |
| 65 | |
| 66 } // namespace bluez | |
| 67 | |
| 68 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOCAL_GATT_CHARACTERISTIC_BLUEZ_H_ | |
| OLD | NEW |