mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2025-06-28 18:45:11 +00:00
Add a huge bunch of docstrings
This commit is contained in:
@ -24,18 +24,30 @@ class ServerDownlinkConnector(ZMQConnectorBase):
|
||||
|
||||
|
||||
class ServerUplinkConnector(ZMQConnectorBase):
|
||||
"""
|
||||
Class capable of sending messages to the TFW server and event handlers.
|
||||
"""
|
||||
def __init__(self, zmq_context=None):
|
||||
super(ServerUplinkConnector, self).__init__(zmq_context)
|
||||
self._zmq_push_socket = self._zmq_context.socket(zmq.PUSH)
|
||||
self._zmq_push_socket.connect('tcp://localhost:{}'.format(TFWENV.RECEIVER_PORT))
|
||||
|
||||
def send_to_eventhandler(self, message):
|
||||
"""
|
||||
Send a message to an event handler.
|
||||
: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')}
|
||||
message['key'] = 'mirror'
|
||||
message['data'] = nested_message
|
||||
self.send(message)
|
||||
|
||||
def send(self, message):
|
||||
"""
|
||||
Send a message to the TFW server
|
||||
:param message: JSON message you want to send
|
||||
"""
|
||||
self._zmq_push_socket.send_multipart(serialize_tfw_msg(message))
|
||||
|
||||
|
||||
|
@ -7,11 +7,20 @@ from tfw.networking.event_handlers import ServerUplinkConnector
|
||||
|
||||
|
||||
class MessageSender:
|
||||
"""
|
||||
Provides a mechanism to send messages to our frontend messaging component which
|
||||
displays messages with the key "message".
|
||||
"""
|
||||
def __init__(self, custom_key: str = None):
|
||||
self.server_connector = ServerUplinkConnector()
|
||||
self.key = custom_key or 'message'
|
||||
|
||||
def send(self, originator, message):
|
||||
"""
|
||||
Sends a message to the key specified in __init__.
|
||||
:param originator: name of sender to be displayed on the frontend
|
||||
:param message: message to send
|
||||
"""
|
||||
data = {
|
||||
'originator': originator,
|
||||
'timestamp': datetime.now().isoformat(),
|
||||
|
@ -15,7 +15,15 @@ LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TFWServer:
|
||||
"""
|
||||
This class handles the proxying of messages between the frontend and event handers.
|
||||
It proxies messages from the "/ws" route to all event handlers subscribed to a ZMQ
|
||||
SUB socket. It also manages an FSM you can define as a constructor argument.
|
||||
"""
|
||||
def __init__(self, fsm_type):
|
||||
"""
|
||||
:param fsm_type: the type of FSM you want TFW to use
|
||||
"""
|
||||
self._fsm = fsm_type()
|
||||
self._fsm_updater = FSMUpdater(self._fsm)
|
||||
self._fsm_manager = FSMManager(self._fsm)
|
||||
|
Reference in New Issue
Block a user