Add suport for system events
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
use crate::{bindings, success, Event, NotificationGroup, SimConnect, SimConnectError};
|
||||
use crate::{
|
||||
bindings, success, ClientEvent, NotificationGroup, SimConnect, SimConnectError,
|
||||
SystemEventRequest,
|
||||
};
|
||||
|
||||
impl SimConnect {
|
||||
/// Associates a client defined event with a Microsoft Flight Simulator event name.
|
||||
@@ -7,7 +10,7 @@ impl SimConnect {
|
||||
#[tracing::instrument(name = "SimConnect::register_event", level = "debug", skip(self))]
|
||||
pub fn register_event(
|
||||
&self,
|
||||
event: Event,
|
||||
event: ClientEvent,
|
||||
notification_group: NotificationGroup,
|
||||
) -> Result<(), SimConnectError> {
|
||||
success!(unsafe {
|
||||
@@ -16,7 +19,7 @@ impl SimConnect {
|
||||
event as u32,
|
||||
event.into_c_char(),
|
||||
)
|
||||
});
|
||||
})?;
|
||||
|
||||
success!(unsafe {
|
||||
bindings::SimConnect_AddClientEventToNotificationGroup(
|
||||
@@ -25,7 +28,7 @@ impl SimConnect {
|
||||
event as u32,
|
||||
0,
|
||||
)
|
||||
});
|
||||
})?;
|
||||
|
||||
success!(unsafe {
|
||||
bindings::SimConnect_SetNotificationGroupPriority(
|
||||
@@ -33,8 +36,40 @@ impl SimConnect {
|
||||
notification_group as u32,
|
||||
1,
|
||||
)
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
Ok(())
|
||||
/// Request that a specific system event is notified to the client.
|
||||
#[tracing::instrument(
|
||||
name = "SimConnect::subscribe_to_system_event",
|
||||
level = "debug",
|
||||
skip(self)
|
||||
)]
|
||||
pub fn subscribe_to_system_event(
|
||||
&mut self,
|
||||
event: SystemEventRequest,
|
||||
) -> Result<(), SimConnectError> {
|
||||
success!(unsafe {
|
||||
bindings::SimConnect_SubscribeToSystemEvent(
|
||||
self.handle.as_ptr(),
|
||||
event as u32,
|
||||
event.into_c_char(),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/// Request that notifications are no longer received for the specified system event.
|
||||
#[tracing::instrument(
|
||||
name = "SimConnect::unsubscribe_from_system_event",
|
||||
level = "debug",
|
||||
skip(self)
|
||||
)]
|
||||
pub fn unsubscribe_from_system_event(
|
||||
&mut self,
|
||||
event: SystemEventRequest,
|
||||
) -> Result<(), SimConnectError> {
|
||||
success!(unsafe {
|
||||
bindings::SimConnect_UnsubscribeFromSystemEvent(self.handle.as_ptr(), event as u32)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user