mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-12-22 22:21:56 +00:00
Refactor FSMAware part from FSMAwareEH to a separate class
This commit is contained in:
parent
8c6a14cef5
commit
d718b6425e
@ -106,25 +106,17 @@ class EventHandlerBase(ABC):
|
||||
pass
|
||||
|
||||
|
||||
class FSMAwareEventHandler(EventHandlerBase, ABC):
|
||||
# pylint: disable=abstract-method
|
||||
"""
|
||||
Abstract base class for EventHandlers which automatically
|
||||
keep track of the state of the TFW FSM.
|
||||
"""
|
||||
def __init__(self, key):
|
||||
super().__init__(key)
|
||||
self.subscribe('fsm_update')
|
||||
class FSMAware:
|
||||
def __init__(self):
|
||||
self.fsm_state = None
|
||||
self.in_accepted_state = False
|
||||
self._auth_key = KeyManager().auth_key
|
||||
|
||||
def dispatch_handling(self, message):
|
||||
if message['key'] == 'fsm_update':
|
||||
if verify_message(self._auth_key, message):
|
||||
self._handle_fsm_update(message)
|
||||
return None
|
||||
return super().dispatch_handling(message)
|
||||
def update_fsm_data(self, message):
|
||||
if message['key'] == 'fsm_update' and verify_message(self._auth_key, message):
|
||||
self._handle_fsm_update(message)
|
||||
return True
|
||||
return False
|
||||
|
||||
def _handle_fsm_update(self, message):
|
||||
try:
|
||||
@ -144,6 +136,23 @@ class FSMAwareEventHandler(EventHandlerBase, ABC):
|
||||
pass
|
||||
|
||||
|
||||
class FSMAwareEventHandler(EventHandlerBase, FSMAware, ABC):
|
||||
# pylint: disable=abstract-method
|
||||
"""
|
||||
Abstract base class for EventHandlers which automatically
|
||||
keep track of the state of the TFW FSM.
|
||||
"""
|
||||
def __init__(self, key):
|
||||
EventHandlerBase.__init__(self, key)
|
||||
FSMAware.__init__(self)
|
||||
self.subscribe('fsm_update')
|
||||
|
||||
def dispatch_handling(self, message):
|
||||
if self.update_fsm_data(message):
|
||||
return None
|
||||
return super().dispatch_handling(message)
|
||||
|
||||
|
||||
class BroadcastingEventHandler(EventHandlerBase, ABC):
|
||||
# pylint: disable=abstract-method
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user