got an assembly helper now
This commit is contained in:
@ -180,6 +180,8 @@ impl<R: MessageReceiverProvider<ModeRequest>> ModeRequestReceiver
|
||||
pub enum ModeError {
|
||||
#[error("Messaging error: {0}")]
|
||||
Messaging(#[from] GenericTargetedMessagingError),
|
||||
#[error("busy with other mode request")]
|
||||
Busy,
|
||||
}
|
||||
|
||||
pub trait ModeProvider {
|
||||
|
@ -282,7 +282,7 @@ pub mod alloc_mod {
|
||||
#[derive(Debug)]
|
||||
pub struct ModeStoreVecValue {
|
||||
id: ComponentId,
|
||||
mode_and_submode: ModeAndSubmode,
|
||||
pub mode_and_submode: ModeAndSubmode,
|
||||
pub awaiting_reply: bool,
|
||||
}
|
||||
|
||||
@ -309,6 +309,30 @@ pub mod alloc_mod {
|
||||
#[derive(Debug, Default)]
|
||||
pub struct ModeStoreMap(pub hashbrown::HashMap<ComponentId, ModeAndSubmode>);
|
||||
|
||||
impl ModeStoreVec {
|
||||
/// Generic handler for mode replies received from child components.
|
||||
///
|
||||
/// It returns whether any children are still awating replies.
|
||||
pub fn generic_reply_handler(
|
||||
&mut self,
|
||||
sender_id: ComponentId,
|
||||
reported_mode_and_submode: Option<ModeAndSubmode>,
|
||||
) -> bool {
|
||||
let mut still_awating_replies = false;
|
||||
self.0.iter_mut().for_each(|val| {
|
||||
if val.id() == sender_id {
|
||||
if let Some(mode_and_submode) = reported_mode_and_submode {
|
||||
val.mode_and_submode = mode_and_submode;
|
||||
}
|
||||
val.awaiting_reply = false;
|
||||
}
|
||||
if val.awaiting_reply {
|
||||
still_awating_replies = true;
|
||||
}
|
||||
});
|
||||
still_awating_replies
|
||||
}
|
||||
}
|
||||
impl ModeStoreProvider for ModeStoreVec {
|
||||
fn add_component(&mut self, target_id: ComponentId, mode: ModeAndSubmode) {
|
||||
self.0.push(ModeStoreVecValue::new(target_id, mode));
|
||||
|
@ -28,9 +28,9 @@ pub enum TargetKeepingResult {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum SequenceHandlerResult {
|
||||
SequenceDone,
|
||||
SequenceStepDone,
|
||||
pub enum ModeCommandingResult {
|
||||
CommandingDone,
|
||||
CommandingStepDone,
|
||||
AwaitingSuccessCheck,
|
||||
}
|
||||
|
||||
@ -103,12 +103,12 @@ impl SequenceExecutionHelper {
|
||||
table: &SequenceModeTables,
|
||||
sender: &impl ModeRequestSender,
|
||||
mode_store_vec: &mut ModeStoreVec,
|
||||
) -> Result<SequenceHandlerResult, GenericTargetedMessagingError> {
|
||||
) -> Result<ModeCommandingResult, GenericTargetedMessagingError> {
|
||||
if self.state == SequenceExecutionHelperStates::AwaitingCheckSuccess {
|
||||
return Ok(SequenceHandlerResult::AwaitingSuccessCheck);
|
||||
return Ok(ModeCommandingResult::AwaitingSuccessCheck);
|
||||
}
|
||||
if self.target_mode.is_none() {
|
||||
return Ok(SequenceHandlerResult::SequenceDone);
|
||||
return Ok(ModeCommandingResult::CommandingDone);
|
||||
}
|
||||
match self.current_sequence_index {
|
||||
Some(idx) => {
|
||||
@ -125,7 +125,7 @@ impl SequenceExecutionHelper {
|
||||
// Find the first sequence
|
||||
let seq_table_value = table.0.get(&self.target_mode.unwrap()).unwrap();
|
||||
if seq_table_value.entries.is_empty() {
|
||||
Ok(SequenceHandlerResult::SequenceDone)
|
||||
Ok(ModeCommandingResult::CommandingDone)
|
||||
} else {
|
||||
self.current_sequence_index = Some(0);
|
||||
self.execute_sequence_and_map_to_result(
|
||||
@ -145,7 +145,7 @@ impl SequenceExecutionHelper {
|
||||
sequence_idx: usize,
|
||||
sender: &impl ModeRequestSender,
|
||||
mode_store_vec: &mut ModeStoreVec,
|
||||
) -> Result<SequenceHandlerResult, GenericTargetedMessagingError> {
|
||||
) -> Result<ModeCommandingResult, GenericTargetedMessagingError> {
|
||||
if Self::execute_sequence(
|
||||
self.request_id,
|
||||
&seq_table_value.entries[sequence_idx],
|
||||
@ -153,12 +153,12 @@ impl SequenceExecutionHelper {
|
||||
mode_store_vec,
|
||||
)? {
|
||||
self.state = SequenceExecutionHelperStates::AwaitingCheckSuccess;
|
||||
Ok(SequenceHandlerResult::AwaitingSuccessCheck)
|
||||
Ok(ModeCommandingResult::AwaitingSuccessCheck)
|
||||
} else if seq_table_value.entries.len() - 1 == sequence_idx {
|
||||
return Ok(SequenceHandlerResult::SequenceDone);
|
||||
return Ok(ModeCommandingResult::CommandingDone);
|
||||
} else {
|
||||
self.current_sequence_index = Some(sequence_idx + 1);
|
||||
return Ok(SequenceHandlerResult::SequenceStepDone);
|
||||
return Ok(ModeCommandingResult::CommandingStepDone);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user