diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-11-22 16:14:06 +0100 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-11-23 16:16:09 +0100 |
| commit | 4a4b3f0a1c008e35a4492b7fd05176d1822c7232 (patch) | |
| tree | 287ac69b6f89524282d4e2cbc85c6d8030285c88 /wrappers/python/eduvpn_common/event.py | |
| parent | ea07a6d7b2df9b09d8e4c796b2416a60ba90144a (diff) | |
FSM: Check unhandled transitions
Diffstat (limited to 'wrappers/python/eduvpn_common/event.py')
| -rw-r--r-- | wrappers/python/eduvpn_common/event.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/wrappers/python/eduvpn_common/event.py b/wrappers/python/eduvpn_common/event.py index 1823130..4387222 100644 --- a/wrappers/python/eduvpn_common/event.py +++ b/wrappers/python/eduvpn_common/event.py @@ -147,7 +147,7 @@ class EventHandler(object): def run_state( self, state: int, other_state: int, state_type: StateType, data: str - ) -> None: + ) -> bool: """The function that runs the callback for a specific event :param state: int: The state of the event @@ -158,13 +158,14 @@ class EventHandler(object): :meta private: """ if (state, state_type) not in self.handlers: - return + return False for func in self.handlers[(state, state_type)]: func(other_state, data) + return True def run( self, old_state: int, new_state: int, data: Any, convert: bool = True - ) -> None: + ) -> bool: """Run a specific event. It converts the data and then runs the event for all state types @@ -180,5 +181,9 @@ class EventHandler(object): if convert: converted = convert_data(self.lib, new_state, data) self.run_state(old_state, new_state, StateType.LEAVE, converted) - self.run_state(new_state, old_state, StateType.ENTER, converted) - self.run_state(new_state, old_state, StateType.WAIT, converted) + # We decide handled based on enter transitions + handled = self.run_state(new_state, old_state, StateType.ENTER, converted) + # Only run wait transitions if the enter transition is handled + if handled: + self.run_state(new_state, old_state, StateType.WAIT, converted) + return handled |
