def _build_structure_msg(self): """ Creates a message to describe the structure of this state machine. """ structure_msg = ContainerStructure() container_msg = self._add_to_structure_msg(structure_msg) container_msg.outcomes = self.outcomes structure_msg.behavior_id = self.id return structure_msg
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