Skip to content

Commit

Permalink
feat: added lifecycle start/stop to plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
DamianoPellegrini committed Nov 22, 2023
1 parent 1500f6f commit 8fac1aa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ impl Argo {
let listener = std::net::TcpListener::bind(self.socket_addr)?;

log::info!("Listening on {}", self.socket_addr);

log::info!("Starting plugins...");
for plugin in self.plugins.read().unwrap().iter() {
plugin.lock().expect("Cannot acquire lock").startup();
}

let mut handles = vec![];

Expand Down Expand Up @@ -87,6 +92,11 @@ impl Argo {
}
}

log::info!("Shutting down plugins...");
for plugin in self.plugins.read().unwrap().iter() {
plugin.lock().expect("Cannot acquire lock").shutdown();
}

Ok(())
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ impl From<&AVLDatagram> for TeltonikaEvent {
///
/// _See the [`PluginHandle`](crate::PluginHandle) and [`PluginHandles`](crate::PluginHandles) for more info._
pub trait Plugin {
fn startup(&mut self) {}
fn shutdown(&mut self) {}

#[allow(unused_variables)]
/// Check if a device is allowed to connect
fn can_teltonika_connect(&mut self, imei: &str) -> bool {
Expand Down

0 comments on commit 8fac1aa

Please sign in to comment.