use crate::io::{ApduHeader, Reply};
pub type NbglNextEventAheadCb = fn() -> bool; pub type NbglFetchApduHeaderCb = fn() -> Option<ApduHeader>;
pub type NbglReplyStatusCb = fn(reply: Reply);
struct NbglCallbacks {
next_event_ahead: NbglNextEventAheadCb,
fetch_apdu_header: NbglFetchApduHeaderCb,
reply_status: NbglReplyStatusCb,
}
static mut NBGL_CALLBACKS: Option<NbglCallbacks> = None;
pub fn nbgl_register_callbacks(
next_event_ahead: NbglNextEventAheadCb,
fetch_apdu_header: NbglFetchApduHeaderCb,
reply_status: NbglReplyStatusCb,
) {
unsafe {
NBGL_CALLBACKS = Some(NbglCallbacks {
next_event_ahead,
fetch_apdu_header,
reply_status,
});
}
}
fn get_callbacks() -> &'static NbglCallbacks {
unsafe {
#[allow(static_mut_refs)]
NBGL_CALLBACKS
.as_ref()
.expect("NBGL callbacks not registered")
}
}
pub fn nbgl_next_event_ahead() -> bool {
(get_callbacks().next_event_ahead)()
}
pub fn nbgl_fetch_apdu_header() -> Option<ApduHeader> {
(get_callbacks().fetch_apdu_header)()
}
pub fn nbgl_reply_status(reply: Reply) {
(get_callbacks().reply_status)(reply);
}