def put_async(self, attr_or_items, value=None): """"puts a value or values into an attribute or attributes and returns immediately Args: attr_or_items (Attribute or Dict): The attribute or dictionary of {attributes: values} to set value (object): For single attr, the value set Returns: a list of futures to monitor when each put completes""" if value: attr_or_items = {attr_or_items: value} result_f = [] for attr, value in attr_or_items.items(): endpoint = [attr.parent.name, attr.name, "value"] request = Post(None, self.q, endpoint, value) f = Future(self) new_id = self._save_future(f) request.set_id(new_id) self.process.q.put(request) result_f.append(f) return result_f
def execute(self, args): self.log_debug("Execute %s method called on [%s] with: %s", self._method, self._block, args) self.log_debug("Structure: %s", args.getStructureDict()) # Acquire the lock with self._lock: # We now need to create the Post message and execute it endpoint = [self._block, self._method] request = Post(None, self._server.q, endpoint, self.parse_variants(args.toDict(True))) request.set_id(self._id) self._server.process.q.put(request) # Now wait for the Post reply self.log_debug("Waiting for reply") self.wait_for_reply() self.log_debug("Reply received") response_dict = OrderedDict() if isinstance(self._response, Return): response_dict = self._response["value"] self.log_debug("Response value : %s", self._response["value"]) elif isinstance(self._response, Error): response_dict = self._response.to_dict() response_dict.pop("id") if not response_dict: pv_object = pvaccess.PvObject(OrderedDict({}), 'malcolm:core/Map:1.0') else: #pv_object = self._server.dict_to_structure(response_dict) #self.log_debug("Pv Object structure created") #self.log_debug("%s", self._server.strip_type_id(response_dict)) #pv_object.set(self._server.strip_type_id(response_dict)) pv_object = self._server.dict_to_pv_object(response_dict) self.log_debug("Pv Object value set: %s", pv_object) # Add this RPC to the purge list #self._server.register_dead_rpc(self._id) return pv_object
def post_async(self, method, params): """Asynchronously calls a function on a child block Returns a list of one future which will proved the return value on completion""" endpoint = [method.parent.name, method.name] request = Post(None, self.q, endpoint, params) f = Future(self) new_id = self._save_future(f) request.set_id(new_id) self.process.q.put(request) return [f]
def post_async(self, method, params=None): """Asynchronously calls a function on a child block Returns a list of one future which will proved the return value on completion""" assert isinstance(method, MethodMeta), \ "Expected MethodMeta, got %r" % (method,) endpoint = method.path_relative_to(self.process) request = Post(None, self.q, endpoint, params) f = Future(self) new_id = self._save_future(f) request.set_id(new_id) self.process.q.put(request) return [f]
def test_hello_with_process(self): sync_factory = SyncFactory("sched") process = Process("proc", sync_factory) b = Hello(process, dict(mri="hello"))[0] process.start() # wait until block is Ready task = Task("hello_ready_task", process) task.when_matches(b["state"], "Ready", timeout=1) q = sync_factory.create_queue() req = Post(response_queue=q, context="ClientConnection", endpoint=["hello", "greet"], parameters=dict(name="thing")) req.set_id(44) process.q.put(req) resp = q.get(timeout=1) self.assertEqual(resp.id, 44) self.assertEqual(resp.context, "ClientConnection") self.assertEqual(resp.typeid, "malcolm:core/Return:1.0") self.assertEqual(resp.value["greeting"], "Hello thing") process.stop()
def execute(self, args): self.log_debug("Execute %s method called on [%s] with: %s", self._method, self._block, args) self.log_debug("Structure: %s", args.getStructureDict()) # Acquire the lock with self._lock: try: # We now need to create the Post message and execute it endpoint = [self._block, self._method] request = Post(None, self._server.q, endpoint, self.parse_variants(args.toDict(True))) request.set_id(self._id) self._server.process.q.put(request) # Now wait for the Post reply self.log_debug("Waiting for reply") self.wait_for_reply(timeout=None) self.log_debug("Reply received %s %s", type(self._response), self._response) response_dict = OrderedDict() if isinstance(self._response, Return): response_dict = self._response["value"] self.log_debug("Response value : %s", response_dict) elif isinstance(self._response, Error): response_dict = self._response.to_dict() response_dict.pop("id") if not response_dict: pv_object = pvaccess.PvObject(OrderedDict(), 'malcolm:core/Map:1.0') else: #pv_object = self._server.dict_to_structure(response_dict) #self.log_debug("Pv Object structure created") #self.log_debug("%s", self._server.strip_type_id(response_dict)) #pv_object.set(self._server.strip_type_id(response_dict)) pv_object = self._server.dict_to_pv_object(response_dict) self.log_debug("Pv Object value set: %s", pv_object) # Add this RPC to the purge list #self._server.register_dead_rpc(self._id) return pv_object except Exception: self.log_exception("Request %s failed", self._request)