From 36a86b04540fa83335f612abd0842c0a17cd7761 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Fri, 29 Jun 2018 11:58:05 +0200 Subject: [PATCH] Hide ZMQ serialization magic from EHConnector clients --- lib/tfw/networking/server/event_handler_connector.py | 3 ++- lib/tfw/networking/server/zmq_websocket_handler.py | 11 +++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/tfw/networking/server/event_handler_connector.py b/lib/tfw/networking/server/event_handler_connector.py index 542bac1..c4c6338 100644 --- a/lib/tfw/networking/server/event_handler_connector.py +++ b/lib/tfw/networking/server/event_handler_connector.py @@ -4,7 +4,7 @@ import zmq from zmq.eventloop.zmqstream import ZMQStream -from tfw.networking import ZMQConnectorBase, serialize_tfw_msg +from tfw.networking import ZMQConnectorBase, serialize_tfw_msg, with_deserialize_tfw_msg from tfw.config import TFWENV from tfw.config.logs import logging @@ -32,6 +32,7 @@ class EventHandlerUplinkConnector(ZMQConnectorBase): class EventHandlerConnector(EventHandlerDownlinkConnector, EventHandlerUplinkConnector): def register_callback(self, callback): + callback = with_deserialize_tfw_msg(callback) self._zmq_pull_stream.on_recv(callback) def send_message(self, message: dict): diff --git a/lib/tfw/networking/server/zmq_websocket_handler.py b/lib/tfw/networking/server/zmq_websocket_handler.py index 9456ca4..0bf82fb 100644 --- a/lib/tfw/networking/server/zmq_websocket_handler.py +++ b/lib/tfw/networking/server/zmq_websocket_handler.py @@ -5,7 +5,7 @@ import json from tornado.websocket import WebSocketHandler -from tfw.networking import deserialize_tfw_msg, validate_message +from tfw.networking import validate_message from tfw.mixins import CallbackMixin from tfw.config.logs import logging @@ -87,19 +87,18 @@ class ZMQWebSocketProxy(WebSocketHandler): def open(self, *args, **kwargs): LOG.debug('WebSocket connection initiated') - self._event_handler_connector.register_callback(self.zmq_callback) + self._event_handler_connector.register_callback(self.eventhander_callback) - def zmq_callback(self, msg_parts): + def eventhander_callback(self, message): """ - Invoked on ZMQ message. + Invoked on ZMQ messages from event handlers. """ - message = deserialize_tfw_msg(*msg_parts) LOG.debug('Received on pull socket: %s', message) self.proxy_eventhandler_to_websocket(message) def on_message(self, message): """ - Invoked on WS message. + Invoked on WS messages from frontend. """ message = json.loads(message) LOG.debug('Received on WebSocket: %s', message)