mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 18:41:32 +00:00
Work out multiple inheritance in event_handler_connector.py
This commit is contained in:
parent
6e6d775a05
commit
9760db7c5c
@ -12,7 +12,7 @@ ioloop.install()
|
|||||||
|
|
||||||
class EventHandlerDownlinkConnector(ZMQConnectorBase):
|
class EventHandlerDownlinkConnector(ZMQConnectorBase):
|
||||||
def __init__(self, zmq_context=None):
|
def __init__(self, zmq_context=None):
|
||||||
super().__init__(zmq_context)
|
super(EventHandlerDownlinkConnector, self).__init__(zmq_context)
|
||||||
self._zmq_pull_socket = self._zmq_context.socket(zmq.PULL)
|
self._zmq_pull_socket = self._zmq_context.socket(zmq.PULL)
|
||||||
self._zmq_pull_stream = ZMQStream(self._zmq_pull_socket)
|
self._zmq_pull_stream = ZMQStream(self._zmq_pull_socket)
|
||||||
address = 'tcp://*:{}'.format(RECEIVER_PORT)
|
address = 'tcp://*:{}'.format(RECEIVER_PORT)
|
||||||
@ -22,7 +22,7 @@ class EventHandlerDownlinkConnector(ZMQConnectorBase):
|
|||||||
|
|
||||||
class EventHandlerUplinkConnector(ZMQConnectorBase):
|
class EventHandlerUplinkConnector(ZMQConnectorBase):
|
||||||
def __init__(self, zmq_context=None):
|
def __init__(self, zmq_context=None):
|
||||||
super().__init__(zmq_context)
|
super(EventHandlerUplinkConnector, self).__init__(zmq_context)
|
||||||
self._zmq_pub_socket = self._zmq_context.socket(zmq.PUB)
|
self._zmq_pub_socket = self._zmq_context.socket(zmq.PUB)
|
||||||
address = 'tcp://*:{}'.format(PUBLISHER_PORT)
|
address = 'tcp://*:{}'.format(PUBLISHER_PORT)
|
||||||
self._zmq_pub_socket.bind(address)
|
self._zmq_pub_socket.bind(address)
|
||||||
@ -31,19 +31,16 @@ class EventHandlerUplinkConnector(ZMQConnectorBase):
|
|||||||
|
|
||||||
class EventHandlerConnector(EventHandlerDownlinkConnector, EventHandlerUplinkConnector):
|
class EventHandlerConnector(EventHandlerDownlinkConnector, EventHandlerUplinkConnector):
|
||||||
def __init__(self, zmq_context=None):
|
def __init__(self, zmq_context=None):
|
||||||
self.downlink = EventHandlerDownlinkConnector(zmq_context)
|
super(EventHandlerConnector, self).__init__(zmq_context)
|
||||||
self.uplink = EventHandlerUplinkConnector(zmq_context)
|
|
||||||
#EventHandlerDownlinkConnector.__init__(self, zmq_context) # TODO: solve this with multiple inheritance
|
|
||||||
#EventHandlerUplinkConnector.__init__(self, zmq_context)
|
|
||||||
|
|
||||||
def register_callback(self, callback):
|
def register_callback(self, callback):
|
||||||
self.downlink._zmq_pull_stream.on_recv(callback)
|
self._zmq_pull_stream.on_recv(callback)
|
||||||
|
|
||||||
def send_message(self, message: str, anchor: str = None):
|
def send_message(self, message: str, anchor: str = None):
|
||||||
if not anchor:
|
if not anchor:
|
||||||
anchor = parse_anchor_from_message(message)
|
anchor = parse_anchor_from_message(message)
|
||||||
encoded_message = [part.encode('utf-8') for part in (anchor, message)]
|
encoded_message = [part.encode('utf-8') for part in (anchor, message)]
|
||||||
self.uplink._zmq_pub_socket.send_multipart(encoded_message)
|
self._zmq_pub_socket.send_multipart(encoded_message)
|
||||||
|
|
||||||
|
|
||||||
ehc = EventHandlerConnector()
|
ehc = EventHandlerConnector()
|
||||||
|
Loading…
Reference in New Issue
Block a user