Add session to event fired

pull/8/head
Nicolas Jouanin 2015-08-18 20:56:06 +02:00
rodzic 18cba2f53d
commit db79e460d3
2 zmienionych plików z 11 dodań i 7 usunięć

Wyświetl plik

@ -495,12 +495,12 @@ class Broker:
if self.authenticate(client_session): if self.authenticate(client_session):
connack = ConnackPacket.build(client_session.parent, CONNECTION_ACCEPTED) connack = ConnackPacket.build(client_session.parent, CONNECTION_ACCEPTED)
self.logger.info('%s : connection accepted' % format_client_message(session=client_session)) self.logger.info('%s : connection accepted' % format_client_message(session=client_session))
yield from self.plugins_manager.fire_event(EVENT_MQTT_PACKET_SENT, packet=connack) yield from self.plugins_manager.fire_event(EVENT_MQTT_PACKET_SENT, packet=connack, session=client_session)
yield from connack.to_stream(writer) yield from connack.to_stream(writer)
else: else:
connack = ConnackPacket.build(client_session.parent, NOT_AUTHORIZED) connack = ConnackPacket.build(client_session.parent, NOT_AUTHORIZED)
self.logger.info('%s : connection refused' % format_client_message(session=client_session)) self.logger.info('%s : connection refused' % format_client_message(session=client_session))
yield from self.plugins_manager.fire_event(EVENT_MQTT_PACKET_SENT, packet=connack) yield from self.plugins_manager.fire_event(EVENT_MQTT_PACKET_SENT, packet=connack, session=client_session)
yield from connack.to_stream(writer) yield from connack.to_stream(writer)
yield from writer.close() yield from writer.close()
return return

Wyświetl plik

@ -38,8 +38,8 @@ class ClientContext(BaseContext):
ClientContext is used as the context passed to plugins interacting with the client. ClientContext is used as the context passed to plugins interacting with the client.
It act as an adapter to client services from plugins It act as an adapter to client services from plugins
""" """
def __init__(self, loop=None): def __init__(self, client):
super().__init__(loop) super().__init__(client.loop)
class MQTTClient: class MQTTClient:
@ -89,7 +89,7 @@ class MQTTClient:
self._connection_closed_future = None self._connection_closed_future = None
# Init plugins manager # Init plugins manager
self.plugins_manager = PluginManager('hbmqtt.client', ClientContext(self._loop), self._loop) self.plugins_manager = PluginManager('hbmqtt.client', ClientContext(self))
@asyncio.coroutine @asyncio.coroutine
@ -253,10 +253,14 @@ class MQTTClient:
try : try :
connect_packet = self.build_connect_packet() connect_packet = self.build_connect_packet()
yield from connect_packet.to_stream(writer) yield from connect_packet.to_stream(writer)
yield from self.plugins_manager.fire_event(EVENT_MQTT_PACKET_SENT, packet=connect_packet) yield from self.plugins_manager.fire_event(EVENT_MQTT_PACKET_SENT,
packet=connect_packet,
session=self.session)
connack = yield from ConnackPacket.from_stream(reader) connack = yield from ConnackPacket.from_stream(reader)
yield from self.plugins_manager.fire_event(EVENT_MQTT_PACKET_RECEIVED, packet=connack) yield from self.plugins_manager.fire_event(EVENT_MQTT_PACKET_RECEIVED,
packet=connack,
session=self.session)
return_code = connack.variable_header.return_code return_code = connack.variable_header.return_code
except Exception as e: except Exception as e:
self.logger.warn("connection failed: %s" % e) self.logger.warn("connection failed: %s" % e)