| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_BLUETOOTH_REMOTE_GATT_SERVICE_BLUEZ_H_ |
| 6 #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_BLUEZ_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_BLUEZ_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | |
| 10 #include <map> | |
| 11 #include <string> | 9 #include <string> |
| 12 #include <vector> | 10 #include <vector> |
| 13 | 11 |
| 12 #include "base/callback_forward.h" |
| 14 #include "base/macros.h" | 13 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | |
| 16 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 17 #include "base/observer_list.h" | |
| 18 #include "dbus/object_path.h" | 15 #include "dbus/object_path.h" |
| 19 #include "device/bluetooth/bluetooth_gatt_service.h" | 16 #include "device/bluetooth/bluetooth_gatt_service_bluez.h" |
| 20 #include "device/bluetooth/bluetooth_uuid.h" | 17 #include "device/bluetooth/bluetooth_uuid.h" |
| 21 #include "device/bluetooth/dbus/bluetooth_gatt_characteristic_client.h" | 18 #include "device/bluetooth/dbus/bluetooth_gatt_characteristic_client.h" |
| 22 #include "device/bluetooth/dbus/bluetooth_gatt_service_client.h" | 19 #include "device/bluetooth/dbus/bluetooth_gatt_service_client.h" |
| 23 | 20 |
| 24 namespace device { | 21 namespace device { |
| 25 | 22 |
| 26 class BluetoothAdapter; | 23 class BluetoothAdapter; |
| 24 class BluetoothDevice; |
| 27 class BluetoothGattCharacteristic; | 25 class BluetoothGattCharacteristic; |
| 28 | 26 |
| 29 } // namespace device | 27 } // namespace device |
| 30 | 28 |
| 31 namespace bluez { | 29 namespace bluez { |
| 32 | 30 |
| 33 class BluetoothAdapterBlueZ; | 31 class BluetoothAdapterBlueZ; |
| 34 class BluetoothDeviceBlueZ; | 32 class BluetoothDeviceBlueZ; |
| 35 class BluetoothRemoteGattCharacteristicBlueZ; | 33 class BluetoothRemoteGattCharacteristicBlueZ; |
| 36 class BluetoothRemoteGattDescriptorBlueZ; | 34 class BluetoothGattDescriptorBlueZ; |
| 37 | 35 |
| 38 // The BluetoothRemoteGattServiceBlueZ class implements BluetootGattService | 36 // The BluetoothRemoteGattServiceBlueZ class implements BluetootGattService |
| 39 // for remote GATT services for platforms that use BlueZ. | 37 // for remote GATT services for platforms that use BlueZ. |
| 40 class BluetoothRemoteGattServiceBlueZ | 38 class BluetoothRemoteGattServiceBlueZ |
| 41 : public device::BluetoothGattService, | 39 : public BluetoothGattServiceBlueZ, |
| 42 public bluez::BluetoothGattServiceClient::Observer, | 40 public BluetoothGattServiceClient::Observer, |
| 43 public bluez::BluetoothGattCharacteristicClient::Observer { | 41 public BluetoothGattCharacteristicClient::Observer { |
| 44 public: | 42 public: |
| 45 // device::BluetoothGattService overrides. | 43 // device::BluetoothGattService overrides. |
| 46 std::string GetIdentifier() const override; | |
| 47 device::BluetoothUUID GetUUID() const override; | 44 device::BluetoothUUID GetUUID() const override; |
| 48 bool IsLocal() const override; | 45 bool IsLocal() const override; |
| 49 bool IsPrimary() const override; | 46 bool IsPrimary() const override; |
| 50 device::BluetoothDevice* GetDevice() const override; | 47 device::BluetoothDevice* GetDevice() const override; |
| 51 std::vector<device::BluetoothGattCharacteristic*> GetCharacteristics() | |
| 52 const override; | |
| 53 std::vector<device::BluetoothGattService*> GetIncludedServices() | |
| 54 const override; | |
| 55 device::BluetoothGattCharacteristic* GetCharacteristic( | |
| 56 const std::string& identifier) const override; | |
| 57 bool AddCharacteristic( | 48 bool AddCharacteristic( |
| 58 device::BluetoothGattCharacteristic* characteristic) override; | 49 device::BluetoothGattCharacteristic* characteristic) override; |
| 59 bool AddIncludedService(device::BluetoothGattService* service) override; | 50 bool AddIncludedService(device::BluetoothGattService* service) override; |
| 60 void Register(const base::Closure& callback, | 51 void Register(const base::Closure& callback, |
| 61 const ErrorCallback& error_callback) override; | 52 const ErrorCallback& error_callback) override; |
| 62 void Unregister(const base::Closure& callback, | 53 void Unregister(const base::Closure& callback, |
| 63 const ErrorCallback& error_callback) override; | 54 const ErrorCallback& error_callback) override; |
| 64 | 55 |
| 65 // Object path of the underlying service. | |
| 66 const dbus::ObjectPath& object_path() const { return object_path_; } | |
| 67 | |
| 68 // Parses a named D-Bus error into a service error code. | |
| 69 static device::BluetoothGattService::GattErrorCode DBusErrorToServiceError( | |
| 70 const std::string error_name); | |
| 71 | |
| 72 // Returns the adapter associated with this service. | |
| 73 BluetoothAdapterBlueZ* GetAdapter() const; | |
| 74 | |
| 75 // 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 |
| 76 // used by BluetoothRemoteGattCharacteristicBlueZ instances to notify | 57 // used by BluetoothRemoteGattCharacteristicBlueZ instances to notify |
| 77 // service observers when characteristic descriptors get added and removed. | 58 // service observers when characteristic descriptors get added and removed. |
| 78 void NotifyServiceChanged(); | 59 void NotifyServiceChanged(); |
| 79 | 60 |
| 80 // Notifies its observers that a descriptor |descriptor| belonging to | 61 // Notifies its observers that a descriptor |descriptor| belonging to |
| 81 // characteristic |characteristic| has been added or removed. This is used | 62 // characteristic |characteristic| has been added or removed. This is used |
| 82 // by BluetoothRemoteGattCharacteristicBlueZ instances to notify service | 63 // by BluetoothRemoteGattCharacteristicBlueZ instances to notify service |
| 83 // observers when characteristic descriptors get added and removed. If |added| | 64 // observers when characteristic descriptors get added and removed. If |added| |
| 84 // 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 |
| 85 // be sent. | 66 // be sent. |
| 86 void NotifyDescriptorAddedOrRemoved( | 67 void NotifyDescriptorAddedOrRemoved( |
| 87 BluetoothRemoteGattCharacteristicBlueZ* characteristic, | 68 BluetoothRemoteGattCharacteristicBlueZ* characteristic, |
| 88 BluetoothRemoteGattDescriptorBlueZ* descriptor, | 69 BluetoothGattDescriptorBlueZ* descriptor, |
| 89 bool added); | 70 bool added); |
| 90 | 71 |
| 91 // 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 |
| 92 // by BluetoothRemoteGattCharacteristicBlueZ instances to notify service | 73 // by BluetoothRemoteGattCharacteristicBlueZ instances to notify service |
| 93 // observers. | 74 // observers. |
| 94 void NotifyDescriptorValueChanged( | 75 void NotifyDescriptorValueChanged( |
| 95 BluetoothRemoteGattCharacteristicBlueZ* characteristic, | 76 BluetoothRemoteGattCharacteristicBlueZ* characteristic, |
| 96 BluetoothRemoteGattDescriptorBlueZ* descriptor, | 77 BluetoothGattDescriptorBlueZ* descriptor, |
| 97 const std::vector<uint8_t>& value); | 78 const std::vector<uint8_t>& value); |
| 98 | 79 |
| 99 private: | 80 private: |
| 100 friend class BluetoothDeviceBlueZ; | 81 friend class BluetoothDeviceBlueZ; |
| 101 | 82 |
| 102 typedef std::map<dbus::ObjectPath, BluetoothRemoteGattCharacteristicBlueZ*> | |
| 103 CharacteristicMap; | |
| 104 | |
| 105 BluetoothRemoteGattServiceBlueZ(BluetoothAdapterBlueZ* adapter, | 83 BluetoothRemoteGattServiceBlueZ(BluetoothAdapterBlueZ* adapter, |
| 106 BluetoothDeviceBlueZ* device, | 84 BluetoothDeviceBlueZ* device, |
| 107 const dbus::ObjectPath& object_path); | 85 const dbus::ObjectPath& object_path); |
| 108 ~BluetoothRemoteGattServiceBlueZ() override; | 86 ~BluetoothRemoteGattServiceBlueZ() override; |
| 109 | 87 |
| 110 // bluez::BluetoothGattServiceClient::Observer override. | 88 // bluez::BluetoothGattServiceClient::Observer override. |
| 111 void GattServicePropertyChanged(const dbus::ObjectPath& object_path, | 89 void GattServicePropertyChanged(const dbus::ObjectPath& object_path, |
| 112 const std::string& property_name) override; | 90 const std::string& property_name) override; |
| 113 | 91 |
| 114 // bluez::BluetoothGattCharacteristicClient::Observer override. | 92 // bluez::BluetoothGattCharacteristicClient::Observer override. |
| 115 void GattCharacteristicAdded(const dbus::ObjectPath& object_path) override; | 93 void GattCharacteristicAdded(const dbus::ObjectPath& object_path) override; |
| 116 void GattCharacteristicRemoved(const dbus::ObjectPath& object_path) override; | 94 void GattCharacteristicRemoved(const dbus::ObjectPath& object_path) override; |
| 117 void GattCharacteristicPropertyChanged( | 95 void GattCharacteristicPropertyChanged( |
| 118 const dbus::ObjectPath& object_path, | 96 const dbus::ObjectPath& object_path, |
| 119 const std::string& property_name) override; | 97 const std::string& property_name) override; |
| 120 | 98 |
| 121 // Object path of the GATT service. | |
| 122 dbus::ObjectPath object_path_; | |
| 123 | |
| 124 // The adapter associated with this service. It's ok to store a raw pointer | |
| 125 // here since |adapter_| indirectly owns this instance. | |
| 126 BluetoothAdapterBlueZ* adapter_; | |
| 127 | |
| 128 // 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 |
| 129 // here since |device_| owns this instance. | 100 // here since |device_| owns this instance. |
| 130 BluetoothDeviceBlueZ* device_; | 101 BluetoothDeviceBlueZ* device_; |
| 131 | 102 |
| 132 // Mapping from GATT characteristic object paths to characteristic objects. | |
| 133 // owned by this service. Since the BlueZ implementation uses object | |
| 134 // paths as unique identifiers, we also use this mapping to return | |
| 135 // characteristics by identifier. | |
| 136 CharacteristicMap characteristics_; | |
| 137 | |
| 138 // Indicates whether or not the characteristics of this service are known to | 103 // Indicates whether or not the characteristics of this service are known to |
| 139 // have been discovered. | 104 // have been discovered. |
| 140 bool discovery_complete_; | 105 bool discovery_complete_; |
| 141 | 106 |
| 142 // Note: This should remain the last member so it'll be destroyed and | 107 // Note: This should remain the last member so it'll be destroyed and |
| 143 // invalidate its weak pointers before any other members are destroyed. | 108 // invalidate its weak pointers before any other members are destroyed. |
| 144 base::WeakPtrFactory<BluetoothRemoteGattServiceBlueZ> weak_ptr_factory_; | 109 base::WeakPtrFactory<BluetoothRemoteGattServiceBlueZ> weak_ptr_factory_; |
| 145 | 110 |
| 146 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattServiceBlueZ); | 111 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattServiceBlueZ); |
| 147 }; | 112 }; |
| 148 | 113 |
| 149 } // namespace bluez | 114 } // namespace bluez |
| 150 | 115 |
| 151 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_BLUEZ_H_ | 116 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_BLUEZ_H_ |
| OLD | NEW |