mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-12-23 04:01:56 +00:00
Implement triggering of FSM from ServerUplinkConnector
This commit is contained in:
parent
4842574cf3
commit
73fa65c6e8
@ -25,6 +25,7 @@ class TFWServer:
|
||||
self.application = Application(
|
||||
[(r'/ws', ZMQWebSocketProxy, {'make_response': self.make_response,
|
||||
'proxy_filter': self.proxy_filter,
|
||||
'handle_trigger': self.handle_trigger,
|
||||
'event_handler_connector': self._event_handler_connector})]
|
||||
)
|
||||
#self.controller_responder = ControllerResponder(self.fsm) TODO: add this once controller stuff is resolved
|
||||
@ -42,6 +43,10 @@ class TFWServer:
|
||||
message['FSMUpdate'] = self._fsm_updater.get_fsm_state_and_transitions()
|
||||
return message
|
||||
|
||||
def handle_trigger(self, message):
|
||||
LOG.debug('Executing handler for trigger "%s"', message.get('trigger', ''))
|
||||
self.trigger_fsm(message)
|
||||
|
||||
def trigger_fsm(self, message):
|
||||
trigger = message.get('trigger', '')
|
||||
try:
|
||||
|
@ -31,14 +31,15 @@ class ZMQWebSocketHandler(WebSocketHandler, ABC):
|
||||
def zmq_callback(self, msg_parts):
|
||||
keyhandlers = {'mirror': self.mirror}
|
||||
|
||||
key, data = deserialize_all(*msg_parts)
|
||||
LOG.debug('Received on pull socket: %s', data)
|
||||
key, message = deserialize_all(*msg_parts)
|
||||
LOG.debug('Received on pull socket: %s', message)
|
||||
self.handle_trigger(message)
|
||||
if key not in keyhandlers:
|
||||
for instance in ZMQWebSocketHandler.instances:
|
||||
instance.write_message(data)
|
||||
instance.write_message(message)
|
||||
else:
|
||||
try:
|
||||
keyhandlers[key](data['data'])
|
||||
keyhandlers[key](message['data'])
|
||||
except KeyError:
|
||||
LOG.error('Invalid mirror message format! Ignoring.')
|
||||
|
||||
@ -57,6 +58,10 @@ class ZMQWebSocketHandler(WebSocketHandler, ABC):
|
||||
def send_message(self, message: dict, key: str = None):
|
||||
self._event_handler_connector.send_message(message, key)
|
||||
|
||||
@abstractmethod
|
||||
def handle_trigger(self, message):
|
||||
raise NotImplementedError
|
||||
|
||||
# much secure, very cors, wow
|
||||
def check_origin(self, origin):
|
||||
return True
|
||||
@ -68,6 +73,7 @@ class ZMQWebSocketProxy(ZMQWebSocketHandler):
|
||||
super(ZMQWebSocketProxy, self).initialize(**kwargs)
|
||||
self._make_response = kwargs['make_response']
|
||||
self._proxy_filter = kwargs['proxy_filter']
|
||||
self._handle_trigger = kwargs['handle_trigger']
|
||||
|
||||
def on_message(self, message):
|
||||
message = json.loads(message)
|
||||
@ -76,3 +82,6 @@ class ZMQWebSocketProxy(ZMQWebSocketHandler):
|
||||
|
||||
def make_response(self, message):
|
||||
return self._make_response(message)
|
||||
|
||||
def handle_trigger(self, message):
|
||||
self._handle_trigger(message)
|
||||
|
Loading…
Reference in New Issue
Block a user