OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_CHARACTERISTIC_SERVICE_PROVIDER_H_ | 5 #ifndef DEVICE_BLUETOOTH_DBUS_BLUETOOTH_GATT_CHARACTERISTIC_SERVICE_PROVIDER_H_ |
6 #define DEVICE_BLUETOOTH_DBUS_BLUETOOTH_GATT_CHARACTERISTIC_SERVICE_PROVIDER_H_ | 6 #define DEVICE_BLUETOOTH_DBUS_BLUETOOTH_GATT_CHARACTERISTIC_SERVICE_PROVIDER_H_ |
7 | 7 |
| 8 #include <stdint.h> |
| 9 |
8 #include <string> | 10 #include <string> |
9 #include <vector> | 11 #include <vector> |
10 | 12 |
11 #include "base/basictypes.h" | |
12 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/macros.h" |
13 #include "dbus/bus.h" | 15 #include "dbus/bus.h" |
14 #include "dbus/object_path.h" | 16 #include "dbus/object_path.h" |
15 #include "device/bluetooth/bluetooth_export.h" | 17 #include "device/bluetooth/bluetooth_export.h" |
16 | 18 |
17 namespace bluez { | 19 namespace bluez { |
18 | 20 |
19 // BluetoothGattCharacteristicServiceProvider is used to provide a D-Bus object | 21 // BluetoothGattCharacteristicServiceProvider is used to provide a D-Bus object |
20 // that represents a local GATT characteristic that the Bluetooth daemon can | 22 // that represents a local GATT characteristic that the Bluetooth daemon can |
21 // communicate with. | 23 // communicate with. |
22 // | 24 // |
23 // Instantiate with a chosen D-Bus object path, delegate, and other fields. | 25 // Instantiate with a chosen D-Bus object path, delegate, and other fields. |
24 // The Bluetooth daemon communicates with a GATT characteristic using the | 26 // The Bluetooth daemon communicates with a GATT characteristic using the |
25 // standard DBus.Properties interface. While most properties of the GATT | 27 // standard DBus.Properties interface. While most properties of the GATT |
26 // characteristic interface are read-only and don't change throughout the | 28 // characteristic interface are read-only and don't change throughout the |
27 // life-time of the object, the "Value" property is both writeable and its | 29 // life-time of the object, the "Value" property is both writeable and its |
28 // value can change. Both Get and Set operations performed on the "Value" | 30 // value can change. Both Get and Set operations performed on the "Value" |
29 // property are delegated to the Delegate object, an instance of which is | 31 // property are delegated to the Delegate object, an instance of which is |
30 // mandatory during initialization. In addition, a "SendValueChanged" method is | 32 // mandatory during initialization. In addition, a "SendValueChanged" method is |
31 // provided, which emits a DBus.Properties.PropertyChanged signal for the | 33 // provided, which emits a DBus.Properties.PropertyChanged signal for the |
32 // "Value" property. | 34 // "Value" property. |
33 class DEVICE_BLUETOOTH_EXPORT BluetoothGattCharacteristicServiceProvider { | 35 class DEVICE_BLUETOOTH_EXPORT BluetoothGattCharacteristicServiceProvider { |
34 public: | 36 public: |
35 // Interface for reacting to GATT characteristic value requests. | 37 // Interface for reacting to GATT characteristic value requests. |
36 class Delegate { | 38 class Delegate { |
37 public: | 39 public: |
38 virtual ~Delegate() {} | 40 virtual ~Delegate() {} |
39 | 41 |
40 // ValueCallback is used for methods that require a characteristic value | 42 // ValueCallback is used for methods that require a characteristic value |
41 // to be returned. | 43 // to be returned. |
42 typedef base::Callback<void(const std::vector<uint8>&)> ValueCallback; | 44 typedef base::Callback<void(const std::vector<uint8_t>&)> ValueCallback; |
43 | 45 |
44 // ErrorCallback is used by methods to report failure. | 46 // ErrorCallback is used by methods to report failure. |
45 typedef base::Closure ErrorCallback; | 47 typedef base::Closure ErrorCallback; |
46 | 48 |
47 // This method will be called when a remote device requests to read the | 49 // This method will be called when a remote device requests to read the |
48 // value of the exported GATT characteristic. Invoke |callback| with a value | 50 // value of the exported GATT characteristic. Invoke |callback| with a value |
49 // to return that value to the requester. Invoke |error_callback| to report | 51 // to return that value to the requester. Invoke |error_callback| to report |
50 // a failure to read the value. This can happen, for example, if the | 52 // a failure to read the value. This can happen, for example, if the |
51 // characteristic has no read permission set. Either callback should be | 53 // characteristic has no read permission set. Either callback should be |
52 // invoked after a reasonable amount of time, since the request will time | 54 // invoked after a reasonable amount of time, since the request will time |
53 // out if left pending for too long. | 55 // out if left pending for too long. |
54 virtual void GetCharacteristicValue( | 56 virtual void GetCharacteristicValue( |
55 const ValueCallback& callback, | 57 const ValueCallback& callback, |
56 const ErrorCallback& error_callback) = 0; | 58 const ErrorCallback& error_callback) = 0; |
57 | 59 |
58 // This method will be called, when a remote device requests to write the | 60 // This method will be called, when a remote device requests to write the |
59 // value of the exported GATT characteristic. Invoke |callback| to report | 61 // value of the exported GATT characteristic. Invoke |callback| to report |
60 // that the value was successfully written. Invoke |error_callback| to | 62 // that the value was successfully written. Invoke |error_callback| to |
61 // report a failure to write the value. This can happen, for example, if the | 63 // report a failure to write the value. This can happen, for example, if the |
62 // characteristic has no write permission set. Either callback should be | 64 // characteristic has no write permission set. Either callback should be |
63 // invoked after a reasonable amount of time, since the request will time | 65 // invoked after a reasonable amount of time, since the request will time |
64 // out if left pending for too long. | 66 // out if left pending for too long. |
65 // | 67 // |
66 // The delegate should use this method to perform any side-effects that may | 68 // The delegate should use this method to perform any side-effects that may |
67 // occur based on the set value and potentially send a property changed | 69 // occur based on the set value and potentially send a property changed |
68 // signal to notify the Bluetooth daemon that the value has changed. | 70 // signal to notify the Bluetooth daemon that the value has changed. |
69 virtual void SetCharacteristicValue( | 71 virtual void SetCharacteristicValue( |
70 const std::vector<uint8>& value, | 72 const std::vector<uint8_t>& value, |
71 const base::Closure& callback, | 73 const base::Closure& callback, |
72 const ErrorCallback& error_callback) = 0; | 74 const ErrorCallback& error_callback) = 0; |
73 }; | 75 }; |
74 | 76 |
75 virtual ~BluetoothGattCharacteristicServiceProvider(); | 77 virtual ~BluetoothGattCharacteristicServiceProvider(); |
76 | 78 |
77 // Send a PropertyChanged signal to notify the Bluetooth daemon that the value | 79 // Send a PropertyChanged signal to notify the Bluetooth daemon that the value |
78 // of the "Value" property has changed to |value|. | 80 // of the "Value" property has changed to |value|. |
79 virtual void SendValueChanged(const std::vector<uint8>& value) = 0; | 81 virtual void SendValueChanged(const std::vector<uint8_t>& value) = 0; |
80 | 82 |
81 // Creates the instance, where |bus| is the D-Bus bus connection to export | 83 // Creates the instance, where |bus| is the D-Bus bus connection to export |
82 // the object onto, |uuid| is the 128-bit GATT characteristic UUID, | 84 // the object onto, |uuid| is the 128-bit GATT characteristic UUID, |
83 // |flags| is the list of GATT characteristic properties, |permissions| is the | 85 // |flags| is the list of GATT characteristic properties, |permissions| is the |
84 // list of attribute permissions, |service_path| is the object path of the | 86 // list of attribute permissions, |service_path| is the object path of the |
85 // exported GATT service the characteristic belongs to, |object_path| is the | 87 // exported GATT service the characteristic belongs to, |object_path| is the |
86 // object path that the characteristic should have, and |delegate| is the | 88 // object path that the characteristic should have, and |delegate| is the |
87 // object that "Value" Get/Set requests will be passed to and responses | 89 // object that "Value" Get/Set requests will be passed to and responses |
88 // generated from. | 90 // generated from. |
89 // | 91 // |
(...skipping 14 matching lines...) Expand all Loading... |
104 protected: | 106 protected: |
105 BluetoothGattCharacteristicServiceProvider(); | 107 BluetoothGattCharacteristicServiceProvider(); |
106 | 108 |
107 private: | 109 private: |
108 DISALLOW_COPY_AND_ASSIGN(BluetoothGattCharacteristicServiceProvider); | 110 DISALLOW_COPY_AND_ASSIGN(BluetoothGattCharacteristicServiceProvider); |
109 }; | 111 }; |
110 | 112 |
111 } // namespace bluez | 113 } // namespace bluez |
112 | 114 |
113 #endif // DEVICE_BLUETOOTH_DBUS_BLUETOOTH_GATT_CHARACTERISTIC_SERVICE_PROVIDER_
H_ | 115 #endif // DEVICE_BLUETOOTH_DBUS_BLUETOOTH_GATT_CHARACTERISTIC_SERVICE_PROVIDER_
H_ |
OLD | NEW |