mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 19:41:32 +00:00
Refactor solvable responses
This commit is contained in:
parent
e04cc08dd6
commit
6f785b3ca7
@ -12,21 +12,29 @@ class TFWServer:
|
|||||||
[(r'/ws', FSMManagingSocketHandler, {'fsm': self.fsm})]
|
[(r'/ws', FSMManagingSocketHandler, {'fsm': self.fsm})]
|
||||||
)
|
)
|
||||||
self.controller_connector = ControllerConnector()
|
self.controller_connector = ControllerConnector()
|
||||||
self.controller_connector.register_callback(self.zmq_callback)
|
self.controller_connector.register_callback(self.handle_controller_request)
|
||||||
|
self.controller_request_handlers = {
|
||||||
|
'solution_check': self.handle_solution_check_request,
|
||||||
|
'test': self.handle_test_request
|
||||||
|
}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fsm(self):
|
def fsm(self):
|
||||||
return self._fsm
|
return self._fsm
|
||||||
|
|
||||||
def zmq_callback(self, stream, msg_parts):
|
def handle_controller_request(self, stream, msg_parts):
|
||||||
key, data = deserialize_all(*msg_parts)
|
key, data = deserialize_all(*msg_parts)
|
||||||
if key == 'test':
|
response = self.controller_request_handlers[key](data)
|
||||||
stream.send_multipart(serialize_all(key, 'OK'))
|
stream.send_multipart(serialize_all(key, response))
|
||||||
if key == 'solution_check':
|
|
||||||
stream.send_multipart(serialize_all(key, {
|
def handle_test_request(self, data):
|
||||||
'solved': self.fsm.is_solved(),
|
return 'OK'
|
||||||
'message': 'solved' if self.fsm.is_solved() else 'not solved'
|
|
||||||
}))
|
def handle_solution_check_request(self, data):
|
||||||
|
return {
|
||||||
|
'solved': self.fsm.is_solved(),
|
||||||
|
'message': 'solved' if self.fsm.is_solved() else 'not solved'
|
||||||
|
}
|
||||||
|
|
||||||
def listen(self, port):
|
def listen(self, port):
|
||||||
self.application.listen(port)
|
self.application.listen(port)
|
||||||
|
Loading…
Reference in New Issue
Block a user