def __call__(self, input_marshal_id): input_m = Marshal(id=input_marshal_id, should_release=False) input_values = [] for input_ty in self.input_types: input_values += input_m.read_obj(input_ty), try: output = self.f(*input_values) except: traceback.print_exc() raise if len(self.output_types) == 0: # void rpc return 0 # mark as a NULL reply output_m = Marshal(should_release=False) # C++ code will release the marshal object if len(self.output_types) == 1: # single return value output_m.write_obj(output, self.output_types[0]) else: # multiple return values for i in range(len(self.output_types)): output_m.write_obj(output[i], self.output_types[i]) return output_m.id
def __call__(self, input_marshal_id): input_m = Marshal(id=input_marshal_id, should_release=False) input_values = [] for input_ty in self.input_types: input_values += input_m.read_obj(input_ty), try: output = self.f(*input_values) except: traceback.print_exc() raise if len(self.output_types) == 0: # void rpc return 0 # mark as a NULL reply output_m = Marshal( should_release=False) # C++ code will release the marshal object if len(self.output_types) == 1: # single return value output_m.write_obj(output, self.output_types[0]) else: # multiple return values for i in range(len(self.output_types)): output_m.write_obj(output[i], self.output_types[i]) return output_m.id
def sync_call(self, rpc_id, req_values, req_types, rep_types): req_m = Marshal() for i in range(len(req_values)): req_m.write_obj(req_values[i], req_types[i]) error_code, rep_marshal_id = _pyrpc.client_sync_call(self.id, rpc_id, req_m.id) results = [] if rep_marshal_id != 0 and error_code == 0: rep_m = Marshal(id=rep_marshal_id) for ty in rep_types: results += rep_m.read_obj(ty), return error_code, results
def sync_call(self, rpc_id, req_values, req_types, rep_types): req_m = Marshal() for i in range(len(req_values)): req_m.write_obj(req_values[i], req_types[i]) error_code, rep_marshal_id = _pyrpc.client_sync_call( self.id, rpc_id, req_m.id) results = [] if rep_marshal_id != 0 and error_code == 0: rep_m = Marshal(id=rep_marshal_id) for ty in rep_types: results += rep_m.read_obj(ty), return error_code, results
def wait(self, timeout_sec=None): if self.wait_ok: return if timeout_sec is None: self.err_code, rep_marshal_id = _pyrpc.future_wait(self.id) else: timeout_msec = int(timeout_sec * 1000) self.err_code, rep_marshal_id = _pyrpc.future_timedwait(self.id, timeout_msec) results = [] if rep_marshal_id != 0 and self.err_code == 0: rep_m = Marshal(id=rep_marshal_id) for ty in self.rep_types: results += rep_m.read_obj(ty), self.wait_ok = True if len(results) == 0: self.rep = None elif len(results) == 1: self.rep = results[0] else: self.rep = results return self.err_code
def wait(self, timeout_sec=None): if self.wait_ok: return if timeout_sec is None: self.err_code, rep_marshal_id = _pyrpc.future_wait(self.id) else: timeout_msec = int(timeout_sec * 1000) self.err_code, rep_marshal_id = _pyrpc.future_timedwait( self.id, timeout_msec) results = [] if rep_marshal_id != 0 and self.err_code == 0: rep_m = Marshal(id=rep_marshal_id) for ty in self.rep_types: results += rep_m.read_obj(ty), self.wait_ok = True if len(results) == 0: self.rep = None elif len(results) == 1: self.rep = results[0] else: self.rep = results return self.err_code