diff --git a/hbmqtt/broker.py b/hbmqtt/broker.py index 2e434ca..9643d43 100644 --- a/hbmqtt/broker.py +++ b/hbmqtt/broker.py @@ -116,8 +116,9 @@ class BrokerContext(BaseContext): BrokerContext is used as the context passed to plugins interacting with the broker. It act as an adapter to broker services from plugins developed for HBMQTT broker """ - def __init__(self, loop=None): - super().__init__(loop) + def __init__(self): + super().__init__() + self.config = None class Broker: @@ -177,7 +178,9 @@ class Broker: self.sys_handle = None # Init plugins manager - self.plugins_manager = PluginManager('hbmqtt.broker.plugins', BrokerContext(self._loop), self._loop) + context = BrokerContext() + context.config = self.config + self.plugins_manager = PluginManager('hbmqtt.broker.plugins', context, self._loop) def _build_listeners_config(self, broker_config): self.listeners_config = dict() diff --git a/hbmqtt/client.py b/hbmqtt/client.py index 5810ff2..8479f44 100644 --- a/hbmqtt/client.py +++ b/hbmqtt/client.py @@ -38,8 +38,9 @@ class ClientContext(BaseContext): ClientContext is used as the context passed to plugins interacting with the client. It act as an adapter to client services from plugins """ - def __init__(self, client): - super().__init__(client._loop) + def __init__(self): + super().__init__() + self.config = None class MQTTClient: @@ -89,7 +90,9 @@ class MQTTClient: self._connection_closed_future = None # Init plugins manager - self.plugins_manager = PluginManager('hbmqtt.client.plugins', ClientContext(self)) + context = ClientContext() + context.config = self.config + self.plugins_manager = PluginManager('hbmqtt.client.plugins', context) @asyncio.coroutine diff --git a/hbmqtt/plugins/manager.py b/hbmqtt/plugins/manager.py index 34f2efc..c2448d4 100644 --- a/hbmqtt/plugins/manager.py +++ b/hbmqtt/plugins/manager.py @@ -22,11 +22,8 @@ def get_plugin_manager(namespace): class BaseContext: - def __init__(self, loop=None): - if loop is not None: - self._loop = loop - else: - self._loop = asyncio.get_event_loop() + def __init__(self): + self.loop = None self.logger = None @@ -48,6 +45,7 @@ class PluginManager: self.context = BaseContext() else: self.context = context + context.loop = loop self._plugins = [] self._load_plugins(namespace) self._fired_events = []