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_BLUEZ_BLUETOOTH_GATT_SERVICE_BLUEZ_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_GATT_SERVICE_BLUEZ_H_ |
6 #define DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_GATT_SERVICE_BLUEZ_H_ | 6 #define DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_GATT_SERVICE_BLUEZ_H_ |
7 | 7 |
8 #include <map> | 8 #include <cstdint> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
| 12 #include "base/callback_forward.h" |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "dbus/object_path.h" | 14 #include "dbus/object_path.h" |
14 #include "device/bluetooth/bluetooth_gatt_service.h" | 15 #include "device/bluetooth/bluetooth_local_gatt_service.h" |
15 | 16 |
16 namespace bluez { | 17 namespace bluez { |
17 | 18 |
18 class BluetoothAdapterBlueZ; | 19 class BluetoothAdapterBlueZ; |
19 class BluetoothDeviceBlueZ; | 20 class BluetoothDeviceBlueZ; |
20 | 21 |
21 // The BluetoothGattServiceBlueZ class implements BluetootGattService | 22 // The BluetoothGattServiceBlueZ class implements BluetootGattService |
22 // for GATT services on platforms that use BlueZ. | 23 // for GATT services on platforms that use BlueZ. |
23 class BluetoothGattServiceBlueZ : public virtual device::BluetoothGattService { | 24 class BluetoothGattServiceBlueZ : public virtual device::BluetoothGattService { |
24 public: | 25 public: |
| 26 // A simpler interface for reacting to GATT attribute value requests by the |
| 27 // DBus attribute service providers. |
| 28 class AttributeValueDelegate { |
| 29 public: |
| 30 virtual ~AttributeValueDelegate() {} |
| 31 |
| 32 // This method will be called when a remote device requests to read the |
| 33 // value of the exported GATT attribute. Invoke |callback| with a value |
| 34 // to return that value to the requester. Invoke |error_callback| to report |
| 35 // a failure to read the value. This can happen, for example, if the |
| 36 // attribute has no read permission set. Either callback should be |
| 37 // invoked after a reasonable amount of time, since the request will time |
| 38 // out if left pending for too long causing a disconnection. |
| 39 virtual void GetValue( |
| 40 const device::BluetoothLocalGattService::Delegate::ValueCallback& |
| 41 callback, |
| 42 const device::BluetoothLocalGattService::Delegate::ErrorCallback& |
| 43 error_callback) = 0; |
| 44 |
| 45 // This method will be called, when a remote device requests to write the |
| 46 // value of the exported GATT attribute. Invoke |callback| to report |
| 47 // that the value was successfully written. Invoke |error_callback| to |
| 48 // report a failure to write the value. This can happen, for example, if the |
| 49 // attribute has no write permission set. Either callback should be |
| 50 // invoked after a reasonable amount of time, since the request will time |
| 51 // out if left pending for too long causing a disconnection. |
| 52 virtual void SetValue( |
| 53 const std::vector<uint8_t>& value, |
| 54 const base::Closure& callback, |
| 55 const device::BluetoothLocalGattService::Delegate::ErrorCallback& |
| 56 error_callback) = 0; |
| 57 }; |
| 58 |
25 // device::BluetoothGattService overrides. | 59 // device::BluetoothGattService overrides. |
26 std::string GetIdentifier() const override; | 60 std::string GetIdentifier() const override; |
27 | 61 |
28 // Object path of the underlying service. | 62 // Object path of the underlying service. |
29 const dbus::ObjectPath& object_path() const { return object_path_; } | 63 const dbus::ObjectPath& object_path() const { return object_path_; } |
30 | 64 |
31 // Parses a named D-Bus error into a service error code. | 65 // Parses a named D-Bus error into a service error code. |
32 static device::BluetoothGattService::GattErrorCode DBusErrorToServiceError( | 66 static device::BluetoothGattService::GattErrorCode DBusErrorToServiceError( |
33 const std::string error_name); | 67 const std::string error_name); |
34 | 68 |
35 // Returns the adapter associated with this service. | 69 // Returns the adapter associated with this service. |
36 BluetoothAdapterBlueZ* GetAdapter() const; | 70 BluetoothAdapterBlueZ* GetAdapter() const; |
37 | 71 |
| 72 dbus::ObjectPath GenerateAttributeObjectPath( |
| 73 const std::string attribute_type); |
| 74 |
38 protected: | 75 protected: |
39 explicit BluetoothGattServiceBlueZ(BluetoothAdapterBlueZ* adapter); | 76 explicit BluetoothGattServiceBlueZ(BluetoothAdapterBlueZ* adapter); |
40 ~BluetoothGattServiceBlueZ() override; | 77 ~BluetoothGattServiceBlueZ() override; |
41 | 78 |
42 // Object path of the GATT service. | 79 // Object path of the GATT service. |
43 dbus::ObjectPath object_path_; | 80 dbus::ObjectPath object_path_; |
44 | 81 |
45 private: | 82 private: |
46 friend class BluetoothDeviceBlueZ; | 83 friend class BluetoothDeviceBlueZ; |
47 | 84 |
48 // The adapter associated with this service. It's ok to store a raw pointer | 85 // The adapter associated with this service. It's ok to store a raw pointer |
49 // here since |adapter_| indirectly owns this instance. | 86 // here since |adapter_| indirectly owns this instance. |
50 BluetoothAdapterBlueZ* adapter_; | 87 BluetoothAdapterBlueZ* adapter_; |
51 | 88 |
52 DISALLOW_COPY_AND_ASSIGN(BluetoothGattServiceBlueZ); | 89 DISALLOW_COPY_AND_ASSIGN(BluetoothGattServiceBlueZ); |
53 }; | 90 }; |
54 | 91 |
55 } // namespace bluez | 92 } // namespace bluez |
56 | 93 |
57 #endif // DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_GATT_SERVICE_BLUEZ_H_ | 94 #endif // DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_GATT_SERVICE_BLUEZ_H_ |
OLD | NEW |