Verify ReadResponse identity
This commit is contained in:
parent
ebb982f7dc
commit
00cabcefea
1 changed files with 17 additions and 8 deletions
|
@ -33,28 +33,37 @@ DiscoveredCharacteristic::read(uint16_t offset) const
|
|||
|
||||
|
||||
struct OneShotReadCallback {
|
||||
static void launch(GattClient* client, const GattClient::ReadCallback_t& cb) {
|
||||
OneShotReadCallback* oneShot = new OneShotReadCallback(client, cb);
|
||||
static void launch(GattClient* client, Gap::Handle_t connHandle,
|
||||
GattAttribute::Handle_t handle,const GattClient::ReadCallback_t& cb) {
|
||||
OneShotReadCallback* oneShot = new OneShotReadCallback(client, connHandle, handle, cb);
|
||||
oneShot->attach();
|
||||
// delete will be made when this callback is called
|
||||
}
|
||||
|
||||
private:
|
||||
OneShotReadCallback(GattClient* client, const GattClient::ReadCallback_t& cb) :
|
||||
OneShotReadCallback(GattClient* client, Gap::Handle_t connHandle,
|
||||
GattAttribute::Handle_t handle, const GattClient::ReadCallback_t& cb) :
|
||||
_client(client),
|
||||
_connHandle(connHandle),
|
||||
_handle(handle),
|
||||
_callback(cb) { }
|
||||
|
||||
void attach() {
|
||||
_client->onDataRead(makeFunctionPointer(this, &OneShotReadCallback::call));
|
||||
}
|
||||
|
||||
void call(const GattReadCallbackParams* params) {
|
||||
_callback(params);
|
||||
_client->onDataRead().detach(makeFunctionPointer(this, &OneShotReadCallback::call));
|
||||
delete this;
|
||||
void call(const GattReadCallbackParams* params) {
|
||||
// verifiy that it is the right characteristic on the right connection
|
||||
if(params->connHandle == _connHandle && params->handle == _handle) {
|
||||
_callback(params);
|
||||
_client->onDataRead().detach(makeFunctionPointer(this, &OneShotReadCallback::call));
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
GattClient* _client;
|
||||
Gap::Handle_t _connHandle;
|
||||
GattAttribute::Handle_t _handle;
|
||||
GattClient::ReadCallback_t _callback;
|
||||
};
|
||||
|
||||
|
@ -64,7 +73,7 @@ ble_error_t DiscoveredCharacteristic::read(uint16_t offset, const GattClient::Re
|
|||
return error;
|
||||
}
|
||||
|
||||
OneShotReadCallback::launch(gattc, onRead);
|
||||
OneShotReadCallback::launch(gattc, connHandle, valueHandle, onRead);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue