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

bye bye to old .exposed API, now you must call add_method

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/fork@1536 b32b6428-25c9-4566-ad07-03861ab6144f
parent 687e932b
No related branches found
No related tags found
No related merge requests found
......@@ -79,8 +79,8 @@ class Device(object):
self.next_alive = 0
self.__attributes = []
self.__methods = find_dev_methods(self)
self.methods = {'getAttributes' : self._get_attributes,
'getDescription': self._get_description }
self.engine = engine
@property
......@@ -120,17 +120,25 @@ class Device(object):
self.__attributes.append(attr)
attr.device = self
def _get_attributes(self):
return {attr.name: attr for attr in self.__attributes}
def get_attribute(self,name):
for attr in self.__attributes:
if attr.name == name:
return attr
return None
@property
def attributes(self):
return self.__attributes
@attributes.setter
def attributes(self,value):
self.__attributes = value
def attributes(self,values):
self.__attributes = values
def add_method(self,name,func):
self.methods.update({name:func})
def get_methods(self):
return self.methods
def update_alive(self):
""" update the alive timimg"""
......@@ -140,7 +148,6 @@ class Device(object):
""" return Alive timeout used for isAlive msg"""
return 2 * self.alive_period
#####################################################
# Usefull methods
#####################################################
......@@ -152,21 +159,11 @@ class Device(object):
print("Version: \t%s" % self.version)
print("Info: \t%s" % self.info)
#####################################################
# Methods
#####################################################
# Return bound method
def get_methods(self):
"""
Return the available bound methods (according to the definition of a
xAAL device method) for the device
"""
return self.__methods
#####################################################
# Exposed methods
# default public methods
#####################################################
def getDescription(self):
def _get_description(self):
result = {}
if self.vendor_id: result['vendorID'] = self.vendor_id
if self.product_id: result['productID'] = self.product_id
......@@ -178,9 +175,8 @@ class Device(object):
result['unsupportedNotifications'] = self.unsupported_notifications
result['unsupportedAttributes'] = self.unsupported_attributes
return result
getDescription.exposed = True
def getAttributes(self, attributes=None):
def _get_attributes(self, attributes=None):
"""
attributes:
- None = body empty and means request all attributes
......@@ -193,7 +189,7 @@ class Device(object):
with specific error code and with value = suspicious/stale/cached
"""
result = {}
dev_attr = self._get_attributes()
dev_attr = {attr.name: attr for attr in self.__attributes}
if attributes:
"""Process attributes filter"""
for attr in attributes:
......@@ -206,20 +202,3 @@ class Device(object):
for attr in dev_attr.values():
result.update({attr.name: attr.value})
return result
getAttributes.exposed = True
def find_dev_methods(dev):
""" loop throught the object to find and .exposed
functions attributes"""
method_list = [e for e in dir(dev) if callable(getattr(dev, e))]
result = {} # []
klass = dev.__class__
for m in method_list:
func = getattr(klass, m)
if hasattr(func, 'exposed'):
if getattr(func, 'exposed'):
method = getattr(dev, m)
result[method.__name__] = method
return result
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment