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