mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-15 06:17:16 +00:00
28 lines
647 B
Python
28 lines
647 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):
|
|
self.handle_event(message, self.connector)
|
|
|
|
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
|