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_LOCAL_GATT_SERVICE_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_LOCAL_GATT_SERVICE_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_LOCAL_GATT_SERVICE_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_LOCAL_GATT_SERVICE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 26 matching lines...) Expand all Loading... | |
37 // their gatt service class, hence causing an inheritance diamond. | 37 // their gatt service class, hence causing an inheritance diamond. |
38 class DEVICE_BLUETOOTH_EXPORT BluetoothLocalGattService | 38 class DEVICE_BLUETOOTH_EXPORT BluetoothLocalGattService |
39 : public virtual BluetoothGattService { | 39 : public virtual BluetoothGattService { |
40 public: | 40 public: |
41 // The Delegate class is used to send certain events that need to be handled | 41 // The Delegate class is used to send certain events that need to be handled |
42 // when the device is in peripheral mode. The delegate handles read and write | 42 // when the device is in peripheral mode. The delegate handles read and write |
43 // requests that are issued from remote clients. | 43 // requests that are issued from remote clients. |
44 class Delegate { | 44 class Delegate { |
45 public: | 45 public: |
46 // Callbacks used for communicating GATT request responses. | 46 // Callbacks used for communicating GATT request responses. |
47 typedef base::Callback<void(const std::vector<uint8_t>)> ValueCallback; | 47 typedef base::Callback<void(const std::vector<uint8_t>&)> ValueCallback; |
48 typedef base::Closure ErrorCallback; | 48 typedef base::Closure ErrorCallback; |
49 | 49 |
50 // Called when a remote device in the central role requests to read the | 50 // Called when a remote device in the central role requests to read the |
51 // value of the characteristic |characteristic| starting at offset |offset|. | 51 // value of the characteristic |characteristic| starting at offset |offset|. |
52 // This method is only called if the characteristic was specified as | 52 // This method is only called if the characteristic was specified as |
53 // readable and any authentication and authorization challenges were | 53 // readable and any authentication and authorization challenges were |
54 // satisfied by the remote device. | 54 // satisfied by the remote device. |
55 // | 55 // |
56 // To respond to the request with success and return the requested value, | 56 // To respond to the request with success and return the requested value, |
57 // the delegate must invoke |callback| with the value. Doing so will | 57 // the delegate must invoke |callback| with the value. Doing so will |
58 // automatically update the value property of |characteristic|. To respond | 58 // automatically update the value property of |characteristic|. To respond |
59 // to the request with failure (e.g. if an invalid offset was given), | 59 // to the request with failure (e.g. if an invalid offset was given), |
60 // delegates must invoke |error_callback|. If neither callback parameter is | 60 // delegates must invoke |error_callback|. If neither callback parameter is |
61 // invoked, the request will time out and result in an error. Therefore, | 61 // invoked, the request will time out and result in an error. Therefore, |
62 // delegates MUST invoke either |callback| or |error_callback|. | 62 // delegates MUST invoke either |callback| or |error_callback|. |
63 virtual void OnCharacteristicReadRequest( | 63 virtual void OnCharacteristicReadRequest( |
64 const BluetoothLocalGattService* service, | 64 const BluetoothLocalGattService* service, |
65 const BluetoothLocalGattCharacteristic* characteristic, | 65 const BluetoothLocalGattCharacteristic* characteristic, |
66 int offset, | 66 int offset, |
67 const ValueCallback& callback, | 67 const ValueCallback& callback, |
68 const ErrorCallback& error_callback) = 0; | 68 const ErrorCallback& error_callback) = 0; |
69 | 69 |
70 // Called when a remote device in the central role requests to write the | 70 // Called when a remote device in the central role requests to write the |
71 // value of the characteristic |characteristic| starting at offset |offset|. | 71 // value of the characteristic |characteristic| starting at offset |offset|. |
72 // This method is only called if the characteristic was specified as | 72 // This method is only called if the characteristic was specified as |
73 // writable and any authentication and authorization challenges were | 73 // writable and any authentication and authorization challenges were |
74 // satisfied by the remote device. | 74 // satisfied by the remote device. |
75 // | 75 // |
76 // To respond to the request with success the delegate must invoke | 76 // To respond to the request with success the delegate must invoke |
77 // |callback| with the new value of the characteristic. Doing so will | 77 // |callback| with the new value of the characteristic. Doing so will |
scheib
2016/04/28 01:06:24
You've changed the callback to Closure instead of
rkc
2016/04/28 02:06:57
Fixed the comments. Nothing should be using ValueC
| |
78 // automatically update the value property of |characteristic|. To respond | 78 // automatically update the value property of |characteristic|. To respond |
79 // to the request with failure (e.g. if an invalid offset was given), | 79 // to the request with failure (e.g. if an invalid offset was given), |
80 // delegates must invoke |error_callback|. If neither callback parameter is | 80 // delegates must invoke |error_callback|. If neither callback parameter is |
81 // invoked, the request will time out and result in an error. Therefore, | 81 // invoked, the request will time out and result in an error. Therefore, |
82 // delegates MUST invoke either |callback| or |error_callback|. | 82 // delegates MUST invoke either |callback| or |error_callback|. |
83 virtual void OnCharacteristicWriteRequest( | 83 virtual void OnCharacteristicWriteRequest( |
84 const BluetoothLocalGattService* service, | 84 const BluetoothLocalGattService* service, |
85 const BluetoothLocalGattCharacteristic* characteristic, | 85 const BluetoothLocalGattCharacteristic* characteristic, |
86 const std::vector<uint8_t>& value, | 86 const std::vector<uint8_t>& value, |
87 int offset, | 87 int offset, |
88 const ValueCallback& callback, | 88 const base::Closure& callback, |
89 const ErrorCallback& error_callback) = 0; | 89 const ErrorCallback& error_callback) = 0; |
90 | 90 |
91 // Called when a remote device in the central role requests to read the | 91 // Called when a remote device in the central role requests to read the |
92 // value of the descriptor |descriptor| starting at offset |offset|. | 92 // value of the descriptor |descriptor| starting at offset |offset|. |
93 // This method is only called if the characteristic was specified as | 93 // This method is only called if the characteristic was specified as |
94 // readable and any authentication and authorization challenges were | 94 // readable and any authentication and authorization challenges were |
95 // satisfied by the remote device. | 95 // satisfied by the remote device. |
96 // | 96 // |
97 // To respond to the request with success and return the requested value, | 97 // To respond to the request with success and return the requested value, |
98 // the delegate must invoke |callback| with the value. Doing so will | 98 // the delegate must invoke |callback| with the value. Doing so will |
(...skipping 20 matching lines...) Expand all Loading... | |
119 // automatically update the value property of |descriptor|. To respond | 119 // automatically update the value property of |descriptor|. To respond |
120 // to the request with failure (e.g. if an invalid offset was given), | 120 // to the request with failure (e.g. if an invalid offset was given), |
121 // delegates must invoke |error_callback|. If neither callback parameter is | 121 // delegates must invoke |error_callback|. If neither callback parameter is |
122 // invoked, the request will time out and result in an error. Therefore, | 122 // invoked, the request will time out and result in an error. Therefore, |
123 // delegates MUST invoke either |callback| or |error_callback|. | 123 // delegates MUST invoke either |callback| or |error_callback|. |
124 virtual void OnDescriptorWriteRequest( | 124 virtual void OnDescriptorWriteRequest( |
125 const BluetoothLocalGattService* service, | 125 const BluetoothLocalGattService* service, |
126 const BluetoothLocalGattDescriptor* descriptor, | 126 const BluetoothLocalGattDescriptor* descriptor, |
127 const std::vector<uint8_t>& value, | 127 const std::vector<uint8_t>& value, |
128 int offset, | 128 int offset, |
129 const ValueCallback& callback, | 129 const base::Closure& callback, |
130 const ErrorCallback& error_callback) = 0; | 130 const ErrorCallback& error_callback) = 0; |
131 }; | 131 }; |
132 | 132 |
133 // Creates a local GATT service to be used with |adapter| (which will own | 133 // Creates a local GATT service to be used with |adapter| (which will own |
134 // the created service object). A service can register or unregister itself | 134 // the created service object). A service can register or unregister itself |
135 // at any time by calling its Register/Unregister methods. |delegate| | 135 // at any time by calling its Register/Unregister methods. |delegate| |
136 // receives read/write requests for characteristic/descriptor values. It | 136 // receives read/write requests for characteristic/descriptor values. It |
137 // needs to outlive this object. | 137 // needs to outlive this object. |
138 // TODO(rkc): Implement included services. | 138 // TODO(rkc): Implement included services. |
139 static base::WeakPtr<BluetoothLocalGattService> Create( | 139 static base::WeakPtr<BluetoothLocalGattService> Create( |
(...skipping 18 matching lines...) Expand all Loading... | |
158 BluetoothLocalGattService(); | 158 BluetoothLocalGattService(); |
159 ~BluetoothLocalGattService() override; | 159 ~BluetoothLocalGattService() override; |
160 | 160 |
161 private: | 161 private: |
162 DISALLOW_COPY_AND_ASSIGN(BluetoothLocalGattService); | 162 DISALLOW_COPY_AND_ASSIGN(BluetoothLocalGattService); |
163 }; | 163 }; |
164 | 164 |
165 } // namespace device | 165 } // namespace device |
166 | 166 |
167 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOCAL_GATT_SERVICE_H_ | 167 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOCAL_GATT_SERVICE_H_ |
OLD | NEW |