summaryrefslogtreecommitdiffstats
path: root/crates/core/tedge_api/examples/heartbeat.rs
diff options
context:
space:
mode:
authorMarcel Müller <m.mueller@ifm.com>2022-02-15 10:17:10 +0100
committerMatthias Beyer <matthias.beyer@ifm.com>2022-03-04 15:03:53 +0100
commit16b31b20b7fa0a79544f1a827cee392a2f256789 (patch)
treecc17860e5c72374a734cd14c7eac1690d456b338 /crates/core/tedge_api/examples/heartbeat.rs
parentdf08d5bd1ea767ddfd67db7de39159f1588f86d5 (diff)
Merge PluginMessage and CoreMessage to Message
Having only a single message type makes the implementation easier and allows for a leaner core. This in turn allows for easier abstractions on the plugin side, as only a single type of messages exists. 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/examples/heartbeat.rs')
-rw-r--r--crates/core/tedge_api/examples/heartbeat.rs24
1 files changed, 13 insertions, 11 deletions
diff --git a/crates/core/tedge_api/examples/heartbeat.rs b/crates/core/tedge_api/examples/heartbeat.rs
index cac8b973..e8d237f5 100644
--- a/crates/core/tedge_api/examples/heartbeat.rs
+++ b/crates/core/tedge_api/examples/heartbeat.rs
@@ -1,9 +1,7 @@
use async_trait::async_trait;
use tedge_api::{
- address::EndpointKind,
- messages::{CoreMessageKind, PluginMessageKind},
- plugins::Comms,
- Address, CoreMessage, Plugin, PluginBuilder, PluginConfiguration, PluginError, PluginMessage,
+ address::EndpointKind, Address, Comms, Message, MessageKind, Plugin, PluginBuilder,
+ PluginConfiguration, PluginError,
};
struct HeartbeatServiceBuilder;
@@ -50,21 +48,25 @@ impl HeartbeatService {
#[async_trait]
impl Plugin for HeartbeatService {
async fn setup(&mut self) -> Result<(), PluginError> {
- println!("Setting up heartbeat service with interval: {}!", self.config.interval);
+ println!(
+ "Setting up heartbeat service with interval: {}!",
+ self.config.interval
+ );
Ok(())
}
- async fn handle_message(&self, message: PluginMessage) -> Result<(), PluginError> {
+ async fn handle_message(&self, message: Message) -> Result<(), PluginError> {
match message.kind() {
- tedge_api::messages::PluginMessageKind::CheckReadyness => {
- let msg = CoreMessage::new(
+ MessageKind::CheckReadyness => {
+ let msg = Message::new(
message.origin().clone(),
- CoreMessageKind::SignalPluginState {
+ MessageKind::SignalPluginState {
state: String::from("Ok"),
},
);
self.comms.send(msg).await?;
}
+ msg => println!("Does not handle: {:#?}", msg),
}
Ok(())
@@ -97,9 +99,9 @@ async fn main() {
let handle = tokio::task::spawn(async move {
let hb = heartbeat;
- hb.handle_message(PluginMessage::new(
+ hb.handle_message(Message::new(
Address::new(EndpointKind::Core),
- PluginMessageKind::CheckReadyness,
+ MessageKind::CheckReadyness,
))
.await
.unwrap();