mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-12-23 07:11:56 +00:00
Rework FSMManager predicate contract
This commit is contained in:
parent
250b9da6d6
commit
5d7223779a
@ -4,6 +4,7 @@ from collections import defaultdict
|
||||
from tfw.networking.server.controller_responder import ControllerResponder
|
||||
from tfw.networking.server.zmq_websocket_handler import ZMQWebSocketProxy
|
||||
from tfw.networking.event_handlers.server_connector import ServerUplinkConnector
|
||||
from tfw.message_sender import MessageSender
|
||||
from tfw.config.logs import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@ -42,13 +43,20 @@ class FSMManager:
|
||||
def __init__(self, fsm):
|
||||
self._fsm = fsm
|
||||
self.trigger_predicates = defaultdict(list)
|
||||
self.messenge_sender = MessageSender()
|
||||
|
||||
@property
|
||||
def fsm(self):
|
||||
return self._fsm
|
||||
|
||||
def trigger(self, trigger, message):
|
||||
if all((predicate() for predicate in self.trigger_predicates[trigger])):
|
||||
predicate_results = []
|
||||
for predicate in self.trigger_predicates[trigger]:
|
||||
success, message = predicate()
|
||||
predicate_results.append(success)
|
||||
self.messenge_sender.send('FSM', message)
|
||||
|
||||
if all(predicate_results):
|
||||
try: self.fsm.trigger(trigger, message=message)
|
||||
except AttributeError: log.debug('FSM failed to execute nonexistent trigger: "{}"'.format(trigger))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user