baseimage-tutorial-framework/tfw/internals/event_handling/event_handler.py
2019-08-28 16:40:23 +02:00

33 lines
812 B
Python

class EventHandler:
_instances = set()
def __init__(self, connector):
type(self)._instances.add(self)
self.connector = connector
def start(self):
self.connector.register_callback(self._event_callback)
def _event_callback(self, message):
if self._validate_message(message):
self.handle_event(message, self.connector)
def _validate_message(self, message):
# pylint: disable=unused-argument,no-self-use
return True
def handle_event(self, message, connector):
raise NotImplementedError()
@classmethod
def stop_all_instances(cls):
for instance in cls._instances:
instance.stop()
def stop(self):
self.connector.close()
self.cleanup()
def cleanup(self):
pass