Add gracefull shutdown to sub commands

This commit is contained in:
QuantumEntangledAndy committed 2023-08-07 19:03:06 +07:00
1 parent 0d2f0c3e6f
commit 17e8ab0f37
11 files changed
+37 -6

No files matched your search

-5
View File
@@ -85,8 +85,6 @@ pub struct BcCameraOpt {
pub protocol: ConnectionProtocol,
/// Discovery method to allow
pub discovery: DiscoveryMethods,
/// Printing format for auxilaary data such as battery levels
pub aux_printing: PrintFormat,
/// Credentials for login
pub credentials: Credentials,
}
@@ -343,9 +341,6 @@ impl BcCamera {
abilities: Default::default(),
};
me.keepalive().await?;
if let Err(e) = me.monitor_battery(options.aux_printing).await {
warn!("Could not monitor battery: {:?}", e);
}
Ok(me)
}
+1
View File
@@ -25,4 +25,5 @@ pub enum Command {
Talk(super::talk::Opt),
Mqtt(super::mqtt::Opt),
Image(super::image::Opt),
Battery(super::battery::Opt),
}
+4
View File
@@ -29,6 +29,7 @@ use log::*;
use std::fs;
use validator::Validate;
mod battery;
mod cmdline;
mod config;
mod image;
@@ -115,6 +116,9 @@ async fn main() -> Result<()> {
Some(Command::Image(opts)) => {
image::main(opts, config).await?;
}
Some(Command::Battery(opts)) => {
battery::main(opts, config).await?;
}
}
Ok(())
+4
View File
@@ -198,6 +198,10 @@ impl EventCamThread {
.context("Failed to login to the camera")??;
info!("{}: Connected and logged in", camera_config.name);
if let Err(e) = camera.monitor_battery(camera_config.print_format).await {
warn!("Could not monitor battery: {:?}", e);
}
self.tx.send(Messages::Login).await?;
// Shararble cameras
+4
View File
@@ -44,5 +44,9 @@ pub(crate) async fn main(opt: Opt, config: Config) -> Result<()> {
.expect("Should be UTF8");
println!("{}", pir_ser);
}
let _ = camera.logout().await;
camera.disconnect().await?;
Ok(())
}
+4
View File
@@ -90,5 +90,9 @@ pub(crate) async fn main(opt: Opt, config: Config) -> Result<()> {
.context("Unable to execute PTZ move command")?;
}
};
let _ = camera.logout().await;
camera.disconnect().await?;
Ok(())
}
+3
View File
@@ -29,5 +29,8 @@ pub(crate) async fn main(opt: Opt, config: Config) -> Result<()> {
.reboot()
.await
.context("Could not send reboot command to the camera")?;
camera.disconnect().await?;
Ok(())
}
+10
View File
@@ -30,6 +30,16 @@ impl Camera<Connected> {
};
timeout(self.state.camera.login_with_maxenc(max_encryption)).await??;
if let Err(e) = self
.state
.camera
.monitor_battery(self.shared.config.print_format)
.await
{
log::warn!("Could not monitor battery: {:?}", e);
}
Ok(Camera {
shared: self.shared,
state: LoggedIn {
+4
View File
@@ -33,5 +33,9 @@ pub(crate) async fn main(opt: Opt, config: Config) -> Result<()> {
.led_light_set(opt.on)
.await
.context("Unable to set camera light state")?;
let _ = camera.logout().await;
camera.disconnect().await?;
Ok(())
}
+3
View File
@@ -86,5 +86,8 @@ pub(crate) async fn main(opt: Opt, config: Config) -> Result<()> {
.await
.context("Talk stream ended early")?;
let _ = camera.logout().await;
camera.disconnect().await?;
Ok(())
}
-1
View File
@@ -93,7 +93,6 @@ impl AddressOrUid {
uid: camera_config.camera_uid.clone(),
protocol: ConnectionProtocol::TcpUdp,
discovery: camera_config.discovery,
aux_printing: camera_config.print_format,
credentials: Credentials {
username: camera_config.username.clone(),
password: camera_config.password.clone(),