diff options
-rw-r--r-- | server/prolog_session.py | 7 | ||||
-rw-r--r-- | server/user_session.py | 2 | ||||
-rw-r--r-- | wsgi_server.py | 36 |
3 files changed, 29 insertions, 16 deletions
diff --git a/server/prolog_session.py b/server/prolog_session.py index 2c2d690..768f820 100644 --- a/server/prolog_session.py +++ b/server/prolog_session.py @@ -37,8 +37,7 @@ class PrologSession(object): No properties are accessible; use getters and setters instead. Values are passed by value instead of by reference (deep copy!). """ - def __init__(self, user_session): - self._user_session = user_session # the owning session + def __init__(self): self._access_lock = threading.Lock() self._engine_id = None self._problem_id = -1 @@ -120,5 +119,7 @@ class PrologSession(object): more_messages, status, have_more = self.query(query) messages.extend(more_messages) self._problem_id = problem_id -# self._user_session.update_solution(problem_id, [], program) # TODO return messages, status, have_more + + def get_problem_id(self): + return self._problem_id diff --git a/server/user_session.py b/server/user_session.py index d8cdf1d..d5aec44 100644 --- a/server/user_session.py +++ b/server/user_session.py @@ -50,7 +50,7 @@ class UserSession(object): def get_prolog(self): with self._access_lock: if self.prolog_session is None: - self.prolog_session = prolog_session.PrologSession(self) # lazy init + self.prolog_session = prolog_session.PrologSession() # lazy init return self.prolog_session def get_problem_data(self, language, problem_group, problem): diff --git a/wsgi_server.py b/wsgi_server.py index 9b3a51e..76489db 100644 --- a/wsgi_server.py +++ b/wsgi_server.py @@ -102,9 +102,16 @@ class Login(CodeqService): return {'code': 0, 'message': 'OK', 'sid':session.get_sid()} class Activity(CodeqService): - def on_get(self, req, resp): - resp.body = '{}' - resp.status = falcon.HTTP_200 + def process(self, js, session): + trace = js.get('trace') + solution = js.get('solution') + problem_id = js.get('problem_id') + if (trace is not None) or (solution is not None): + # we have something to do + if problem_id is None: + return {'code': 1, 'message': 'Problem ID is missing'} + else: + session.update_solution(problem_id, trace, solution) class Query(CodeqService): def process(self, js, session): @@ -112,28 +119,33 @@ class Query(CodeqService): if step is None: return {'code': 1, 'message': '"step" is not set'} else: + problem_id = js.get('problem_id') + if problem_id is None: + return {'code': 4, 'message': 'Problem ID not given'} + trace = js.get('trace') prolog = session.get_prolog() + program = None if step == 'run': program = js.get('program') query = js.get('query') - problem_id = js.get('problem_id') if program is None: - return {'code': 2, 'message': 'No program specified'} + result = {'code': 2, 'message': 'No program specified'} elif query is None: - return {'code': 3, 'message': 'No query specified'} - elif problem_id is None: - return {'code': 4, 'message': 'Problem ID not given'} + result = {'code': 3, 'message': 'No query specified'} else: messages, status, have_more = prolog.run_for_user(session.get_uid(), problem_id, program, query) - return {'code': 0, 'message': 'ok', 'terminal': {'messages': messages, 'status': status, 'have_more': have_more}} + result = {'code': 0, 'message': 'ok', 'terminal': {'messages': messages, 'status': status, 'have_more': have_more}} elif step == 'next': messages, status, have_more = prolog.step() - return {'code': 0, 'message': 'ok', 'terminal': {'messages': messages, 'status': status, 'have_more': have_more}} + result = {'code': 0, 'message': 'ok', 'terminal': {'messages': messages, 'status': status, 'have_more': have_more}} elif step == 'end': messages, status, have_more = prolog.end() - return {'code': 0, 'message': 'ok', 'terminal': {'messages': messages, 'status': status, 'have_more': have_more}} + result = {'code': 0, 'message': 'ok', 'terminal': {'messages': messages, 'status': status, 'have_more': have_more}} else: - return {'code': 5, 'message': 'Unknown prolog step: {0}'.format(step)} + result = {'code': 5, 'message': 'Unknown prolog step: {0}'.format(step)} + if program or trace: + session.update_solution(problem_id, trace, program) + return result class GetProblem(CodeqService): def process(self, js, session): |