def Tick(self, request, context): response = remote_pb2.TickResponse() self.logger.debug('Ticked with session ID "%s"', request.session_id) with server_util.ResponseContext(response, request): with self.lock: self._tick_implementation(request, response) return response
def TeardownSession(self, request, context): response = remote_pb2.TeardownSessionResponse() self.logger.debug('Tearing down session "%s"', request.session_id) with server_util.ResponseContext(response, request): with self.lock: self._teardown_session_implementation(request, response) return response
def EstablishSession(self, request, context): response = remote_pb2.EstablishSessionResponse() self.logger.debug('Establishing session with %i leases and %i inputs', len(request.leases), len(request.inputs)) with server_util.ResponseContext(response, request): with self.lock: self._establish_session_implementation(request, response) return response
def Stop(self, request, context): # Called when the client has decided it doesn't need to continue checking on this # service. For example, if this service is running as part of a Mission, some other part # of the Mission may have been activated. response = remote_pb2.StopResponse() self.logger.debug('Stopping session "%s"', request.session_id) with server_util.ResponseContext(response, request): with self.lock: self._stop_implementation(request, response) return response
def GetState(self, request, context): response = mission_pb2.GetStateResponse() with server_util.ResponseContext(response, request): q = response.state.questions.add() q.id = self.question_id q.source = self.source q.text = 'Answer me these questions three' i = 0 for t in ('What is your name', 'What is your quest', 'What is the air-speed velocity of an unladen swallow'): o = q.options.add() o.answer_code = i i += 1 self.active_questions[q.id] = q self.question_id += 1 return response
def Tick(self, request, context): """Logs text, then provides a valid response.""" response = remote_pb2.TickResponse() # This utility context manager will fill out some fields in the message headers. with server_util.ResponseContext(response, request): # Default to saying hello to "world". name = 'World' # See if a different name was provided to us in the request's inputs. # This "user-string" input is provided by the Autowalk missions. # To provide other inputs, see the RemoteGrpc message. for keyvalue in request.inputs: if keyvalue.key == 'user-string': name = util.get_value_from_constant_value_message( keyvalue.value.constant) self.logger.info('Hello %s!', name) response.status = remote_pb2.TickResponse.STATUS_SUCCESS return response
def AnswerQuestion(self, request, context): """Mimic AnswerQuestion in actual servicer.""" response = mission_pb2.AnswerQuestionResponse() with server_util.ResponseContext(response, request): if request.question_id in self.answered_questions: response.status = mission_pb2.AnswerQuestionResponse.STATUS_ALREADY_ANSWERED return response if request.question_id not in self.active_questions: response.status = mission_pb2.AnswerQuestionResponse.STATUS_INVALID_QUESTION_ID return response question = self.active_questions[request.question_id] if request.code not in [option.answer_code for option in question.options]: response.status = mission_pb2.AnswerQuestionResponse.STATUS_INVALID_CODE return response self.answered_questions[request.question_id] = request del self.active_questions[request.question_id] response.status = mission_pb2.AnswerQuestionResponse.STATUS_OK return response
def TeardownSession(self, request, context): response = remote_pb2.TeardownSessionResponse() with server_util.ResponseContext(response, request): self.logger.info('TeardownSession unimplemented!') response.status = remote_pb2.TeardownSessionResponse.STATUS_OK return response
def Stop(self, request, context): response = remote_pb2.StopResponse() with server_util.ResponseContext(response, request): self.logger.info('Stop unimplemented!') response.status = remote_pb2.StopResponse.STATUS_OK return response
def PauseMission(self, request, context): response = mission_pb2.PauseMissionResponse() with server_util.ResponseContext(response, request): response.status = self.pause_mission_response_status return response
def LoadMission(self, request, context): response = mission_pb2.LoadMissionResponse() with server_util.ResponseContext(response, request): response.status = self.load_mission_response_status return response