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_DBUS_BLUETOOTH_GATT_ATTRIBUTE_VALUE_DELEGATE_H_ | 5 #ifndef DEVICE_BLUETOOTH_DBUS_BLUETOOTH_GATT_ATTRIBUTE_VALUE_DELEGATE_H_ |
| 6 #define DEVICE_BLUETOOTH_DBUS_BLUETOOTH_GATT_ATTRIBUTE_VALUE_DELEGATE_H_ | 6 #define DEVICE_BLUETOOTH_DBUS_BLUETOOTH_GATT_ATTRIBUTE_VALUE_DELEGATE_H_ |
| 7 | 7 |
| 8 #include <cstdint> | 8 #include <cstdint> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
| 12 #include "dbus/object_path.h" | |
| 13 #include "device/bluetooth/bluetooth_device.h" | |
|
xiyuan
2016/05/16 22:05:00
nit: move the headers to cc and forward decalre Ob
rkc
2016/05/16 23:19:06
Done.
| |
| 12 #include "device/bluetooth/bluetooth_local_gatt_service.h" | 14 #include "device/bluetooth/bluetooth_local_gatt_service.h" |
| 13 | 15 |
| 14 namespace bluez { | 16 namespace bluez { |
| 15 | 17 |
| 18 class BluetoothLocalGattServiceBlueZ; | |
| 19 | |
| 16 // A simpler interface for reacting to GATT attribute value requests by the | 20 // A simpler interface for reacting to GATT attribute value requests by the |
| 17 // DBus attribute service providers. | 21 // DBus attribute service providers. |
| 18 class BluetoothGattAttributeValueDelegate { | 22 class BluetoothGattAttributeValueDelegate { |
| 19 public: | 23 public: |
| 20 virtual ~BluetoothGattAttributeValueDelegate() {} | 24 explicit BluetoothGattAttributeValueDelegate( |
| 25 BluetoothLocalGattServiceBlueZ* service); | |
| 26 virtual ~BluetoothGattAttributeValueDelegate(); | |
| 21 | 27 |
| 22 // This method will be called when a remote device requests to read the | 28 // This method will be called when a remote device requests to read the |
| 23 // value of the exported GATT attribute. Invoke |callback| with a value | 29 // value of the exported GATT attribute. Invoke |callback| with a value |
| 24 // to return that value to the requester. Invoke |error_callback| to report | 30 // to return that value to the requester. Invoke |error_callback| to report |
| 25 // a failure to read the value. This can happen, for example, if the | 31 // a failure to read the value. This can happen, for example, if the |
| 26 // attribute has no read permission set. Either callback should be | 32 // attribute has no read permission set. Either callback should be |
| 27 // invoked after a reasonable amount of time, since the request will time | 33 // invoked after a reasonable amount of time, since the request will time |
| 28 // out if left pending for too long causing a disconnection. | 34 // out if left pending for too long causing a disconnection. |
| 29 virtual void GetValue( | 35 virtual void GetValue( |
| 36 const dbus::ObjectPath& device_path, | |
| 30 const device::BluetoothLocalGattService::Delegate::ValueCallback& | 37 const device::BluetoothLocalGattService::Delegate::ValueCallback& |
| 31 callback, | 38 callback, |
| 32 const device::BluetoothLocalGattService::Delegate::ErrorCallback& | 39 const device::BluetoothLocalGattService::Delegate::ErrorCallback& |
| 33 error_callback) = 0; | 40 error_callback) = 0; |
| 34 | 41 |
| 35 // This method will be called, when a remote device requests to write the | 42 // This method will be called, when a remote device requests to write the |
| 36 // value of the exported GATT attribute. Invoke |callback| to report | 43 // value of the exported GATT attribute. Invoke |callback| to report |
| 37 // that the value was successfully written. Invoke |error_callback| to | 44 // that the value was successfully written. Invoke |error_callback| to |
| 38 // report a failure to write the value. This can happen, for example, if the | 45 // report a failure to write the value. This can happen, for example, if the |
| 39 // attribute has no write permission set. Either callback should be | 46 // attribute has no write permission set. Either callback should be |
| 40 // invoked after a reasonable amount of time, since the request will time | 47 // invoked after a reasonable amount of time, since the request will time |
| 41 // out if left pending for too long causing a disconnection. | 48 // out if left pending for too long causing a disconnection. |
| 42 virtual void SetValue( | 49 virtual void SetValue( |
| 50 const dbus::ObjectPath& device_path, | |
| 43 const std::vector<uint8_t>& value, | 51 const std::vector<uint8_t>& value, |
| 44 const base::Closure& callback, | 52 const base::Closure& callback, |
| 45 const device::BluetoothLocalGattService::Delegate::ErrorCallback& | 53 const device::BluetoothLocalGattService::Delegate::ErrorCallback& |
| 46 error_callback) = 0; | 54 error_callback) = 0; |
| 47 | 55 |
| 48 // This method will be called, when a remote device requests to start sending | 56 // This method will be called, when a remote device requests to start sending |
| 49 // notifications for this characteristic. This will never be called for | 57 // notifications for this characteristic. This will never be called for |
| 50 // descriptors. | 58 // descriptors. |
| 51 virtual void StartNotifications() = 0; | 59 virtual void StartNotifications() = 0; |
| 52 | 60 |
| 53 // This method will be called, when a remote device requests to stop sending | 61 // This method will be called, when a remote device requests to stop sending |
| 54 // notifications for this characteristic. This will never be called for | 62 // notifications for this characteristic. This will never be called for |
| 55 // descriptors. | 63 // descriptors. |
| 56 virtual void StopNotifications() = 0; | 64 virtual void StopNotifications() = 0; |
| 65 | |
| 66 protected: | |
| 67 // Gets the Bluetooth device object on the current service's adapter with | |
| 68 // the given object path. | |
| 69 device::BluetoothDevice* GetDeviceWithPath( | |
| 70 const dbus::ObjectPath& object_path); | |
| 71 | |
| 72 BluetoothLocalGattServiceBlueZ* service() { return service_; } | |
| 73 | |
| 74 private: | |
| 75 BluetoothLocalGattServiceBlueZ* service_; | |
|
xiyuan
2016/05/16 22:05:00
nit: const ptr since |service_| would not change f
rkc
2016/05/16 23:19:06
Done.
| |
| 57 }; | 76 }; |
|
xiyuan
2016/05/16 22:05:00
nit: DISALLOW_COPY_AND_ASSIGN(...)
rkc
2016/05/16 23:19:06
Done.
| |
| 58 | 77 |
| 59 } // namespace bluez | 78 } // namespace bluez |
| 60 | 79 |
| 61 #endif // DEVICE_BLUETOOTH_DBUS_BLUETOOTH_GATT_ATTRIBUTE_VALUE_DELEGATE_H_ | 80 #endif // DEVICE_BLUETOOTH_DBUS_BLUETOOTH_GATT_ATTRIBUTE_VALUE_DELEGATE_H_ |
| OLD | NEW |