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_SERVICE_BLUEZ_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_GATT_SERVICE_BLUEZ_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_H_ |
7 | 7 |
8 #include <map> | |
9 #include <string> | 8 #include <string> |
10 #include <vector> | 9 #include <vector> |
11 | 10 |
12 #include "base/macros.h" | 11 #include "base/macros.h" |
13 #include "dbus/object_path.h" | 12 #include "device/bluetooth/bluetooth_export.h" |
14 #include "device/bluetooth/bluetooth_gatt_service.h" | 13 #include "device/bluetooth/bluetooth_gatt_service.h" |
| 14 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" |
15 | 15 |
16 namespace device { | 16 namespace device { |
17 | 17 |
18 class BluetoothGattCharacteristic; | 18 class BluetoothDevice; |
| 19 class BluetoothRemoteGattCharacteristic; |
| 20 class BluetoothRemoteGattDescriptor; |
| 21 |
| 22 // BluetoothRemoteGattService represents a remote GATT service. |
| 23 // |
| 24 // Instances of the BluetoothRemoteGATTService class are used to represent GATT |
| 25 // attribute hierarchies that have been received from a |
| 26 // remote Bluetooth GATT peripheral. Such BluetoothRemoteGattService instances |
| 27 // are constructed and owned by a BluetoothDevice. |
| 28 // |
| 29 // Note: We use virtual inheritance on the GATT service since it will be |
| 30 // inherited by platform specific versions of the GATT service classes also. The |
| 31 // platform specific remote GATT service classes will inherit both this class |
| 32 // and their GATT service class, hence causing an inheritance diamond. |
| 33 class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattService |
| 34 : public virtual BluetoothGattService { |
| 35 public: |
| 36 ~BluetoothRemoteGattService() override; |
| 37 |
| 38 // Returns the BluetoothDevice that this GATT service was received from, which |
| 39 // also owns this service. |
| 40 virtual BluetoothDevice* GetDevice() const = 0; |
| 41 |
| 42 // List of characteristics that belong to this service. |
| 43 virtual std::vector<BluetoothRemoteGattCharacteristic*> GetCharacteristics() |
| 44 const = 0; |
| 45 |
| 46 // List of GATT services that are included by this service. |
| 47 virtual std::vector<BluetoothRemoteGattService*> GetIncludedServices() |
| 48 const = 0; |
| 49 |
| 50 // Returns the GATT characteristic with identifier |identifier| if it belongs |
| 51 // to this GATT service. |
| 52 virtual BluetoothRemoteGattCharacteristic* GetCharacteristic( |
| 53 const std::string& identifier) const = 0; |
| 54 |
| 55 protected: |
| 56 BluetoothRemoteGattService(); |
| 57 |
| 58 private: |
| 59 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattService); |
| 60 }; |
19 | 61 |
20 } // namespace device | 62 } // namespace device |
21 | 63 |
22 namespace bluez { | 64 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_H_ |
23 | |
24 class BluetoothAdapterBlueZ; | |
25 class BluetoothDeviceBlueZ; | |
26 class BluetoothGattCharacteristicBlueZ; | |
27 | |
28 // The BluetoothGattServiceBlueZ class implements BluetootGattService | |
29 // for GATT services on platforms that use BlueZ. | |
30 class BluetoothGattServiceBlueZ : public device::BluetoothGattService { | |
31 public: | |
32 // device::BluetoothGattService overrides. | |
33 std::string GetIdentifier() const override; | |
34 std::vector<device::BluetoothGattCharacteristic*> GetCharacteristics() | |
35 const override; | |
36 std::vector<device::BluetoothGattService*> GetIncludedServices() | |
37 const override; | |
38 device::BluetoothGattCharacteristic* GetCharacteristic( | |
39 const std::string& identifier) const override; | |
40 | |
41 // Object path of the underlying service. | |
42 const dbus::ObjectPath& object_path() const { return object_path_; } | |
43 | |
44 // Parses a named D-Bus error into a service error code. | |
45 static device::BluetoothGattService::GattErrorCode DBusErrorToServiceError( | |
46 const std::string error_name); | |
47 | |
48 // Returns the adapter associated with this service. | |
49 BluetoothAdapterBlueZ* GetAdapter() const; | |
50 | |
51 protected: | |
52 BluetoothGattServiceBlueZ(BluetoothAdapterBlueZ* adapter, | |
53 const dbus::ObjectPath& object_path); | |
54 ~BluetoothGattServiceBlueZ() override; | |
55 | |
56 // Does not take ownership of the characteristic object. | |
57 using CharacteristicMap = | |
58 std::map<dbus::ObjectPath, BluetoothGattCharacteristicBlueZ*>; | |
59 | |
60 // Mapping from GATT characteristic object paths to characteristic objects. | |
61 // owned by this service. Since the BlueZ implementation uses object | |
62 // paths as unique identifiers, we also use this mapping to return | |
63 // characteristics by identifier. | |
64 CharacteristicMap characteristics_; | |
65 | |
66 private: | |
67 friend class BluetoothDeviceBlueZ; | |
68 | |
69 // The adapter associated with this service. It's ok to store a raw pointer | |
70 // here since |adapter_| indirectly owns this instance. | |
71 BluetoothAdapterBlueZ* adapter_; | |
72 | |
73 // Object path of the GATT service. | |
74 dbus::ObjectPath object_path_; | |
75 | |
76 DISALLOW_COPY_AND_ASSIGN(BluetoothGattServiceBlueZ); | |
77 }; | |
78 | |
79 } // namespace bluez | |
80 | |
81 #endif // DEVICE_BLUETOOTH_BLUETOOTH_GATT_SERVICE_BLUEZ_H_ | |
OLD | NEW |