From 0adada31e7971d469487f75d5f785d2ed28b82d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Tue, 15 Mar 2022 09:51:02 +0100 Subject: Rename Comms to CoreCommunication MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes the name clearer and shows that one speaks to the Core that orchestrates the rest. Signed-off-by: Marcel Müller --- crates/core/tedge_api/examples/heartbeat.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'crates/core/tedge_api/examples') 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, 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 -- cgit v1.2.3