mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 21:31:31 +00:00
Implement crude FSMManager – wip
This commit is contained in:
parent
41a32437b2
commit
5e9eb88bfc
@ -36,6 +36,30 @@ class TFWServer:
|
||||
self.application.listen(port)
|
||||
|
||||
|
||||
class FSMManager:
|
||||
def __init__(self, fsm_type):
|
||||
self.fsm = fsm_type()
|
||||
self.trigger_handlers = {}
|
||||
|
||||
def trigger(self, trigger):
|
||||
self._prepare_handlerlist(trigger)
|
||||
if all((handler() for handler in self.trigger_handlers[trigger])):
|
||||
try: self.fsm.trigger(trigger, message='')
|
||||
except AttributeError: log.debug('FSM failed to execute nonexistent trigger: "{}"'.format(trigger))
|
||||
|
||||
def subscribe_handler(self, trigger, handler):
|
||||
self._prepare_handlerlist(trigger)
|
||||
self.trigger_handlers[trigger].append(handler)
|
||||
|
||||
def unsubscribe_handler(self, trigger, handler):
|
||||
self._prepare_handlerlist(trigger)
|
||||
self.trigger_handlers[trigger].append(handler)
|
||||
|
||||
def _prepare_handlerlist(self, trigger):
|
||||
try: self.trigger_handlers[trigger]
|
||||
except KeyError: self.trigger_handlers[trigger] = []
|
||||
|
||||
|
||||
class FSMUpdater:
|
||||
def __init__(self, fsm):
|
||||
self.fsm = fsm
|
||||
|
Loading…
Reference in New Issue
Block a user