Skip to content

Commit 6e7ad0b

Browse files
authored
Improve simple pointer protocol state query (#43)
* Fix pointer tests * Use an Option to prevent future issues
1 parent 16a6015 commit 6e7ad0b

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/proto/console/pointer/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,18 @@ impl Pointer {
2727

2828
/// Retrieves the pointer device's current state.
2929
///
30+
/// Will return None if the state has not changed since the last query.
31+
///
3032
/// # Errors
31-
/// - `NotReady` is returned if the state hasn't changed since the last call.
3233
/// - `DeviceError` if there was an issue with the pointer device.
33-
pub fn state(&self) -> Result<PointerState> {
34+
pub fn state(&self) -> Result<Option<PointerState>> {
3435
let mut pointer_state = unsafe { mem::uninitialized() };
3536

36-
(self.get_state)(self, &mut pointer_state).into_with(|| pointer_state)
37+
match (self.get_state)(self, &mut pointer_state) {
38+
Status::Success => Ok(Some(pointer_state)),
39+
Status::NotReady => Ok(None),
40+
error => Err(error)
41+
}
3742
}
3843

3944
/// Returns a reference to the pointer device information.

uefi-test-runner/src/proto/console/pointer.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ pub fn test(bt: &BootServices) {
1212
.reset(false)
1313
.expect("Failed to reset pointer device");
1414

15-
if let Ok(state) = pointer.state() {
16-
info!("Pointer State: {:#?}", state);
15+
let state = pointer.state().expect("Failed to retrieve pointer state");
16+
if let Some(state) = state {
17+
info!("New pointer State: {:#?}", state);
1718
} else {
18-
error!("Failed to retrieve pointer state");
19+
info!("Pointer state has not changed since the last query");
1920
}
2021
} else {
2122
warn!("No pointer device found");

0 commit comments

Comments
 (0)