baseimage-tutorial-framework/lib/tfw/internals/event_handling/event_handler.py

28 lines
696 B
Python

class EventHandler:
_instances = set()
def __init__(self, server_connector):
type(self)._instances.add(self)
self.server_connector = server_connector
def start(self):
self.server_connector.register_callback(self._event_callback)
def _event_callback(self, message):
self.handle_event(message, self.server_connector)
def handle_event(self, message, server_connector):
raise NotImplementedError()
@classmethod
def stop_all_instances(cls):
for instance in cls._instances:
instance.stop()
def stop(self):
self.server_connector.close()
self.cleanup()
def cleanup(self):
pass