From c015727153d4bb78c2fa0aec6ec857b782771193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Bokros?= Date: Thu, 8 Feb 2018 16:26:28 +0100 Subject: [PATCH] Create initial version of controller --- src/controller/__init__.py | 0 src/controller/app.py | 19 +++++++++++++++++++ src/controller/handlers/__init__.py | 2 ++ .../handlers/solution_check_handler.py | 11 +++++++++++ src/controller/handlers/test_handler.py | 11 +++++++++++ 5 files changed, 43 insertions(+) create mode 100644 src/controller/__init__.py create mode 100644 src/controller/app.py create mode 100644 src/controller/handlers/__init__.py create mode 100644 src/controller/handlers/solution_check_handler.py create mode 100644 src/controller/handlers/test_handler.py diff --git a/src/controller/__init__.py b/src/controller/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/controller/app.py b/src/controller/app.py new file mode 100644 index 0000000..b3af301 --- /dev/null +++ b/src/controller/app.py @@ -0,0 +1,19 @@ +from tornado.ioloop import IOLoop +from tornado.web import Application + +from tfw.config import CRP_LISTENER_PORT, AVATAO_SECRET +from .handlers import SolutionCheckHandler, TestHandler +from tfw.networking.solvable_connector import SolvableConnector + + +if __name__ == '__main__': + solvable_connector = SolvableConnector() + routes = [ + (r'/{secret}/'.format(secret=AVATAO_SECRET), SolutionCheckHandler, {'solvable_connector': solvable_connector}), + (r'/{secret}/test'.format(secret=AVATAO_SECRET), TestHandler, {'solvable_connector': solvable_connector}) + ] + app = Application( + routes + ) + app.listen(CRP_LISTENER_PORT) + IOLoop.instance().start() diff --git a/src/controller/handlers/__init__.py b/src/controller/handlers/__init__.py new file mode 100644 index 0000000..ac7e0ba --- /dev/null +++ b/src/controller/handlers/__init__.py @@ -0,0 +1,2 @@ +from .solution_check_handler import SolutionCheckHandler +from .test_handler import TestHandler diff --git a/src/controller/handlers/solution_check_handler.py b/src/controller/handlers/solution_check_handler.py new file mode 100644 index 0000000..85bfe7c --- /dev/null +++ b/src/controller/handlers/solution_check_handler.py @@ -0,0 +1,11 @@ +from tornado.web import RequestHandler + + +class SolutionCheckHandler(RequestHandler): + def initialize(self, solvable_connector): + self.solvable_connector = solvable_connector + + def get(self): + self.solvable_connector.send('solution_check', {}) + resp_key, resp_data = self.solvable_connector.recv() + return resp_data diff --git a/src/controller/handlers/test_handler.py b/src/controller/handlers/test_handler.py new file mode 100644 index 0000000..0514e08 --- /dev/null +++ b/src/controller/handlers/test_handler.py @@ -0,0 +1,11 @@ +from tornado.web import RequestHandler + + +class TestHandler(RequestHandler): + def initialize(self, solvable_connector): + self.solvable_connector = solvable_connector + + def get(self): + self.solvable_connector.send('test', {}) + resp_key, resp_data = self.solvable_connector.recv() + return resp_data