Add unsubscribe to objects
This commit is contained in:
@@ -18,27 +18,40 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let client = SimConnect::new("Simple Program");
|
||||
|
||||
match client {
|
||||
Ok(mut client) => loop {
|
||||
let notification = client.get_next_dispatch()?;
|
||||
Ok(mut client) => {
|
||||
let mut notifications_received = 0;
|
||||
|
||||
match notification {
|
||||
Some(Notification::Open) => {
|
||||
println!("Open");
|
||||
loop {
|
||||
let notification = client.get_next_dispatch()?;
|
||||
|
||||
// After the connection is successfully open, we register the struct
|
||||
client.register_object::<GpsData>()?;
|
||||
}
|
||||
Some(Notification::Object(data)) => {
|
||||
if let Ok(gps_data) = GpsData::try_from(&data) {
|
||||
println!("{gps_data:?}");
|
||||
match notification {
|
||||
Some(Notification::Open) => {
|
||||
println!("Connection opened.");
|
||||
|
||||
// After the connection is successfully open, we register the struct
|
||||
client.register_object::<GpsData>()?;
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
Some(Notification::Object(data)) => {
|
||||
if let Ok(gps_data) = GpsData::try_from(&data) {
|
||||
println!("{gps_data:?}");
|
||||
|
||||
// sleep for about a frame to reduce CPU usage
|
||||
std::thread::sleep(std::time::Duration::from_millis(16));
|
||||
},
|
||||
notifications_received += 1;
|
||||
|
||||
// After we have received 10 notifications, we unregister the struct
|
||||
if notifications_received > 10 {
|
||||
client.unregister_object::<GpsData>()?;
|
||||
println!("Subscription stopped.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
// sleep for about a frame to reduce CPU usage
|
||||
std::thread::sleep(std::time::Duration::from_millis(16));
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Error: {e:?}")
|
||||
}
|
||||
|
@@ -31,7 +31,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
match notification {
|
||||
Some(Notification::Open) => {
|
||||
println!("Open");
|
||||
println!("Connection opened.");
|
||||
|
||||
// After the connection is successfully open, we register the structs
|
||||
client.register_object::<GpsData>()?;
|
||||
|
@@ -22,27 +22,40 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let client = SimConnect::new("Simple Program");
|
||||
|
||||
match client {
|
||||
Ok(mut client) => loop {
|
||||
let notification = client.get_next_dispatch()?;
|
||||
Ok(mut client) => {
|
||||
let mut notifications_received = 0;
|
||||
|
||||
match notification {
|
||||
Some(Notification::Open) => {
|
||||
info!("Open");
|
||||
loop {
|
||||
let notification = client.get_next_dispatch()?;
|
||||
|
||||
// After the connection is successfully open, we register the struct
|
||||
client.register_object::<GpsData>()?;
|
||||
}
|
||||
Some(Notification::Object(data)) => {
|
||||
if let Ok(gps_data) = GpsData::try_from(&data) {
|
||||
info!("{gps_data:?}");
|
||||
match notification {
|
||||
Some(Notification::Open) => {
|
||||
info!("Open");
|
||||
|
||||
// After the connection is successfully open, we register the struct
|
||||
client.register_object::<GpsData>()?;
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
Some(Notification::Object(data)) => {
|
||||
if let Ok(gps_data) = GpsData::try_from(&data) {
|
||||
info!("{gps_data:?}");
|
||||
|
||||
// sleep for about a frame to reduce CPU usage
|
||||
std::thread::sleep(std::time::Duration::from_millis(16));
|
||||
},
|
||||
notifications_received += 1;
|
||||
|
||||
// After we have received 10 notifications, we unregister the struct
|
||||
if notifications_received > 10 {
|
||||
client.unregister_object::<GpsData>()?;
|
||||
println!("Subscription stopped.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
// sleep for about a frame to reduce CPU usage
|
||||
std::thread::sleep(std::time::Duration::from_millis(16));
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
error!("{e:?}")
|
||||
}
|
||||
|
@@ -37,27 +37,40 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let client = SimConnect::new("Simple Program");
|
||||
|
||||
match client {
|
||||
Ok(mut client) => loop {
|
||||
let notification = client.get_next_dispatch()?;
|
||||
Ok(mut client) => {
|
||||
let mut notifications_received = 0;
|
||||
|
||||
match notification {
|
||||
Some(Notification::Open) => {
|
||||
println!("Open");
|
||||
loop {
|
||||
let notification = client.get_next_dispatch()?;
|
||||
|
||||
// After the connection is successfully open, we register the struct
|
||||
client.register_object::<GpsData>()?;
|
||||
}
|
||||
Some(Notification::Object(data)) => {
|
||||
if let Ok(gps_data) = GpsData::try_from(&data) {
|
||||
println!("{gps_data:?}");
|
||||
match notification {
|
||||
Some(Notification::Open) => {
|
||||
println!("Connection opened.");
|
||||
|
||||
// After the connection is successfully open, we register the struct
|
||||
client.register_object::<GpsData>()?;
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
Some(Notification::Object(data)) => {
|
||||
if let Ok(gps_data) = GpsData::try_from(&data) {
|
||||
println!("{gps_data:?}");
|
||||
|
||||
// sleep for about a frame to reduce CPU usage
|
||||
std::thread::sleep(std::time::Duration::from_millis(16));
|
||||
},
|
||||
notifications_received += 1;
|
||||
|
||||
// After we have received 10 notifications, we unregister the struct
|
||||
if notifications_received > 10 {
|
||||
client.unregister_object::<GpsData>()?;
|
||||
println!("Subscription stopped.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
// sleep for about a frame to reduce CPU usage
|
||||
std::thread::sleep(std::time::Duration::from_millis(16));
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Error: {e:?}")
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
match notification {
|
||||
Some(Notification::Open) => {
|
||||
println!("Open");
|
||||
println!("Connection opened.");
|
||||
|
||||
// After the connection is successfully open
|
||||
|
||||
|
Reference in New Issue
Block a user