diff options
author | Marcel Müller <m.mueller@ifm.com> | 2022-03-15 09:51:02 +0100 |
---|---|---|
committer | Marcel Müller <m.mueller@ifm.com> | 2022-03-15 11:52:47 +0100 |
commit | 0adada31e7971d469487f75d5f785d2ed28b82d0 (patch) | |
tree | c814808c02b91f8ae5d265b13bbe17bf5b53435f /crates/core/tedge_api/examples/heartbeat.rs | |
parent | beeab26c39aa7ec36d9c5b497a7b6bff3f8edf16 (diff) |
Rename Comms to CoreCommunication
This makes the name clearer and shows that one speaks to the Core that
orchestrates the rest.
Signed-off-by: Marcel Müller <m.mueller@ifm.com>
Diffstat (limited to 'crates/core/tedge_api/examples/heartbeat.rs')
-rw-r--r-- | crates/core/tedge_api/examples/heartbeat.rs | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/crates/core/tedge_api/examples/heartbeat.rs b/crates/core/tedge_api/examples/heartbeat.rs index 5c96a0fc..10c1a6c6 100644 --- a/crates/core/tedge_api/examples/heartbeat.rs +++ b/crates/core/tedge_api/examples/heartbeat.rs @@ -1,6 +1,6 @@ use async_trait::async_trait; use tedge_api::{ - address::EndpointKind, Address, Comms, Message, MessageKind, Plugin, PluginBuilder, + address::EndpointKind, Address, CoreCommunication, Message, MessageKind, Plugin, PluginBuilder, PluginConfiguration, PluginError, }; @@ -15,14 +15,14 @@ impl PluginBuilder for HeartbeatServiceBuilder { async fn verify_configuration( &self, _config: &PluginConfiguration, - ) -> Result<(), tedge_api::errors::PluginError> { + ) -> Result<(), tedge_api::error::PluginError> { Ok(()) } async fn instantiate( &self, config: PluginConfiguration, - tedge_comms: tedge_api::plugins::Comms, + tedge_comms: tedge_api::plugin::CoreCommunication, ) -> Result<Box<dyn Plugin>, PluginError> { let hb_config: HeartbeatConfig = toml::Value::try_into(config.into_inner())?; Ok(Box::new(HeartbeatService::new(tedge_comms, hb_config))) @@ -35,12 +35,12 @@ struct HeartbeatConfig { } struct HeartbeatService { - comms: tedge_api::plugins::Comms, + comms: tedge_api::plugin::CoreCommunication, config: HeartbeatConfig, } impl HeartbeatService { - fn new(comms: tedge_api::plugins::Comms, config: HeartbeatConfig) -> Self { + fn new(comms: tedge_api::plugin::CoreCommunication, config: HeartbeatConfig) -> Self { Self { comms, config } } } @@ -61,8 +61,7 @@ impl Plugin for HeartbeatService { let kind = MessageKind::SignalPluginState { state: String::from("Ok"), }; - let msg = self.comms.new_message(message.origin().clone(), kind); - self.comms.send(msg).await?; + self.comms.send(kind, message.origin().clone()).await?; } msg => println!("Does not handle: {:#?}", msg), } @@ -81,7 +80,8 @@ async fn main() { let hsb = HeartbeatServiceBuilder; let (sender, mut receiver) = tokio::sync::mpsc::channel(10); - let comms = Comms::new("heartbeat-service".to_string(), sender); + let plugin_name = "heartbeat-service".to_string(); + let comms = CoreCommunication::new(plugin_name.clone(), sender); let config = toml::from_str( r#" @@ -97,10 +97,9 @@ async fn main() { let handle = tokio::task::spawn(async move { let hb = heartbeat; - hb.handle_message(comms.new_message( - Address::new(EndpointKind::Plugin { - id: "heartbeat-service".to_string(), - }), + hb.handle_message(Message::new( + Address::new(EndpointKind::Plugin { id: plugin_name }), + Address::new(EndpointKind::Core), MessageKind::CheckReadyness, )) .await |