@@ -361,11 +361,8 @@ void BLECharacteristic::_eventHandler(ble_evt_t* event)
361361 {
362362 ble_gatts_evt_read_t * rd_req = &request->request .read ;
363363
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)) )
369366 {
370367 _rd_authorize_cb (conn_hdl, this , rd_req);
371368 }
@@ -382,10 +379,8 @@ void BLECharacteristic::_eventHandler(ble_evt_t* event)
382379 // Write Request with authorization
383380 if (_wr_authorize_cb != NULL )
384381 {
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)) )
389384 {
390385 _wr_authorize_cb (conn_hdl, this , wr_req);
391386 }
@@ -435,13 +430,12 @@ void BLECharacteristic::_eventHandler(ble_evt_t* event)
435430
436431 sd_ble_gatts_rw_authorize_reply (conn_hdl, &reply);
437432
438- // Long write complete, call write callback if set
439433 if (_wr_cb)
440434 {
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 )) )
445439 {
446440 _wr_cb (conn_hdl, this , _long_wr.buffer , _long_wr.count );
447441 }
@@ -476,10 +470,8 @@ void BLECharacteristic::_eventHandler(ble_evt_t* event)
476470
477471 if (_wr_cb)
478472 {
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 )) )
483475 {
484476 _wr_cb (conn_hdl, this , request->data , request->len );
485477 }
@@ -496,11 +488,8 @@ void BLECharacteristic::_eventHandler(ble_evt_t* event)
496488
497489 if (_cccd_wr_cb)
498490 {
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)) )
504493 {
505494 _cccd_wr_cb (conn_hdl, this , value);
506495 }
0 commit comments