Chromium Code Reviews| 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 { | |
|
scheib
2016/04/26 06:03:32
Usually the delegate interface is defined on the c
rkc
2016/04/26 18:23:59
This delegate is used by both characteristics and
scheib
2016/04/27 05:12:59
I see that it is a delegate used by two dbus class
rkc
2016/04/27 19:41:06
Moving to its own class in bluez/dbus.
Done.
| |
| 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 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 48 // The adapter associated with this service. It's ok to store a raw pointer | 82 // The adapter associated with this service. It's ok to store a raw pointer |
| 49 // here since |adapter_| indirectly owns this instance. | 83 // here since |adapter_| indirectly owns this instance. |
| 50 BluetoothAdapterBlueZ* adapter_; | 84 BluetoothAdapterBlueZ* adapter_; |
| 51 | 85 |
| 52 DISALLOW_COPY_AND_ASSIGN(BluetoothGattServiceBlueZ); | 86 DISALLOW_COPY_AND_ASSIGN(BluetoothGattServiceBlueZ); |
| 53 }; | 87 }; |
| 54 | 88 |
| 55 } // namespace bluez | 89 } // namespace bluez |
| 56 | 90 |
| 57 #endif // DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_GATT_SERVICE_BLUEZ_H_ | 91 #endif // DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_GATT_SERVICE_BLUEZ_H_ |
| OLD | NEW |