mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-05 14:51:22 +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
|
pass
|
||||||
|
|
||||||
|
|
||||||
class FSMAwareEventHandler(EventHandlerBase, ABC):
|
class FSMAware:
|
||||||
# pylint: disable=abstract-method
|
def __init__(self):
|
||||||
"""
|
|
||||||
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')
|
|
||||||
self.fsm_state = None
|
self.fsm_state = None
|
||||||
self.in_accepted_state = False
|
self.in_accepted_state = False
|
||||||
self._auth_key = KeyManager().auth_key
|
self._auth_key = KeyManager().auth_key
|
||||||
|
|
||||||
def dispatch_handling(self, message):
|
def update_fsm_data(self, message):
|
||||||
if message['key'] == 'fsm_update':
|
if message['key'] == 'fsm_update' and verify_message(self._auth_key, message):
|
||||||
if verify_message(self._auth_key, message):
|
|
||||||
self._handle_fsm_update(message)
|
self._handle_fsm_update(message)
|
||||||
return None
|
return True
|
||||||
return super().dispatch_handling(message)
|
return False
|
||||||
|
|
||||||
def _handle_fsm_update(self, message):
|
def _handle_fsm_update(self, message):
|
||||||
try:
|
try:
|
||||||
@ -144,6 +136,23 @@ class FSMAwareEventHandler(EventHandlerBase, ABC):
|
|||||||
pass
|
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):
|
class BroadcastingEventHandler(EventHandlerBase, ABC):
|
||||||
# pylint: disable=abstract-method
|
# pylint: disable=abstract-method
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user