Callback input validator function on property set
This will provide a way for subclasses to register a callback handler which will
then be called into whenever a property update is attempted. The callback will
validate the user inputs and then either throw exception or return success. On
an exception, its rethrown.
Change-Id: I4c1920adb7e4873f2c530752313dd3ebc2230dc2
Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
diff --git a/obmc/dbuslib/bindings.py b/obmc/dbuslib/bindings.py
index 203b56f..d3fdbaf 100644
--- a/obmc/dbuslib/bindings.py
+++ b/obmc/dbuslib/bindings.py
@@ -31,6 +31,7 @@
class DbusProperties(dbus.service.Object):
def __init__(self, **kw):
+ self.validator = kw.pop('validator')
super(DbusProperties, self).__init__(**kw)
self.properties = {}
self._export = False
@@ -76,6 +77,10 @@
def Set(self, interface_name, property_name, new_value):
if (interface_name not in self.properties):
self.properties[interface_name] = {}
+
+ if self.validator:
+ self.validator(interface_name, property_name, new_value)
+
try:
old_value = self.properties[interface_name][property_name]
if (old_value != new_value):