diff options
author | Marcel Müller <m.mueller@ifm.com> | 2022-02-10 14:00:05 +0100 |
---|---|---|
committer | Matthias Beyer <matthias.beyer@ifm.com> | 2022-03-04 15:03:53 +0100 |
commit | 517c4bf19ea5c059d0043076a7ac7e823567ec6a (patch) | |
tree | d4f9e0d1390a3752bd125c2f7e1284b6e6d3e857 /crates/core/tedge_api | |
parent | 21d7556690369b1084fe9ac1716c6bad59871d97 (diff) |
Make PluginBuilder methods async
Allowing them to be async means that they can do slightly more
complicated methods of checking configuration and instantiating
plugins. (Like IO to check for file existence, etc..)
Signed-off-by: Marcel Müller <m.mueller@ifm.com>
Signed-off-by: Matthias Beyer <matthias.beyer@ifm.com>
Diffstat (limited to 'crates/core/tedge_api')
-rw-r--r-- | crates/core/tedge_api/examples/heartbeat.rs | 7 | ||||
-rw-r--r-- | crates/core/tedge_api/src/plugins.rs | 5 |
2 files changed, 7 insertions, 5 deletions
diff --git a/crates/core/tedge_api/examples/heartbeat.rs b/crates/core/tedge_api/examples/heartbeat.rs index 80f8b10e..7776e488 100644 --- a/crates/core/tedge_api/examples/heartbeat.rs +++ b/crates/core/tedge_api/examples/heartbeat.rs @@ -8,19 +8,20 @@ use tedge_api::{ struct HeartbeatServiceBuilder; +#[async_trait] impl PluginBuilder for HeartbeatServiceBuilder { fn name(&self) -> &'static str { todo!() } - fn verify_configuration( + async fn verify_configuration( &self, _config: &PluginConfiguration, ) -> Result<(), tedge_api::errors::PluginError> { Ok(()) } - fn instantiate( + async fn instantiate( &self, config: PluginConfiguration, tedge_comms: tedge_api::plugins::Comms, @@ -89,7 +90,7 @@ async fn main() { ) .unwrap(); - let mut heartbeat = hsb.instantiate(config, comms).unwrap(); + let mut heartbeat = hsb.instantiate(config, comms).await.unwrap(); heartbeat.setup().await.unwrap(); diff --git a/crates/core/tedge_api/src/plugins.rs b/crates/core/tedge_api/src/plugins.rs index cb1710be..78cb3356 100644 --- a/crates/core/tedge_api/src/plugins.rs +++ b/crates/core/tedge_api/src/plugins.rs @@ -36,18 +36,19 @@ impl Comms { pub type PluginConfiguration = toml::Spanned<toml::value::Value>; /// A plugin builder for a given plugin +#[async_trait] pub trait PluginBuilder: Sync + Send + 'static { /// The name of the plugins this creates, this should be unique and will prevent startup otherwise fn name(&self) -> &'static str; /// This may be called anytime to verify whether a plugin could be instantiated with the /// passed configuration. - fn verify_configuration(&self, config: &PluginConfiguration) -> Result<(), PluginError>; + async fn verify_configuration(&self, config: &PluginConfiguration) -> Result<(), PluginError>; /// Instantiate a new instance of this plugin using the given configuration /// /// This _must not_ block - fn instantiate( + async fn instantiate( &self, config: PluginConfiguration, tedge_comms: Comms, |