BLECharacteristic falls back to immed call if ada callback failed

This commit is contained in:
hathach committed 2019-09-23 15:32:36 +07:00
1 parent 31ed8a4fbb
commit 940e902edd
3 files changed
+18 -37

No files matched your search

@@ -361,11 +361,8 @@ void BLECharacteristic::_eventHandler(ble_evt_t* event)
{
ble_gatts_evt_read_t * rd_req = &request->request.read;
if ( _use_ada_cb.read_authorize )
{
ada_callback(rd_req, sizeof(*rd_req), _rd_authorize_cb, conn_hdl, this, rd_req);
}
else
if ( !(_use_ada_cb.read_authorize &&
ada_callback(rd_req, sizeof(*rd_req), _rd_authorize_cb, conn_hdl, this, rd_req)) )
{
_rd_authorize_cb(conn_hdl, this, rd_req);
}
@@ -382,10 +379,8 @@ void BLECharacteristic::_eventHandler(ble_evt_t* event)
// Write Request with authorization
if (_wr_authorize_cb != NULL)
{
if ( _use_ada_cb.write_authorize )
{
ada_callback(wr_req, sizeof(*wr_req), _wr_authorize_cb, conn_hdl, this, wr_req);
}else
if ( !(_use_ada_cb.write_authorize &&
ada_callback(wr_req, sizeof(*wr_req), _wr_authorize_cb, conn_hdl, this, wr_req)) )
{
_wr_authorize_cb(conn_hdl, this, wr_req);
}
@@ -435,13 +430,12 @@ void BLECharacteristic::_eventHandler(ble_evt_t* event)
sd_ble_gatts_rw_authorize_reply(conn_hdl, &reply);
// Long write complete, call write callback if set
if (_wr_cb)
{
if (_use_ada_cb.write)
{
ada_callback(_long_wr.buffer, _long_wr.count, _wr_cb, conn_hdl, this, _long_wr.buffer, _long_wr.count);
}else
// Long write complete, call write callback if set
// If using ada callback but failed --> invoke callback immediately
if ( !(_use_ada_cb.write &&
ada_callback(_long_wr.buffer, _long_wr.count, _wr_cb, conn_hdl, this, _long_wr.buffer, _long_wr.count)) )
{
_wr_cb(conn_hdl, this, _long_wr.buffer, _long_wr.count);
}
@@ -476,10 +470,8 @@ void BLECharacteristic::_eventHandler(ble_evt_t* event)
if (_wr_cb)
{
if (_use_ada_cb.write)
{
ada_callback(request->data, request->len, _wr_cb, conn_hdl, this, request->data, request->len);
}else
if ( !(_use_ada_cb.write &&
ada_callback(request->data, request->len, _wr_cb, conn_hdl, this, request->data, request->len)) )
{
_wr_cb(conn_hdl, this, request->data, request->len);
}
@@ -496,11 +488,8 @@ void BLECharacteristic::_eventHandler(ble_evt_t* event)
if (_cccd_wr_cb)
{
if ( _use_ada_cb.cccd_write )
{
ada_callback(NULL, 0, _cccd_wr_cb, conn_hdl, this, value);
}
else
if ( !(_use_ada_cb.cccd_write &&
ada_callback(NULL, 0, _cccd_wr_cb, conn_hdl, this, value)) )
{
_cccd_wr_cb(conn_hdl, this, value);
}
@@ -411,10 +411,8 @@ void BLEClientCharacteristic::_eventHandler(ble_evt_t* evt)
if (_notify_cb)
{
// use AdaCallback or invoke directly
if (_use_ada_cb.notify)
{
ada_callback(hvx->data, hvx->len, _notify_cb, this, hvx->data, hvx->len);
}else
if ( !(_use_ada_cb.notify &&
ada_callback(hvx->data, hvx->len, _notify_cb, this, hvx->data, hvx->len)) )
{
_notify_cb(this, hvx->data, hvx->len);
}
@@ -425,10 +423,8 @@ void BLEClientCharacteristic::_eventHandler(ble_evt_t* evt)
if (_indicate_cb)
{
// use AdaCallback or invoke directly
if (_use_ada_cb.indicate)
{
ada_callback(hvx->data, hvx->len, _indicate_cb, this, hvx->data, hvx->len);
}else
if ( !(_use_ada_cb.indicate &&
ada_callback(hvx->data, hvx->len, _indicate_cb, this, hvx->data, hvx->len)) )
{
_indicate_cb(this, hvx->data, hvx->len);
}
@@ -131,9 +131,7 @@ static void bond_save_keys_dfr (uint8_t role, uint16_t conn_hdl, bond_keys_t* bk
bool bond_save_keys (uint8_t role, uint16_t conn_hdl, bond_keys_t* bkeys)
{
// queue to execute in Ada Callback thread
ada_callback(bkeys, sizeof(bond_keys_t), bond_save_keys_dfr, role, conn_hdl, bkeys);
return true;
return ada_callback(bkeys, sizeof(bond_keys_t), bond_save_keys_dfr, role, conn_hdl, bkeys);
}
bool bond_load_keys(uint8_t role, uint16_t ediv, bond_keys_t* bkeys)
@@ -190,9 +188,7 @@ bool bond_save_cccd (uint8_t role, uint16_t conn_hdl, uint16_t ediv)
VERIFY(ediv != 0xFFFF);
// queue to execute in Ada Callback thread
ada_callback(NULL, 0, bond_save_cccd_dfr, role, conn_hdl, ediv);
return true;
return ada_callback(NULL, 0, bond_save_cccd_dfr, role, conn_hdl, ediv);
}
bool bond_load_cccd(uint8_t role, uint16_t conn_hdl, uint16_t ediv)