Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting "any" state transitions in FSM #344

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions direct/src/fsm/FSM.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ def filterGreen(self, request, args):
# must be approved by some filter function.
defaultTransitions = None

# An enum class for special states like the DEFAULT or ANY state,
# that should be treatened by the FSM in a special way
class EnumStates():
ANY = 1
DEFAULT = 2

def __init__(self, name):
self.fsmLock = RLock()
self._name = name
Expand Down Expand Up @@ -376,6 +382,27 @@ def defaultFilter(self, request, args):
# accept it.
return (request,) + args

elif FSM.EnumStates.ANY in self.defaultTransitions.get(self.state, []):
# Whenever we have a '*' as our to transition, we allow
# to transit to any other state
return (request,) + args

elif request in self.defaultTransitions.get(FSM.EnumStates.ANY, []):
# If the requested state is in the default transitions
# from any state list, we also alow to transit to the
# new state
return (request,) + args

elif FSM.EnumStates.ANY in self.defaultTransitions.get(FSM.EnumStates.ANY, []):
# This is like we had set the defaultTransitions to None.
# Any state can transit to any other state
return (request,) + args

elif request in self.defaultTransitions.get(FSM.EnumStates.DEFAULT, []):
# This is the fallback state that we use whenever no
# other trnasition was possible
return (request,) + args

# If self.defaultTransitions is not None, it is an error
# to request a direct state transition (capital letter
# request) not listed in defaultTransitions and not
Expand Down