mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 23:11:33 +00:00
Simplify ServerUplinkConnector mirror logic, add broadcast support
This commit is contained in:
parent
9f6ac6d27e
commit
381cd2b11e
@ -40,26 +40,40 @@ class ServerUplinkConnector(ZMQConnectorBase):
|
|||||||
|
|
||||||
def send_to_eventhandler(self, message):
|
def send_to_eventhandler(self, message):
|
||||||
"""
|
"""
|
||||||
Send a message to an event handler.
|
Send a message to an event handler through the TFW server.
|
||||||
|
|
||||||
This envelopes the desired message in the 'data' field of the message to
|
This envelopes the desired message in the 'data' field of the message to
|
||||||
TFWServer, which will mirror it to event handlers.
|
TFWServer, which will mirror it to event handlers.
|
||||||
|
|
||||||
:param message: JSON message you want to send
|
:param message: JSON message you want to send
|
||||||
:param message['key']: key of event handler you want to address
|
|
||||||
"""
|
"""
|
||||||
nested_message = {'key': message['key'], 'data': message.pop('data')}
|
self.send({
|
||||||
message['key'] = 'mirror'
|
'key': 'mirror',
|
||||||
message['data'] = nested_message
|
'data': message
|
||||||
self.send(message)
|
})
|
||||||
|
|
||||||
def send(self, message):
|
def send(self, message):
|
||||||
"""
|
"""
|
||||||
Send a message to the TFW server
|
Send a message to the frontend through the TFW server.
|
||||||
|
|
||||||
:param message: JSON message you want to send
|
:param message: JSON message you want to send
|
||||||
"""
|
"""
|
||||||
self._zmq_push_socket.send_multipart(serialize_tfw_msg(message))
|
self._zmq_push_socket.send_multipart(serialize_tfw_msg(message))
|
||||||
|
|
||||||
|
def broadcast(self, message):
|
||||||
|
"""
|
||||||
|
Broadast a message through the TFW server.
|
||||||
|
|
||||||
|
This envelopes the desired message in the 'data' field of the message to
|
||||||
|
TFWServer, which will broadast it.
|
||||||
|
|
||||||
|
:param message: JSON message you want to send
|
||||||
|
"""
|
||||||
|
self.send({
|
||||||
|
'key': 'broadcast',
|
||||||
|
'data': message
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
class ServerConnector(ServerUplinkConnector, ServerDownlinkConnector):
|
class ServerConnector(ServerUplinkConnector, ServerDownlinkConnector):
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user