MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ transition_state()

bool MayaFlux::Kakshya::transition_state ( ProcessingState current_state,
ProcessingState  new_state,
std::function< void()>  on_transition = nullptr 
)

Perform a state transition for a ProcessingState, with optional callback.

Parameters
current_stateCurrent state (modified in place).
new_stateState to transition to.
on_transitionOptional callback to invoke on transition.
Returns
True if transition was valid and performed.

Definition at line 56 of file ContainerUtils.cpp.

57{
58 static const std::unordered_map<ProcessingState, std::unordered_set<ProcessingState>> valid_transitions = {
59 { ProcessingState::IDLE, { ProcessingState::READY, ProcessingState::ERROR } },
60 { ProcessingState::READY, { ProcessingState::PROCESSING, ProcessingState::IDLE, ProcessingState::ERROR } },
61 { ProcessingState::PROCESSING, { ProcessingState::PROCESSED, ProcessingState::ERROR } },
62 { ProcessingState::PROCESSED, { ProcessingState::READY, ProcessingState::IDLE } },
63 { ProcessingState::ERROR, { ProcessingState::IDLE } },
64 { ProcessingState::NEEDS_REMOVAL, { ProcessingState::IDLE } }
65 };
66 auto it = valid_transitions.find(current_state);
67 if (it != valid_transitions.end() && (it->second.count(new_state) != 0U)) {
68 current_state = new_state;
69 if (on_transition)
70 on_transition();
71 return true;
72 }
73 return false;
74}

References ERROR, IDLE, NEEDS_REMOVAL, PROCESSED, PROCESSING, and READY.