@@ -361,11 +361,8 @@ void BLECharacteristic::_eventHandler(ble_evt_t* event)
361
361
{
362
362
ble_gatts_evt_read_t * rd_req = &request->request .read ;
363
363
364
- if ( _use_ada_cb.read_authorize )
365
- {
366
- ada_callback (rd_req, sizeof (*rd_req), _rd_authorize_cb, conn_hdl, this , rd_req);
367
- }
368
- else
364
+ if ( !(_use_ada_cb.read_authorize &&
365
+ ada_callback (rd_req, sizeof (*rd_req), _rd_authorize_cb, conn_hdl, this , rd_req)) )
369
366
{
370
367
_rd_authorize_cb (conn_hdl, this , rd_req);
371
368
}
@@ -382,10 +379,8 @@ void BLECharacteristic::_eventHandler(ble_evt_t* event)
382
379
// Write Request with authorization
383
380
if (_wr_authorize_cb != NULL )
384
381
{
385
- if ( _use_ada_cb.write_authorize )
386
- {
387
- ada_callback (wr_req, sizeof (*wr_req), _wr_authorize_cb, conn_hdl, this , wr_req);
388
- }else
382
+ if ( !(_use_ada_cb.write_authorize &&
383
+ ada_callback (wr_req, sizeof (*wr_req), _wr_authorize_cb, conn_hdl, this , wr_req)) )
389
384
{
390
385
_wr_authorize_cb (conn_hdl, this , wr_req);
391
386
}
@@ -435,13 +430,12 @@ void BLECharacteristic::_eventHandler(ble_evt_t* event)
435
430
436
431
sd_ble_gatts_rw_authorize_reply (conn_hdl, &reply);
437
432
438
- // Long write complete, call write callback if set
439
433
if (_wr_cb)
440
434
{
441
- if (_use_ada_cb. write )
442
- {
443
- ada_callback (_long_wr. buffer , _long_wr. count , _wr_cb, conn_hdl, this , _long_wr. buffer , _long_wr. count );
444
- } else
435
+ // Long write complete, call write callback if set
436
+ // If using ada callback but failed --> invoke callback immediately
437
+ if ( !(_use_ada_cb. write &&
438
+ ada_callback (_long_wr. buffer , _long_wr. count , _wr_cb, conn_hdl, this , _long_wr. buffer , _long_wr. count )) )
445
439
{
446
440
_wr_cb (conn_hdl, this , _long_wr.buffer , _long_wr.count );
447
441
}
@@ -476,10 +470,8 @@ void BLECharacteristic::_eventHandler(ble_evt_t* event)
476
470
477
471
if (_wr_cb)
478
472
{
479
- if (_use_ada_cb.write )
480
- {
481
- ada_callback (request->data , request->len , _wr_cb, conn_hdl, this , request->data , request->len );
482
- }else
473
+ if ( !(_use_ada_cb.write &&
474
+ ada_callback (request->data , request->len , _wr_cb, conn_hdl, this , request->data , request->len )) )
483
475
{
484
476
_wr_cb (conn_hdl, this , request->data , request->len );
485
477
}
@@ -496,11 +488,8 @@ void BLECharacteristic::_eventHandler(ble_evt_t* event)
496
488
497
489
if (_cccd_wr_cb)
498
490
{
499
- if ( _use_ada_cb.cccd_write )
500
- {
501
- ada_callback (NULL , 0 , _cccd_wr_cb, conn_hdl, this , value);
502
- }
503
- else
491
+ if ( !(_use_ada_cb.cccd_write &&
492
+ ada_callback (NULL , 0 , _cccd_wr_cb, conn_hdl, this , value)) )
504
493
{
505
494
_cccd_wr_cb (conn_hdl, this , value);
506
495
}
0 commit comments