| 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 29 matching lines...) Expand all Loading... |
| 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 |device| requests to read the value of the |
| 51 // value of the characteristic |characteristic| starting at offset |offset|. | 51 // 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 BluetoothDevice* device, |
| 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 |device| requests to write the value of the |
| 71 // value of the characteristic |characteristic| starting at offset |offset|. | 71 // 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|. To respond to the request with failure delegates must invoke | 77 // |callback|. To respond to the request with failure delegates must invoke |
| 78 // |error_callback|. If neither callback parameter is invoked, the request | 78 // |error_callback|. If neither callback parameter is invoked, the request |
| 79 // will time out and result in an error. Therefore, delegates MUST invoke | 79 // will time out and result in an error. Therefore, delegates MUST invoke |
| 80 // either |callback| or |error_callback|. | 80 // either |callback| or |error_callback|. |
| 81 virtual void OnCharacteristicWriteRequest( | 81 virtual void OnCharacteristicWriteRequest( |
| 82 const BluetoothLocalGattService* service, | 82 const BluetoothDevice* device, |
| 83 const BluetoothLocalGattCharacteristic* characteristic, | 83 const BluetoothLocalGattCharacteristic* characteristic, |
| 84 const std::vector<uint8_t>& value, | 84 const std::vector<uint8_t>& value, |
| 85 int offset, | 85 int offset, |
| 86 const base::Closure& callback, | 86 const base::Closure& callback, |
| 87 const ErrorCallback& error_callback) = 0; | 87 const ErrorCallback& error_callback) = 0; |
| 88 | 88 |
| 89 // Called when a remote device in the central role requests to read the | 89 // Called when a remote device |device| requests to read the value of the |
| 90 // value of the descriptor |descriptor| starting at offset |offset|. | 90 // descriptor |descriptor| starting at offset |offset|. |
| 91 // This method is only called if the characteristic was specified as | 91 // This method is only called if the descriptor was specified as |
| 92 // readable and any authentication and authorization challenges were | 92 // readable and any authentication and authorization challenges were |
| 93 // satisfied by the remote device. | 93 // satisfied by the remote device. |
| 94 // | 94 // |
| 95 // To respond to the request with success and return the requested value, | 95 // To respond to the request with success and return the requested value, |
| 96 // the delegate must invoke |callback| with the value. Doing so will | 96 // the delegate must invoke |callback| with the value. Doing so will |
| 97 // automatically update the value property of |descriptor|. To respond | 97 // automatically update the value property of |descriptor|. To respond |
| 98 // to the request with failure (e.g. if an invalid offset was given), | 98 // to the request with failure (e.g. if an invalid offset was given), |
| 99 // delegates must invoke |error_callback|. If neither callback parameter is | 99 // delegates must invoke |error_callback|. If neither callback parameter is |
| 100 // invoked, the request will time out and result in an error. Therefore, | 100 // invoked, the request will time out and result in an error. Therefore, |
| 101 // delegates MUST invoke either |callback| or |error_callback|. | 101 // delegates MUST invoke either |callback| or |error_callback|. |
| 102 virtual void OnDescriptorReadRequest( | 102 virtual void OnDescriptorReadRequest( |
| 103 const BluetoothLocalGattService* service, | 103 const BluetoothDevice* device, |
| 104 const BluetoothLocalGattDescriptor* descriptor, | 104 const BluetoothLocalGattDescriptor* descriptor, |
| 105 int offset, | 105 int offset, |
| 106 const ValueCallback& callback, | 106 const ValueCallback& callback, |
| 107 const ErrorCallback& error_callback) = 0; | 107 const ErrorCallback& error_callback) = 0; |
| 108 | 108 |
| 109 // Called when a remote device in the central role requests to write the | 109 // Called when a remote device |devie| requests to write the value of the |
| 110 // value of the descriptor |descriptor| starting at offset |offset|. | 110 // descriptor |descriptor| starting at offset |offset|. |
| 111 // This method is only called if the characteristic was specified as | 111 // This method is only called if the descriptor was specified as |
| 112 // writable and any authentication and authorization challenges were | 112 // writable and any authentication and authorization challenges were |
| 113 // satisfied by the remote device. | 113 // satisfied by the remote device. |
| 114 // | 114 // |
| 115 // To respond to the request with success the delegate must invoke | 115 // To respond to the request with success the delegate must invoke |
| 116 // |callback|. To respond to the request with failure delegates must invoke | 116 // |callback|. To respond to the request with failure delegates must invoke |
| 117 // |error_callback|. If neither callback parameter is invoked, the request | 117 // |error_callback|. If neither callback parameter is invoked, the request |
| 118 // will time out and result in an error. Therefore, delegates MUST invoke | 118 // will time out and result in an error. Therefore, delegates MUST invoke |
| 119 // either |callback| or |error_callback|. | 119 // either |callback| or |error_callback|. |
| 120 virtual void OnDescriptorWriteRequest( | 120 virtual void OnDescriptorWriteRequest( |
| 121 const BluetoothLocalGattService* service, | 121 const BluetoothDevice* device, |
| 122 const BluetoothLocalGattDescriptor* descriptor, | 122 const BluetoothLocalGattDescriptor* descriptor, |
| 123 const std::vector<uint8_t>& value, | 123 const std::vector<uint8_t>& value, |
| 124 int offset, | 124 int offset, |
| 125 const base::Closure& callback, | 125 const base::Closure& callback, |
| 126 const ErrorCallback& error_callback) = 0; | 126 const ErrorCallback& error_callback) = 0; |
| 127 | 127 |
| 128 // Called when a remote device requests notifications to start for | 128 // Called when a remote device |device| requests notifications to start for |
| 129 // |characteristic|. This is only called if the characteristic has | 129 // |characteristic|. This is only called if the characteristic has |
| 130 // specified the notify or indicate property. | 130 // specified the notify or indicate property. |
| 131 virtual void OnNotificationsStart( | 131 virtual void OnNotificationsStart( |
| 132 const BluetoothLocalGattService* service, | 132 const BluetoothDevice* device, |
| 133 const BluetoothLocalGattCharacteristic* characteristic) = 0; | 133 const BluetoothLocalGattCharacteristic* characteristic) = 0; |
| 134 | 134 |
| 135 // Called when a remote device requests notifications to stop for | 135 // Called when a remote device |device| requests notifications to stop for |
| 136 // |characteristic|. This is only called if the characteristic has | 136 // |characteristic|. This is only called if the characteristic has |
| 137 // specified the notify or indicate property. | 137 // specified the notify or indicate property. |
| 138 virtual void OnNotificationsStop( | 138 virtual void OnNotificationsStop( |
| 139 const BluetoothLocalGattService* service, | 139 const BluetoothDevice* device, |
| 140 const BluetoothLocalGattCharacteristic* characteristic) = 0; | 140 const BluetoothLocalGattCharacteristic* characteristic) = 0; |
| 141 }; | 141 }; |
| 142 | 142 |
| 143 // Creates a local GATT service to be used with |adapter| (which will own | 143 // Creates a local GATT service to be used with |adapter| (which will own |
| 144 // the created service object). A service can register or unregister itself | 144 // the created service object). A service can register or unregister itself |
| 145 // at any time by calling its Register/Unregister methods. |delegate| | 145 // at any time by calling its Register/Unregister methods. |delegate| |
| 146 // receives read/write requests for characteristic/descriptor values. It | 146 // receives read/write requests for characteristic/descriptor values. It |
| 147 // needs to outlive this object. | 147 // needs to outlive this object. |
| 148 // TODO(rkc): Implement included services. | 148 // TODO(rkc): Implement included services. |
| 149 static base::WeakPtr<BluetoothLocalGattService> Create( | 149 static base::WeakPtr<BluetoothLocalGattService> Create( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 178 BluetoothLocalGattService(); | 178 BluetoothLocalGattService(); |
| 179 ~BluetoothLocalGattService() override; | 179 ~BluetoothLocalGattService() override; |
| 180 | 180 |
| 181 private: | 181 private: |
| 182 DISALLOW_COPY_AND_ASSIGN(BluetoothLocalGattService); | 182 DISALLOW_COPY_AND_ASSIGN(BluetoothLocalGattService); |
| 183 }; | 183 }; |
| 184 | 184 |
| 185 } // namespace device | 185 } // namespace device |
| 186 | 186 |
| 187 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOCAL_GATT_SERVICE_H_ | 187 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOCAL_GATT_SERVICE_H_ |
| OLD | NEW |