# Path: avatar2/watchmen.py
# AFTER = 'after'
# 
# BEFORE = 'before'
# 
# def watch(watched_type):
#     """
#     Decorator for the watchmen system
#     """
# 
#     def decorator(func):
#         @wraps(func)
#         def watchtrigger(self, *args, **kwargs):
#             # To avoid circular dependencies, we import here ...
#             from .avatar2 import Avatar
#             from .targets.target import Target
# 
#             cb_kwargs = dict(kwargs)
#             if isinstance(self, Avatar):
#                 avatar = self
#             elif isinstance(self, Target):
#                 avatar = self.avatar
#                 cb_kwargs['watched_target'] = self
# 
#             avatar.watchmen.t(watched_type, BEFORE, *args, **cb_kwargs)
#             ret = func(self, *args, **kwargs)
#             cb_kwargs.update({'watched_return': ret})
#             cb_ret = avatar.watchmen.t(watched_type, AFTER, *args, **cb_kwargs)
# 
#             return ret if cb_ret is None else cb_ret
# 
#         return watchtrigger
# 
#     return decorator
# 
# Path: avatar2/targets/target.py
# class TargetStates(IntEnum):
#     """
#     A simple Enum for the different states a target can be in.
#     """
#     CREATED = 0x1
#     INITIALIZED = 0x2
#     STOPPED = 0x4
#     RUNNING = 0x8
#     SYNCING = 0x10
#     EXITED = 0x20
#     NOT_RUNNING = INITIALIZED | STOPPED
#     BREAKPOINT = SYNCING | STOPPED


from types import MethodType
from threading import Event
from enum import Enum
from avatar2.watchmen import AFTER, BEFORE, watch
from avatar2 import TargetStates
                trans.to_target.cont()
            avatar.watchmen.trigger('OrchestrationTransition', AFTER, trans)
    elif avatar.orchestration_stopped.is_set() == False:
        avatar.stop_orchestration(
            OrchestrationStopReason.UNKNOWN_BREAKPOINT_HIT)


@watch('OrchestrationTransitionAdd')
def add_transition(self, address, from_target, to_target,
                   sync_regs=True, synced_ranges=None, stop=False,
                   hw_breakpoint=False):
    if synced_ranges is None:
        synced_ranges = []
    trans = Transition(address, from_target, to_target,
                       sync_regs=sync_regs,
                       synced_ranges=synced_ranges,
                       stop=stop, hw_bkpt=hw_breakpoint)

    self.transitions[(address, from_target)] = trans


@watch('OrchestrationTransitionsEnabled')
def enable_transitions(self):
    for t in self.targets.values():
        if t.state != TargetStates.STOPPED:
            raise Exception("%s has to be stopped to enable transitions" % t)
    for t in self.transitions.values():
        t.bkptno = t.from_target.set_breakpoint(t.address, hardware=t.hw_bkpt)



# Path: avatar2/watchmen.py
# AFTER = 'after'
# 
# BEFORE = 'before'
# 
# def watch(watched_type):
#     """
#     Decorator for the watchmen system
#     """
# 
#     def decorator(func):
#         @wraps(func)
#         def watchtrigger(self, *args, **kwargs):
#             # To avoid circular dependencies, we import here ...
#             from .avatar2 import Avatar
#             from .targets.target import Target
# 
#             cb_kwargs = dict(kwargs)
#             if isinstance(self, Avatar):
#                 avatar = self
#             elif isinstance(self, Target):
#                 avatar = self.avatar
#                 cb_kwargs['watched_target'] = self
# 
#             avatar.watchmen.t(watched_type, BEFORE, *args, **cb_kwargs)
#             ret = func(self, *args, **kwargs)
#             cb_kwargs.update({'watched_return': ret})
#             cb_ret = avatar.watchmen.t(watched_type, AFTER, *args, **cb_kwargs)
# 
#             return ret if cb_ret is None else cb_ret
# 
#         return watchtrigger
# 
#     return decorator
# 
# Path: avatar2/targets/target.py
# class TargetStates(IntEnum):
#     """
#     A simple Enum for the different states a target can be in.
#     """
#     CREATED = 0x1
#     INITIALIZED = 0x2
#     STOPPED = 0x4
#     RUNNING = 0x8
#     SYNCING = 0x10
#     EXITED = 0x20
#     NOT_RUNNING = INITIALIZED | STOPPED
#     BREAKPOINT = SYNCING | STOPPED


# Path: avatar2/plugins/orchestrator.py
from types import MethodType
from threading import Event
from enum import Enum
from avatar2.watchmen import AFTER, BEFORE, watch
from avatar2 import TargetStates

                trans.to_target.cont()
            avatar.watchmen.trigger('OrchestrationTransition', AFTER, trans)
    elif avatar.orchestration_stopped.is_set() == False:
        avatar.stop_orchestration(
            OrchestrationStopReason.UNKNOWN_BREAKPOINT_HIT)


@watch('OrchestrationTransitionAdd')
def add_transition(self, address, from_target, to_target,
                   sync_regs=True, synced_ranges=None, stop=False,
                   hw_breakpoint=False):
    if synced_ranges is None:
        synced_ranges = []
    trans = Transition(address, from_target, to_target,
                       sync_regs=sync_regs,
                       synced_ranges=synced_ranges,
                       stop=stop, hw_bkpt=hw_breakpoint)

    self.transitions[(address, from_target)] = trans


@watch('OrchestrationTransitionsEnabled')
def enable_transitions(self):
    for t in self.targets.values():
        if t.state != TargetStates.STOPPED:
            raise Exception("%s has to be stopped to enable transitions" % t)
    for t in self.transitions.values():
        t.bkptno = t.from_target.set_breakpoint(t.address, hardware=t.hw_bkpt)



@watch('OrchestrationTransitionsDisabled')