def _add_to_structure_msg(self, structure_msg): """ Adds this state machine and all children to the structure message. @type structure_msg: ContainerStructure @param structure_msg: The message that will finally contain the structure message. """ # add self to message container_msg = Container() container_msg.path = self.path container_msg.children = [state.name for state in self._states] structure_msg.containers.append(container_msg) # add children to message for state in self._states: # create and add children if isinstance(state, OperatableStateMachine): state_msg = state._add_to_structure_msg(structure_msg) else: state_msg = Container(path=state.path) structure_msg.containers.append(state_msg) # complete structure info for children state_msg.outcomes = state.outcomes state_msg.transitions = [ self._transitions[state.name][outcome] for outcome in state.outcomes ] state_msg.autonomy = [ self._autonomy[state.name][outcome] for outcome in state.outcomes ] return container_msg
def _build_msg(self, prefix, msg): """ Adds this state to the initial structure message. @type prefix: string @param prefix: A path consisting of the container hierarchy containing this state. @type msg: ContainerStructure @param msg: The message that will finally contain the structure message. """ # set path name = prefix + self.name # no children children = None # set outcomes outcomes = self._outcome_list # set transitions and autonomy levels transitions = [] autonomy = [] for i in range(len(outcomes)): outcome = outcomes[i] if outcome == 'preempted': # set preempt transition transitions.append('preempted') autonomy.append(-1) else: transitions.append(str(self.transitions[outcome])) autonomy.append(self.autonomy[outcome]) # add to message msg.containers.append(Container(name, children, outcomes, transitions, autonomy))
def _build_msg(self, prefix, msg=None): """ Adds this state machine to the initial structure message. @type prefix: string @param prefix: A path consisting of the container hierarchy containing this state. @type msg: ContainerStructure @param msg: The message that will finally contain the structure message. """ # set children children = [] for state in self._ordered_states: children.append(str(state.name)) # set name name = prefix + (self.name if self.id is None else '') if msg is None: # top-level state machine (has no transitions) self._message = ContainerStructure() outcomes = list(self._outcomes) transitions = None autonomy = None else: # lower-level state machine self._message = msg outcomes = list(self.transitions) # set transitions and autonomy transitions = [] autonomy = [] for i in range(len(self.transitions)): outcome = outcomes[i] if outcome == 'preempted': # set preempt transition transitions.append('preempted') autonomy.append(-1) else: transitions.append(str(self.transitions[outcome])) autonomy.append(self.autonomy[outcome]) # add to message self._message.containers.append( Container(name, children, outcomes, transitions, autonomy)) # build message for children for state in self._ordered_states: state._build_msg(name + '/', self._message) # top-level state machine returns the message if msg is None: return self._message