mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-23 00:31:31 +00:00
Hide ZMQ serialization magic from EHConnector clients
This commit is contained in:
parent
934f8ec74c
commit
36a86b0454
@ -4,7 +4,7 @@
|
|||||||
import zmq
|
import zmq
|
||||||
from zmq.eventloop.zmqstream import ZMQStream
|
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 import TFWENV
|
||||||
from tfw.config.logs import logging
|
from tfw.config.logs import logging
|
||||||
|
|
||||||
@ -32,6 +32,7 @@ class EventHandlerUplinkConnector(ZMQConnectorBase):
|
|||||||
|
|
||||||
class EventHandlerConnector(EventHandlerDownlinkConnector, EventHandlerUplinkConnector):
|
class EventHandlerConnector(EventHandlerDownlinkConnector, EventHandlerUplinkConnector):
|
||||||
def register_callback(self, callback):
|
def register_callback(self, callback):
|
||||||
|
callback = with_deserialize_tfw_msg(callback)
|
||||||
self._zmq_pull_stream.on_recv(callback)
|
self._zmq_pull_stream.on_recv(callback)
|
||||||
|
|
||||||
def send_message(self, message: dict):
|
def send_message(self, message: dict):
|
||||||
|
@ -5,7 +5,7 @@ import json
|
|||||||
|
|
||||||
from tornado.websocket import WebSocketHandler
|
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.mixins import CallbackMixin
|
||||||
from tfw.config.logs import logging
|
from tfw.config.logs import logging
|
||||||
|
|
||||||
@ -87,19 +87,18 @@ class ZMQWebSocketProxy(WebSocketHandler):
|
|||||||
|
|
||||||
def open(self, *args, **kwargs):
|
def open(self, *args, **kwargs):
|
||||||
LOG.debug('WebSocket connection initiated')
|
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)
|
LOG.debug('Received on pull socket: %s', message)
|
||||||
self.proxy_eventhandler_to_websocket(message)
|
self.proxy_eventhandler_to_websocket(message)
|
||||||
|
|
||||||
def on_message(self, message):
|
def on_message(self, message):
|
||||||
"""
|
"""
|
||||||
Invoked on WS message.
|
Invoked on WS messages from frontend.
|
||||||
"""
|
"""
|
||||||
message = json.loads(message)
|
message = json.loads(message)
|
||||||
LOG.debug('Received on WebSocket: %s', message)
|
LOG.debug('Received on WebSocket: %s', message)
|
||||||
|
Loading…
Reference in New Issue
Block a user