Create initial version of controller

This commit is contained in:
Bálint Bokros 2018-02-08 16:26:28 +01:00
parent 95e1f907ee
commit c015727153
5 changed files with 43 additions and 0 deletions

View File

19
src/controller/app.py Normal file
View File

@ -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()

View File

@ -0,0 +1,2 @@
from .solution_check_handler import SolutionCheckHandler
from .test_handler import TestHandler

View File

@ -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

View File

@ -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