Skip to content
Snippets Groups Projects
Commit bf436552 authored by jkerdreu's avatar jkerdreu
Browse files

AoiLib merge in progress

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/0.7@2725 b32b6428-25c9-4566-ad07-03861ab6144f
parent 88b897de
No related branches found
No related tags found
No related merge requests found
......@@ -204,21 +204,6 @@ class Engine(object):
func(msg)
self.process_attributesChange()
# ======== DEPRECATED ===================
def _process_rx_msg(self):
"""process incomming messages"""
cnt = 0
msg = self.receive_msg()
while msg:
for func in self.subscribers:
func(msg)
self.process_attributesChange()
# only flush some message, to limit rate
cnt = cnt + 1
if cnt > config.queue_size: break
msg = self.receive_msg()
# =========================================
def handle_request(self, msg):
"""Filter msg for devices according default xAAL API then process the
request for each targets identied in the engine
......@@ -249,7 +234,7 @@ class Engine(object):
* error returned on the xAAL bus
"""
try:
result = run_action(msg, target)
result = run_method(msg, target)
if result != None:
self.send_reply(dev=target,targets=[msg.source],action=msg.action,body=result)
except CallbackError as e:
......@@ -371,15 +356,25 @@ def filter_msg_for_devices(msg, devices):
results.append(dev)
return results
def run_method(msg,device):
method,params = search_method(msg,device)
result = None
try:
result = method(**params)
except Exception as e:
logger.error(e)
raise XAALError("Error in method:%s params:%s" % (msg.action,params))
return result
def run_action(msg, device):
def search_method(msg, device):
"""Extract & run an action (match with exposed method) from a msg
on the selected device.
Return:
- None
- result from method if method return something
Note: If action not found raise error, if wrong parameter raise error
Note: If method not found raise error, if wrong parameter error log
"""
methods = device.get_methods()
params = {}
......@@ -396,18 +391,16 @@ def run_action(msg, device):
if temp in method_params:
params.update({temp:body_params[k]})
else:
logger.info("Wrong method parameter [%s] for action %s" %(k, msg.action))
try:
result = method(**params)
except Exception as e:
logger.error(e)
raise XAALError("Error in method:%s params:%s" % (msg.action,params))
logger.warning("Wrong method parameter [%s] for action %s" %(k, msg.action))
result = (method,params)
else:
raise XAALError("Method %s not found" % msg.action)
raise XAALError("Method %s not found on device %s" % (msg.action,device))
return result
def get_args_method(method):
""" return the list on arguments for a given method """
""" return the list on arguments for a given python method """
spec = inspect.getargspec(method)
try:
spec.args.remove('self')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment