# Path: flexbe_mirror/src/flexbe_mirror/mirror_state.py
# class MirrorState(EventState):
#     '''
#     This state will display its possible outcomes as buttons in the GUI
#     and is designed in a way to be created dynamically.
#     '''
# 
#     def __init__(self, target_name, target_path, given_outcomes, outcome_autonomy):
#         super(MirrorState, self).__init__(outcomes=given_outcomes)
#         self.set_rate(100)
#         self._target_name = target_name
#         self._target_path = target_path
# 
#         self._outcome_topic = 'flexbe/mirror/outcome'
# 
#         self._pub = ProxyPublisher()
#         self._sub = ProxySubscriberCached({self._outcome_topic: UInt8})
# 
#     def execute(self, userdata):
#         if self._sub.has_buffered(self._outcome_topic):
#             msg = self._sub.get_from_buffer(self._outcome_topic)
#             if msg.data < len(self.outcomes):
#                 rospy.loginfo("State update: %s > %s", self._target_name, self.outcomes[msg.data])
#                 return self.outcomes[msg.data]
#         try:
#             self.sleep()
#         except ROSInterruptException:
#             print('Interrupted mirror sleep.')
# 
#     def on_enter(self, userdata):
#         self._pub.publish('flexbe/behavior_update', String("/" + "/".join(self._target_path.split("/")[1:])))


import rospy
import threading
import zlib
from flexbe_core.core import PreemptableState, PreemptableStateMachine, LockableStateMachine
from .mirror_state import MirrorState
from flexbe_core.proxy import ProxyPublisher, ProxySubscriberCached
from flexbe_msgs.msg import ContainerStructure, BehaviorSync, BEStatus
from std_msgs.msg import Empty, String, Int32, UInt8
        for con_msg in msg.containers:
            if con_msg.path == path:
                container = con_msg
                break

        transitions = None
        if container.transitions is not None:
            transitions = {}
            for i in range(len(container.transitions)):
                transitions[container.outcomes[i]] = container.transitions[i] + '_mirror'

        path_frags = path.split('/')
        container_name = path_frags[len(path_frags)-1]
        if len(container.children) > 0:
            sm_outcomes = []
            for outcome in container.outcomes:
                sm_outcomes.append(outcome + '_mirror')
            sm = PreemptableStateMachine(outcomes=sm_outcomes)
            with sm:
                for child in container.children:
                    self._add_node(msg, path+'/'+child)
            if len(transitions) > 0:
                container_transitions = {}
                for i in range(len(container.transitions)):
                    container_transitions[sm_outcomes[i]] = transitions[container.outcomes[i]]
                PreemptableStateMachine.add(container_name + '_mirror', sm, transitions=container_transitions)
            else:
                self._sm = sm
        else:
            PreemptableStateMachine.add(container_name + '_mirror',

# Path: flexbe_mirror/src/flexbe_mirror/mirror_state.py
# class MirrorState(EventState):
#     '''
#     This state will display its possible outcomes as buttons in the GUI
#     and is designed in a way to be created dynamically.
#     '''
# 
#     def __init__(self, target_name, target_path, given_outcomes, outcome_autonomy):
#         super(MirrorState, self).__init__(outcomes=given_outcomes)
#         self.set_rate(100)
#         self._target_name = target_name
#         self._target_path = target_path
# 
#         self._outcome_topic = 'flexbe/mirror/outcome'
# 
#         self._pub = ProxyPublisher()
#         self._sub = ProxySubscriberCached({self._outcome_topic: UInt8})
# 
#     def execute(self, userdata):
#         if self._sub.has_buffered(self._outcome_topic):
#             msg = self._sub.get_from_buffer(self._outcome_topic)
#             if msg.data < len(self.outcomes):
#                 rospy.loginfo("State update: %s > %s", self._target_name, self.outcomes[msg.data])
#                 return self.outcomes[msg.data]
#         try:
#             self.sleep()
#         except ROSInterruptException:
#             print('Interrupted mirror sleep.')
# 
#     def on_enter(self, userdata):
#         self._pub.publish('flexbe/behavior_update', String("/" + "/".join(self._target_path.split("/")[1:])))


# Path: flexbe_mirror/src/flexbe_mirror/flexbe_mirror.py
import rospy
import threading
import zlib
from flexbe_core.core import PreemptableState, PreemptableStateMachine, LockableStateMachine
from .mirror_state import MirrorState
from flexbe_core.proxy import ProxyPublisher, ProxySubscriberCached
from flexbe_msgs.msg import ContainerStructure, BehaviorSync, BEStatus
from std_msgs.msg import Empty, String, Int32, UInt8

        for con_msg in msg.containers:
            if con_msg.path == path:
                container = con_msg
                break

        transitions = None
        if container.transitions is not None:
            transitions = {}
            for i in range(len(container.transitions)):
                transitions[container.outcomes[i]] = container.transitions[i] + '_mirror'

        path_frags = path.split('/')
        container_name = path_frags[len(path_frags)-1]
        if len(container.children) > 0:
            sm_outcomes = []
            for outcome in container.outcomes:
                sm_outcomes.append(outcome + '_mirror')
            sm = PreemptableStateMachine(outcomes=sm_outcomes)
            with sm:
                for child in container.children:
                    self._add_node(msg, path+'/'+child)
            if len(transitions) > 0:
                container_transitions = {}
                for i in range(len(container.transitions)):
                    container_transitions[sm_outcomes[i]] = transitions[container.outcomes[i]]
                PreemptableStateMachine.add(container_name + '_mirror', sm, transitions=container_transitions)
            else:
                self._sm = sm
        else:
            PreemptableStateMachine.add(container_name + '_mirror',

                                        MirrorState(container_name, path, container.outcomes, container.autonomy),