diff options
author | Marcel Müller <m.mueller@ifm.com> | 2022-05-19 14:36:06 +0200 |
---|---|---|
committer | Matthias Beyer <matthias.beyer@ifm.com> | 2022-05-20 12:16:30 +0200 |
commit | d6517ace8e343145c868d5aebbaa328ad0f880cb (patch) | |
tree | adcec48785529ab08c5031c11acf15f5849eee58 /crates | |
parent | 295676c596eefc334e20503858d67ecc2bc51f8f (diff) |
Add Plugin::main() with a default body
The plugin "main" should implement the main usecase of the plugin. This
is where plugin authors should do their work.
Of course, having a default implementation makes implementing a Plugin
that only handles messages as easy as it can get: An author just has to
implement an seemingly empty `Plugin` trait for their type, plus the
`Handle<>` implementations for message handling.
If they want to do extra things, overwriting the functions from `Plugin`
is the way to go.
Signed-off-by: Marcel Müller <m.mueller@ifm.com>
Signed-off-by: Matthias Beyer <matthias.beyer@ifm.com>
Reviewed-by: Matthias Beyer <matthias.beyer@ifm.com>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/core/tedge_api/src/plugin.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/crates/core/tedge_api/src/plugin.rs b/crates/core/tedge_api/src/plugin.rs index 0ffbe551..431127cf 100644 --- a/crates/core/tedge_api/src/plugin.rs +++ b/crates/core/tedge_api/src/plugin.rs @@ -315,6 +315,14 @@ pub trait Plugin: Sync + Send + DowncastSync { Ok(()) } + /// The main function of the plugin + /// + /// This method is called once all plugins have [`start`](Plugin::start)ed. The plugin is free + /// to spawn new tasks or loop indefinitely (while still observing the cancel token!) + async fn main(&self) -> Result<(), PluginError> { + Ok(()) + } + /// Gracefully handle shutdown /// /// This function is called by the core of thin-edge before the software shuts down as a whole, |