sendsyncmaybe
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::{collections::HashMap, ffi::c_void};
|
||||
|
||||
use tracing::{error, span, trace, warn, Level};
|
||||
@@ -83,9 +84,8 @@ use crate::{as_c_string, bindings, ok_if_fail, success, SimConnectError};
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
#[derive(Debug)]
|
||||
pub struct SimConnect {
|
||||
pub(crate) handle: std::ptr::NonNull<c_void>,
|
||||
pub(crate) handle: SimConnectHandle,
|
||||
pub(crate) next_request_id: u32,
|
||||
pub(crate) registered_objects: HashMap<String, RegisteredObject>,
|
||||
pub(crate) system_event_register: EventRegister<SystemEventRequest>,
|
||||
@@ -105,15 +105,34 @@ impl RegisteredObject {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SimConnectHandle(std::ptr::NonNull<c_void>);
|
||||
|
||||
impl DerefMut for SimConnectHandle {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for SimConnectHandle {
|
||||
type Target = std::ptr::NonNull<c_void>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Send for SimConnectHandle {}
|
||||
unsafe impl Sync for SimConnectHandle {}
|
||||
|
||||
impl SimConnect {
|
||||
/// Create a new SimConnect SDK client.
|
||||
#[tracing::instrument(name = "SimConnect::new", level = "debug")]
|
||||
pub fn new(name: &str) -> Result<Self, SimConnectError> {
|
||||
let mut handle = std::ptr::null_mut();
|
||||
let mut g = std::ptr::null_mut();
|
||||
|
||||
success!(unsafe {
|
||||
bindings::SimConnect_Open(
|
||||
&mut handle,
|
||||
&mut g,
|
||||
as_c_string!(name),
|
||||
std::ptr::null_mut(),
|
||||
0,
|
||||
@@ -123,11 +142,11 @@ impl SimConnect {
|
||||
})?;
|
||||
|
||||
Ok(Self {
|
||||
handle: std::ptr::NonNull::new(handle).ok_or_else(|| {
|
||||
handle: SimConnectHandle(std::ptr::NonNull::new(g).ok_or_else(|| {
|
||||
SimConnectError::UnexpectedError(
|
||||
"SimConnect_Open returned null pointer on success".to_string(),
|
||||
)
|
||||
})?,
|
||||
})?),
|
||||
next_request_id: 0,
|
||||
registered_objects: HashMap::new(),
|
||||
system_event_register: EventRegister::new(),
|
||||
@@ -148,7 +167,7 @@ impl SimConnect {
|
||||
unsafe {
|
||||
ok_if_fail!(
|
||||
bindings::SimConnect_GetNextDispatch(
|
||||
self.handle.as_ptr(),
|
||||
self.handle.0.as_ptr(),
|
||||
&mut data_buf,
|
||||
size_buf_pointer
|
||||
),
|
||||
|
Reference in New Issue
Block a user