diff --git a/src/rustylee/src/brain.rs b/src/rustylee/src/brain.rs index 9a9765a..bde1fd3 100644 --- a/src/rustylee/src/brain.rs +++ b/src/rustylee/src/brain.rs @@ -1,4 +1,4 @@ -use tracing::{debug, info}; +use tracing::{debug, info, instrument}; use std::sync::mpsc::{Receiver, Sender}; use crate::lifecycle::{LifeState, LifecycleCommand, LifecycleCommandResponse, LifecycleReceipt}; use crate::lifecycle::LifeState::{Dying, Buried, Genisys, Dead}; @@ -7,6 +7,7 @@ use crate::organs::organ_socket::OrganSocket; use crate::protocols::{BrainMessage, OrganCommand, OrganCommandEnvelope, OrganResponse}; use crate::system::time::Time; +#[derive(Debug)] pub struct Brain { state:LifeState, divine_rx : Receiver, @@ -59,6 +60,7 @@ impl Brain { } } + #[instrument(skip(self), fields(state=?self.state))] fn rest(&self) { debug!("Brain is {} and resting.", self.state); std::thread::sleep(std::time::Duration::from_millis(200)) diff --git a/src/rustylee/src/child_identity.rs b/src/rustylee/src/child_identity.rs index 3dadd56..5ff274c 100644 --- a/src/rustylee/src/child_identity.rs +++ b/src/rustylee/src/child_identity.rs @@ -1,7 +1,7 @@ #[derive(Debug, Clone, Copy)] pub struct ChildIdentity { - id: u32, - parent_id: u32, + pub id: u32, + pub parent_id: u32, } impl ChildIdentity { diff --git a/src/rustylee/src/organs/led_pump.rs b/src/rustylee/src/organs/led_pump.rs index cdb53b0..57a29c2 100644 --- a/src/rustylee/src/organs/led_pump.rs +++ b/src/rustylee/src/organs/led_pump.rs @@ -3,13 +3,16 @@ use crate::organs::parenchyma::Parenchyma; use crate::protocols::{OrganCommand, OrganCommandEnvelope, OrganResponse}; use crate::system::time::Time; use crate::{child_identity, impl_identifiable}; -use tracing::{info}; +use tracing::{info, instrument}; +#[derive(Debug)] pub struct LedPump { identity: child_identity::ChildIdentity, last_beat: u64, } impl_identifiable!(LedPump, { + #[instrument(skip(self), fields(led_pump_id = self.identity.id))] + fn do_work(&mut self, _envelope: OrganCommandEnvelope) -> OrganResponse { // Your logic here let now = Time::time_stamp_millis(); diff --git a/src/rustylee/src/organs/organ.rs b/src/rustylee/src/organs/organ.rs index 069ca27..8dd7627 100644 --- a/src/rustylee/src/organs/organ.rs +++ b/src/rustylee/src/organs/organ.rs @@ -6,16 +6,6 @@ use crate::organs::parenchyma::Parenchyma; use crate::protocols::{BrainMessage, OrganCommand, OrganCommandEnvelope, OrganResponse}; use crate::system::time::Time; - - -// pub trait Organ: Send { -// /// Returns the immutable U32 ID assigned by the factory. -// fn id(&self) -> u32; -// -// fn add_parenchyma(&mut self, parenchyma: Box); -// } - - pub struct Organ { id: u32, brain_command_rx: mpsc::Receiver, @@ -45,8 +35,12 @@ impl Organ { } } - #[instrument(skip(self), fields(heart_id = self.id))] pub fn start(&mut self) { + self.run_organ_message_loop(); + } + + #[instrument(skip(self), fields(heart_id = self.id))] + fn run_organ_message_loop(&mut self) { info!("Heart listener active"); while let Ok(envelope) = self.brain_command_rx.recv() { diff --git a/src/rustylee/src/organs/organ_socket.rs b/src/rustylee/src/organs/organ_socket.rs index 62a303c..b62e5dd 100644 --- a/src/rustylee/src/organs/organ_socket.rs +++ b/src/rustylee/src/organs/organ_socket.rs @@ -3,6 +3,7 @@ use std::sync::mpsc::Sender; use crate::lifecycle::LifeState; use crate::protocols::{OrganCommand, OrganCommandEnvelope}; +#[derive(Debug)] pub struct OrganSocket { pub id: u32, pub last_reported_state : LifeState,