The Brain now broadcasts a 'Waken' command to all connected organs during its startup phase. Organs, like the Heart, transition to an 'Awake' state upon receiving this command and provide feedback. The Brain then updates its own 'LifeState' to 'Awake' once organs acknowledge the wake-up. This change establishes a fundamental handshake, ensuring that core system functions only activate once the components are initialized and responsive. It introduces the `LifeState::Awake` and `OrganCommand::Waken` states for this purpose.
57 lines
1.4 KiB
Rust
57 lines
1.4 KiB
Rust
use std::time::Instant;
|
|
use std::fmt;
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
pub enum LifeState {
|
|
Dead,
|
|
Genisys,
|
|
// Sleeping,
|
|
// Wakening,
|
|
Awake,
|
|
// DeepThought,
|
|
// ActionFocused,
|
|
// Flight,
|
|
// Panic,
|
|
Dying,
|
|
Buried,
|
|
}
|
|
|
|
impl fmt::Display for LifeState {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
let state_str = match self {
|
|
LifeState::Dead => "Dead",
|
|
LifeState::Genisys => "In Genesis",
|
|
// LifeState::Sleeping => "Sleeping",
|
|
// LifeState::Wakening => "Wakening",
|
|
LifeState::Awake => "Fully Awake",
|
|
// LifeState::DeepThought => "In Deep Thought",
|
|
// LifeState::ActionFocused => "Action Focused",
|
|
// LifeState::Flight => "In Flight",
|
|
// LifeState::Panic => "PANIC!",
|
|
LifeState::Dying => "Dying",
|
|
LifeState::Buried => "Buried",
|
|
};
|
|
write!(f, "{}", state_str)
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
pub enum LifecycleCommandResponse {
|
|
Ok,
|
|
Refused,
|
|
Failed
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct LifecycleCommand {
|
|
pub required_state: LifeState,
|
|
pub command_time: Instant
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct LifecycleReceipt {
|
|
pub command: LifecycleCommand,
|
|
pub response: LifecycleCommandResponse,
|
|
pub new_state: LifeState
|
|
}
|
|
|