| OLD | NEW |
| 1 // Copyright 2014 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_REMOTE_GATT_SERVICE_BLUEZ_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_REMOTE_GATT_SERVICE_BLUEZ_H_ |
| 6 #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_BLUEZ_H_ | 6 #define DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_REMOTE_GATT_SERVICE_BLUEZ_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <map> |
| 9 #include <string> | 10 #include <string> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/callback_forward.h" | |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "dbus/object_path.h" | 15 #include "dbus/object_path.h" |
| 16 #include "device/bluetooth/bluetooth_gatt_service_bluez.h" | 16 #include "device/bluetooth/bluetooth_remote_gatt_service.h" |
| 17 #include "device/bluetooth/bluetooth_uuid.h" | 17 #include "device/bluetooth/bluetooth_uuid.h" |
| 18 #include "device/bluetooth/bluez/bluetooth_gatt_service_bluez.h" |
| 18 #include "device/bluetooth/dbus/bluetooth_gatt_characteristic_client.h" | 19 #include "device/bluetooth/dbus/bluetooth_gatt_characteristic_client.h" |
| 19 #include "device/bluetooth/dbus/bluetooth_gatt_service_client.h" | 20 #include "device/bluetooth/dbus/bluetooth_gatt_service_client.h" |
| 20 | 21 |
| 21 namespace device { | 22 namespace device { |
| 22 | 23 |
| 23 class BluetoothAdapter; | 24 class BluetoothAdapter; |
| 24 class BluetoothDevice; | 25 class BluetoothDevice; |
| 25 class BluetoothGattCharacteristic; | 26 class BluetoothRemoteGattCharacteristic; |
| 26 | 27 |
| 27 } // namespace device | 28 } // namespace device |
| 28 | 29 |
| 29 namespace bluez { | 30 namespace bluez { |
| 30 | 31 |
| 31 class BluetoothAdapterBlueZ; | 32 class BluetoothAdapterBlueZ; |
| 32 class BluetoothDeviceBlueZ; | 33 class BluetoothDeviceBlueZ; |
| 33 class BluetoothRemoteGattCharacteristicBlueZ; | 34 class BluetoothRemoteGattCharacteristicBlueZ; |
| 34 class BluetoothGattDescriptorBlueZ; | 35 class BluetoothRemoteGattDescriptorBlueZ; |
| 35 | 36 |
| 36 // The BluetoothRemoteGattServiceBlueZ class implements BluetootGattService | 37 // The BluetoothRemoteGattServiceBlueZ class implements BluetootGattService |
| 37 // for remote GATT services for platforms that use BlueZ. | 38 // for remote GATT services for platforms that use BlueZ. |
| 38 class BluetoothRemoteGattServiceBlueZ | 39 class BluetoothRemoteGattServiceBlueZ |
| 39 : public BluetoothGattServiceBlueZ, | 40 : public BluetoothGattServiceBlueZ, |
| 40 public BluetoothGattServiceClient::Observer, | 41 public BluetoothGattServiceClient::Observer, |
| 41 public BluetoothGattCharacteristicClient::Observer { | 42 public BluetoothGattCharacteristicClient::Observer, |
| 43 public device::BluetoothRemoteGattService { |
| 42 public: | 44 public: |
| 43 // device::BluetoothGattService overrides. | 45 // device::BluetoothRemoteGattService overrides. |
| 44 device::BluetoothUUID GetUUID() const override; | 46 device::BluetoothUUID GetUUID() const override; |
| 45 bool IsLocal() const override; | 47 device::BluetoothDevice* GetDevice() const override; |
| 46 bool IsPrimary() const override; | 48 bool IsPrimary() const override; |
| 47 device::BluetoothDevice* GetDevice() const override; | 49 std::vector<device::BluetoothRemoteGattCharacteristic*> GetCharacteristics() |
| 48 bool AddCharacteristic( | 50 const override; |
| 49 device::BluetoothGattCharacteristic* characteristic) override; | 51 std::vector<device::BluetoothRemoteGattService*> GetIncludedServices() |
| 50 bool AddIncludedService(device::BluetoothGattService* service) override; | 52 const override; |
| 51 void Register(const base::Closure& callback, | 53 device::BluetoothRemoteGattCharacteristic* GetCharacteristic( |
| 52 const ErrorCallback& error_callback) override; | 54 const std::string& identifier) const override; |
| 53 void Unregister(const base::Closure& callback, | |
| 54 const ErrorCallback& error_callback) override; | |
| 55 | 55 |
| 56 // Notifies its observers that the GATT service has changed. This is mainly | 56 // Notifies its observers that the GATT service has changed. This is mainly |
| 57 // used by BluetoothRemoteGattCharacteristicBlueZ instances to notify | 57 // used by BluetoothRemoteGattCharacteristicBlueZ instances to notify |
| 58 // service observers when characteristic descriptors get added and removed. | 58 // service observers when characteristic descriptors get added and removed. |
| 59 void NotifyServiceChanged(); | 59 void NotifyServiceChanged(); |
| 60 | 60 |
| 61 // Notifies its observers that a descriptor |descriptor| belonging to | 61 // Notifies its observers that a descriptor |descriptor| belonging to |
| 62 // characteristic |characteristic| has been added or removed. This is used | 62 // characteristic |characteristic| has been added or removed. This is used |
| 63 // by BluetoothRemoteGattCharacteristicBlueZ instances to notify service | 63 // by BluetoothRemoteGattCharacteristicBlueZ instances to notify service |
| 64 // observers when characteristic descriptors get added and removed. If |added| | 64 // observers when characteristic descriptors get added and removed. If |added| |
| 65 // is true, an "Added" event will be sent. Otherwise, a "Removed" event will | 65 // is true, an "Added" event will be sent. Otherwise, a "Removed" event will |
| 66 // be sent. | 66 // be sent. |
| 67 void NotifyDescriptorAddedOrRemoved( | 67 void NotifyDescriptorAddedOrRemoved( |
| 68 BluetoothRemoteGattCharacteristicBlueZ* characteristic, | 68 BluetoothRemoteGattCharacteristicBlueZ* characteristic, |
| 69 BluetoothGattDescriptorBlueZ* descriptor, | 69 BluetoothRemoteGattDescriptorBlueZ* descriptor, |
| 70 bool added); | 70 bool added); |
| 71 | 71 |
| 72 // Notifies its observers that the value of a descriptor has changed. Called | 72 // Notifies its observers that the value of a descriptor has changed. Called |
| 73 // by BluetoothRemoteGattCharacteristicBlueZ instances to notify service | 73 // by BluetoothRemoteGattCharacteristicBlueZ instances to notify service |
| 74 // observers. | 74 // observers. |
| 75 void NotifyDescriptorValueChanged( | 75 void NotifyDescriptorValueChanged( |
| 76 BluetoothRemoteGattCharacteristicBlueZ* characteristic, | 76 BluetoothRemoteGattCharacteristicBlueZ* characteristic, |
| 77 BluetoothGattDescriptorBlueZ* descriptor, | 77 BluetoothRemoteGattDescriptorBlueZ* descriptor, |
| 78 const std::vector<uint8_t>& value); | 78 const std::vector<uint8_t>& value); |
| 79 | 79 |
| 80 private: | 80 private: |
| 81 friend class BluetoothDeviceBlueZ; | 81 friend class BluetoothDeviceBlueZ; |
| 82 | 82 |
| 83 BluetoothRemoteGattServiceBlueZ(BluetoothAdapterBlueZ* adapter, | 83 BluetoothRemoteGattServiceBlueZ(BluetoothAdapterBlueZ* adapter, |
| 84 BluetoothDeviceBlueZ* device, | 84 BluetoothDeviceBlueZ* device, |
| 85 const dbus::ObjectPath& object_path); | 85 const dbus::ObjectPath& object_path); |
| 86 ~BluetoothRemoteGattServiceBlueZ() override; | 86 ~BluetoothRemoteGattServiceBlueZ() override; |
| 87 | 87 |
| 88 // bluez::BluetoothGattServiceClient::Observer override. | 88 // bluez::BluetoothGattServiceClient::Observer override. |
| 89 void GattServicePropertyChanged(const dbus::ObjectPath& object_path, | 89 void GattServicePropertyChanged(const dbus::ObjectPath& object_path, |
| 90 const std::string& property_name) override; | 90 const std::string& property_name) override; |
| 91 | 91 |
| 92 // bluez::BluetoothGattCharacteristicClient::Observer override. | 92 // bluez::BluetoothGattCharacteristicClient::Observer override. |
| 93 void GattCharacteristicAdded(const dbus::ObjectPath& object_path) override; | 93 void GattCharacteristicAdded(const dbus::ObjectPath& object_path) override; |
| 94 void GattCharacteristicRemoved(const dbus::ObjectPath& object_path) override; | 94 void GattCharacteristicRemoved(const dbus::ObjectPath& object_path) override; |
| 95 void GattCharacteristicPropertyChanged( | 95 void GattCharacteristicPropertyChanged( |
| 96 const dbus::ObjectPath& object_path, | 96 const dbus::ObjectPath& object_path, |
| 97 const std::string& property_name) override; | 97 const std::string& property_name) override; |
| 98 | 98 |
| 99 // The device this GATT service belongs to. It's ok to store a raw pointer | 99 // The device this GATT service belongs to. It's ok to store a raw pointer |
| 100 // here since |device_| owns this instance. | 100 // here since |device_| owns this instance. |
| 101 BluetoothDeviceBlueZ* device_; | 101 BluetoothDeviceBlueZ* device_; |
| 102 | 102 |
| 103 // TODO(rkc): Investigate and fix ownership of the characteristic objects in |
| 104 // this map. See crbug.com/604166. |
| 105 using CharacteristicMap = |
| 106 std::map<dbus::ObjectPath, BluetoothRemoteGattCharacteristicBlueZ*>; |
| 107 |
| 108 // Mapping from GATT characteristic object paths to characteristic objects. |
| 109 // owned by this service. Since the BlueZ implementation uses object |
| 110 // paths as unique identifiers, we also use this mapping to return |
| 111 // characteristics by identifier. |
| 112 CharacteristicMap characteristics_; |
| 113 |
| 103 // Indicates whether or not the characteristics of this service are known to | 114 // Indicates whether or not the characteristics of this service are known to |
| 104 // have been discovered. | 115 // have been discovered. |
| 105 bool discovery_complete_; | 116 bool discovery_complete_; |
| 106 | 117 |
| 107 // Note: This should remain the last member so it'll be destroyed and | 118 // Note: This should remain the last member so it'll be destroyed and |
| 108 // invalidate its weak pointers before any other members are destroyed. | 119 // invalidate its weak pointers before any other members are destroyed. |
| 109 base::WeakPtrFactory<BluetoothRemoteGattServiceBlueZ> weak_ptr_factory_; | 120 base::WeakPtrFactory<BluetoothRemoteGattServiceBlueZ> weak_ptr_factory_; |
| 110 | 121 |
| 111 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattServiceBlueZ); | 122 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattServiceBlueZ); |
| 112 }; | 123 }; |
| 113 | 124 |
| 114 } // namespace bluez | 125 } // namespace bluez |
| 115 | 126 |
| 116 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_BLUEZ_H_ | 127 #endif // DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_REMOTE_GATT_SERVICE_BLUEZ_H_ |
| OLD | NEW |