RustyLee: Validates organ responses before command processing
Ensures the brain only processes commands from organs that return an 'Ok' response. Specifically, the 'Waken' command now requires an 'Ok' response to transition the brain to the 'Awake' state, improving the robustness of inter-organ communication.
This commit is contained in:
parent
33ae160566
commit
2439de214b
1 changed files with 15 additions and 4 deletions
|
|
@ -4,7 +4,7 @@ use crate::lifecycle::{LifeState, LifecycleCommand, LifecycleCommandResponse, Li
|
|||
use crate::lifecycle::LifeState::{Dying, Buried, Genisys, Dead};
|
||||
use crate::organs::organ_factory::OrganFactory;
|
||||
use crate::organs::organ_socket::OrganSocket;
|
||||
use crate::protocols::{BrainMessage, OrganCommand, OrganCommandEnvelope};
|
||||
use crate::protocols::{BrainMessage, OrganCommand, OrganCommandEnvelope, OrganResponse};
|
||||
use crate::system::time::Time;
|
||||
|
||||
pub struct Brain {
|
||||
|
|
@ -155,9 +155,20 @@ impl Brain {
|
|||
|
||||
fn process_message_from_organ(&mut self, message: BrainMessage) {
|
||||
debug!("organ message received: {:?}.", message);
|
||||
if let OrganCommand::Waken = message.organ_command.command {
|
||||
self.state = LifeState::Awake;
|
||||
}
|
||||
if let OrganResponse::Ok = message.response{
|
||||
match message.organ_command.command {
|
||||
OrganCommand::Waken => {
|
||||
self.state = LifeState::Awake;
|
||||
}
|
||||
|
||||
_ => {
|
||||
debug!("organ message received, no action taken: {:?}.", message.organ_command);
|
||||
}
|
||||
}
|
||||
|
||||
if let OrganCommand::Waken = message.organ_command.command {
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue