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_GATT_CHARACTERISTIC_BLUEZ_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_GATT_CHARACTERISTIC_BLUEZ_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_GATT_CHARACTERISTIC_BLUEZ_H_ | 6 #define DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_GATT_CHARACTERISTIC_BLUEZ_H_ |
7 | 7 |
8 #include <map> | |
9 #include <string> | 8 #include <string> |
10 #include <vector> | |
11 | 9 |
12 #include "base/macros.h" | 10 #include "base/macros.h" |
13 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
14 #include "dbus/object_path.h" | 12 #include "dbus/object_path.h" |
15 #include "device/bluetooth/bluetooth_gatt_characteristic.h" | 13 #include "device/bluetooth/bluetooth_gatt_characteristic.h" |
16 | 14 |
17 namespace device { | |
18 | |
19 class BluetoothGattDescriptor; | |
20 class BluetoothGattService; | |
21 | |
22 } // namespace device | |
23 | |
24 namespace bluez { | 15 namespace bluez { |
25 | 16 |
26 class BluetoothGattDescriptorBlueZ; | |
27 class BluetoothGattServiceBlueZ; | |
28 | |
29 // The BluetoothGattCharacteristicBlueZ class implements | 17 // The BluetoothGattCharacteristicBlueZ class implements |
30 // BluetoothGattCharacteristic for GATT characteristics for platforms | 18 // BluetoothRemoteGattCharacteristic for GATT characteristics for platforms |
31 // that use BlueZ. | 19 // that use BlueZ. |
32 class BluetoothGattCharacteristicBlueZ | 20 class BluetoothGattCharacteristicBlueZ |
33 : public device::BluetoothGattCharacteristic { | 21 : public virtual device::BluetoothGattCharacteristic { |
34 public: | 22 public: |
35 // device::BluetoothGattCharacteristic overrides. | 23 // device::BluetoothGattCharacteristic overrides. |
36 std::string GetIdentifier() const override; | 24 std::string GetIdentifier() const override; |
37 device::BluetoothGattService* GetService() const override; | |
38 Permissions GetPermissions() const override; | |
39 std::vector<device::BluetoothGattDescriptor*> GetDescriptors() const override; | |
40 device::BluetoothGattDescriptor* GetDescriptor( | |
41 const std::string& identifier) const override; | |
42 | 25 |
43 // Object path of the underlying D-Bus characteristic. | 26 // Object path of the underlying D-Bus characteristic. |
44 const dbus::ObjectPath& object_path() const { return object_path_; } | 27 const dbus::ObjectPath& object_path() const { return object_path_; } |
45 | 28 |
46 protected: | 29 protected: |
47 BluetoothGattCharacteristicBlueZ(BluetoothGattServiceBlueZ* service, | 30 explicit BluetoothGattCharacteristicBlueZ( |
48 const dbus::ObjectPath& object_path); | 31 const dbus::ObjectPath& object_path); |
49 ~BluetoothGattCharacteristicBlueZ() override; | 32 ~BluetoothGattCharacteristicBlueZ() override; |
50 | 33 |
51 // Does not take ownership of the descriptor object. | |
52 using DescriptorMap = | |
53 std::map<dbus::ObjectPath, BluetoothGattDescriptorBlueZ*>; | |
54 | |
55 // Mapping from GATT descriptor object paths to descriptor objects owned by | |
56 // this characteristic. Since the BlueZ implementation uses object paths | |
57 // as unique identifiers, we also use this mapping to return descriptors by | |
58 // identifier. | |
59 DescriptorMap descriptors_; | |
60 | |
61 // The GATT service this GATT characteristic belongs to. | |
62 BluetoothGattServiceBlueZ* service_; | |
63 | |
64 private: | 34 private: |
65 friend class BluetoothRemoteGattServiceBlueZ; | |
66 | |
67 // Object path of the D-Bus characteristic object. | 35 // Object path of the D-Bus characteristic object. |
68 dbus::ObjectPath object_path_; | 36 dbus::ObjectPath object_path_; |
69 | 37 |
70 // Note: This should remain the last member so it'll be destroyed and | 38 // Note: This should remain the last member so it'll be destroyed and |
71 // invalidate its weak pointers before any other members are destroyed. | 39 // invalidate its weak pointers before any other members are destroyed. |
72 base::WeakPtrFactory<BluetoothGattCharacteristicBlueZ> weak_ptr_factory_; | 40 base::WeakPtrFactory<BluetoothGattCharacteristicBlueZ> weak_ptr_factory_; |
73 | 41 |
74 DISALLOW_COPY_AND_ASSIGN(BluetoothGattCharacteristicBlueZ); | 42 DISALLOW_COPY_AND_ASSIGN(BluetoothGattCharacteristicBlueZ); |
75 }; | 43 }; |
76 | 44 |
77 } // namespace bluez | 45 } // namespace bluez |
78 | 46 |
79 #endif // DEVICE_BLUETOOTH_BLUETOOTH_GATT_CHARACTERISTIC_BLUEZ_H_ | 47 #endif // DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_GATT_CHARACTERISTIC_BLUEZ_H_ |
OLD | NEW |