Skip to content

Commit

Permalink
Merge pull request #244 from alexmoon/concurrent-notifications
Browse files Browse the repository at this point in the history
Create a separate portal for receiving notification events
  • Loading branch information
Dirbaio authored Mar 18, 2024
2 parents cdee83c + d1b0d37 commit 12eb174
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions nrf-softdevice/src/ble/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ impl ConnectionState {
// Signal possible in-progess operations that the connection has disconnected.
#[cfg(feature = "ble-gatt-client")]
crate::ble::gatt_client::portal(conn_handle).call(_ble_evt);
#[cfg(feature = "ble-gatt-client")]
crate::ble::gatt_client::hvx_portal(conn_handle).call(_ble_evt);
#[cfg(feature = "ble-gatt-server")]
crate::ble::gatt_server::portal(conn_handle).call(_ble_evt);
#[cfg(feature = "ble-l2cap")]
Expand Down
12 changes: 10 additions & 2 deletions nrf-softdevice/src/ble/gatt_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,11 @@ unsafe fn check_status(ble_evt: *const raw::ble_evt_t) -> Result<&'static raw::b

pub(crate) unsafe fn on_evt(ble_evt: *const raw::ble_evt_t) {
let gattc_evt = get_union_field(ble_evt, &(*ble_evt).evt.gattc_evt);
portal(gattc_evt.conn_handle).call(ble_evt);
if (*ble_evt).header.evt_id == raw::BLE_GATTC_EVTS_BLE_GATTC_EVT_HVX as u16 {
hvx_portal(gattc_evt.conn_handle).call(ble_evt);
} else {
portal(gattc_evt.conn_handle).call(ble_evt);
}
}

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
Expand Down Expand Up @@ -606,9 +610,13 @@ pub(crate) async fn att_mtu_exchange(conn: &Connection, mtu: u16) -> Result<(),

const PORTAL_NEW: Portal<*const raw::ble_evt_t> = Portal::new();
static PORTALS: [Portal<*const raw::ble_evt_t>; CONNS_MAX] = [PORTAL_NEW; CONNS_MAX];
static HVX_PORTALS: [Portal<*const raw::ble_evt_t>; CONNS_MAX] = [PORTAL_NEW; CONNS_MAX];
pub(crate) fn portal(conn_handle: u16) -> &'static Portal<*const raw::ble_evt_t> {
&PORTALS[conn_handle as usize]
}
pub(crate) fn hvx_portal(conn_handle: u16) -> &'static Portal<*const raw::ble_evt_t> {
&HVX_PORTALS[conn_handle as usize]
}

pub async fn run<'a, F, C>(conn: &Connection, client: &C, mut f: F) -> DisconnectedError
where
Expand All @@ -620,7 +628,7 @@ where
Err(e) => return e,
};

portal(handle)
hvx_portal(handle)
.wait_many(|ble_evt| unsafe {
let ble_evt = &*ble_evt;
if u32::from(ble_evt.header.evt_id) == raw::BLE_GAP_EVTS_BLE_GAP_EVT_DISCONNECTED {
Expand Down

0 comments on commit 12eb174

Please sign in to comment.