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_BLUETOOTH_GATT_SERVICE_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_GATT_SERVICE_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_GATT_SERVICE_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_GATT_SERVICE_H_ |
7 | 7 |
| 8 #include <stdint.h> |
| 9 |
8 #include <vector> | 10 #include <vector> |
9 | 11 |
10 #include "base/basictypes.h" | |
11 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/macros.h" |
12 #include "device/bluetooth/bluetooth_export.h" | 14 #include "device/bluetooth/bluetooth_export.h" |
13 #include "device/bluetooth/bluetooth_uuid.h" | 15 #include "device/bluetooth/bluetooth_uuid.h" |
14 | 16 |
15 namespace device { | 17 namespace device { |
16 | 18 |
17 class BluetoothDevice; | 19 class BluetoothDevice; |
18 class BluetoothGattCharacteristic; | 20 class BluetoothGattCharacteristic; |
19 class BluetoothGattDescriptor; | 21 class BluetoothGattDescriptor; |
20 | 22 |
21 // BluetoothGattService represents a local or remote GATT service. A GATT | 23 // BluetoothGattService represents a local or remote GATT service. A GATT |
(...skipping 11 matching lines...) Expand all Loading... |
33 // constructed directly and registered. Once registered, a GATT attribute | 35 // constructed directly and registered. Once registered, a GATT attribute |
34 // hierarchy will be visible to remote devices in the "central" role. | 36 // hierarchy will be visible to remote devices in the "central" role. |
35 class DEVICE_BLUETOOTH_EXPORT BluetoothGattService { | 37 class DEVICE_BLUETOOTH_EXPORT BluetoothGattService { |
36 public: | 38 public: |
37 // The Delegate class is used to send certain events that need to be handled | 39 // The Delegate class is used to send certain events that need to be handled |
38 // when the device is in peripheral mode. The delegate handles read and write | 40 // when the device is in peripheral mode. The delegate handles read and write |
39 // requests that are issued from remote clients. | 41 // requests that are issued from remote clients. |
40 class Delegate { | 42 class Delegate { |
41 public: | 43 public: |
42 // Callbacks used for communicating GATT request responses. | 44 // Callbacks used for communicating GATT request responses. |
43 typedef base::Callback<void(const std::vector<uint8>)> ValueCallback; | 45 typedef base::Callback<void(const std::vector<uint8_t>)> ValueCallback; |
44 typedef base::Closure ErrorCallback; | 46 typedef base::Closure ErrorCallback; |
45 | 47 |
46 // Called when a remote device in the central role requests to read the | 48 // Called when a remote device in the central role requests to read the |
47 // value of the characteristic |characteristic| starting at offset |offset|. | 49 // value of the characteristic |characteristic| starting at offset |offset|. |
48 // This method is only called if the characteristic was specified as | 50 // This method is only called if the characteristic was specified as |
49 // readable and any authentication and authorization challenges were | 51 // readable and any authentication and authorization challenges were |
50 // satisfied by the remote device. | 52 // satisfied by the remote device. |
51 // | 53 // |
52 // To respond to the request with success and return the requested value, | 54 // To respond to the request with success and return the requested value, |
53 // the delegate must invoke |callback| with the value. Doing so will | 55 // the delegate must invoke |callback| with the value. Doing so will |
(...skipping 18 matching lines...) Expand all Loading... |
72 // To respond to the request with success the delegate must invoke | 74 // To respond to the request with success the delegate must invoke |
73 // |callback| with the new value of the characteristic. Doing so will | 75 // |callback| with the new value of the characteristic. Doing so will |
74 // automatically update the value property of |characteristic|. To respond | 76 // automatically update the value property of |characteristic|. To respond |
75 // to the request with failure (e.g. if an invalid offset was given), | 77 // to the request with failure (e.g. if an invalid offset was given), |
76 // delegates must invoke |error_callback|. If neither callback parameter is | 78 // delegates must invoke |error_callback|. If neither callback parameter is |
77 // invoked, the request will time out and result in an error. Therefore, | 79 // invoked, the request will time out and result in an error. Therefore, |
78 // delegates MUST invoke either |callback| or |error_callback|. | 80 // delegates MUST invoke either |callback| or |error_callback|. |
79 virtual void OnCharacteristicWriteRequest( | 81 virtual void OnCharacteristicWriteRequest( |
80 const BluetoothGattService* service, | 82 const BluetoothGattService* service, |
81 const BluetoothGattCharacteristic* characteristic, | 83 const BluetoothGattCharacteristic* characteristic, |
82 const std::vector<uint8>& value, | 84 const std::vector<uint8_t>& value, |
83 int offset, | 85 int offset, |
84 const ValueCallback& callback, | 86 const ValueCallback& callback, |
85 const ErrorCallback& error_callback) = 0; | 87 const ErrorCallback& error_callback) = 0; |
86 | 88 |
87 // Called when a remote device in the central role requests to read the | 89 // Called when a remote device in the central role requests to read the |
88 // value of the descriptor |descriptor| starting at offset |offset|. | 90 // value of the descriptor |descriptor| starting at offset |offset|. |
89 // This method is only called if the characteristic was specified as | 91 // This method is only called if the characteristic was specified as |
90 // readable and any authentication and authorization challenges were | 92 // readable and any authentication and authorization challenges were |
91 // satisfied by the remote device. | 93 // satisfied by the remote device. |
92 // | 94 // |
(...skipping 20 matching lines...) Expand all Loading... |
113 // To respond to the request with success the delegate must invoke | 115 // To respond to the request with success the delegate must invoke |
114 // |callback| with the new value of the descriptor. Doing so will | 116 // |callback| with the new value of the descriptor. Doing so will |
115 // automatically update the value property of |descriptor|. To respond | 117 // automatically update the value property of |descriptor|. To respond |
116 // to the request with failure (e.g. if an invalid offset was given), | 118 // to the request with failure (e.g. if an invalid offset was given), |
117 // delegates must invoke |error_callback|. If neither callback parameter is | 119 // delegates must invoke |error_callback|. If neither callback parameter is |
118 // invoked, the request will time out and result in an error. Therefore, | 120 // invoked, the request will time out and result in an error. Therefore, |
119 // delegates MUST invoke either |callback| or |error_callback|. | 121 // delegates MUST invoke either |callback| or |error_callback|. |
120 virtual void OnDescriptorWriteRequest( | 122 virtual void OnDescriptorWriteRequest( |
121 const BluetoothGattService* service, | 123 const BluetoothGattService* service, |
122 const BluetoothGattDescriptor* descriptor, | 124 const BluetoothGattDescriptor* descriptor, |
123 const std::vector<uint8>& value, | 125 const std::vector<uint8_t>& value, |
124 int offset, | 126 int offset, |
125 const ValueCallback& callback, | 127 const ValueCallback& callback, |
126 const ErrorCallback& error_callback) = 0; | 128 const ErrorCallback& error_callback) = 0; |
127 }; | 129 }; |
128 | 130 |
129 // Interacting with Characteristics and Descriptors can produce | 131 // Interacting with Characteristics and Descriptors can produce |
130 // this set of errors. | 132 // this set of errors. |
131 enum GattErrorCode { | 133 enum GattErrorCode { |
132 GATT_ERROR_UNKNOWN = 0, | 134 GATT_ERROR_UNKNOWN = 0, |
133 GATT_ERROR_FAILED, | 135 GATT_ERROR_FAILED, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 protected: | 223 protected: |
222 BluetoothGattService(); | 224 BluetoothGattService(); |
223 | 225 |
224 private: | 226 private: |
225 DISALLOW_COPY_AND_ASSIGN(BluetoothGattService); | 227 DISALLOW_COPY_AND_ASSIGN(BluetoothGattService); |
226 }; | 228 }; |
227 | 229 |
228 } // namespace device | 230 } // namespace device |
229 | 231 |
230 #endif // DEVICE_BLUETOOTH_BLUETOOTH_GATT_SERVICE_H_ | 232 #endif // DEVICE_BLUETOOTH_BLUETOOTH_GATT_SERVICE_H_ |
OLD | NEW |