summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad Bishop <bradleyb@fuzziesquirrel.com>2017-10-27 15:33:02 -0400
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2017-11-02 22:22:31 -0400
commit2b0543482c73eff66dc9f0cf126af3a86feb48c7 (patch)
tree84dff14525e464ad56ac6acb60a4c1d20f141dd6
parentc88b0958925dabc74818de49e96defade3a1ab29 (diff)
downloadpyphosphor-2b0543482c73eff66dc9f0cf126af3a86feb48c7.tar.gz
pyphosphor-2b0543482c73eff66dc9f0cf126af3a86feb48c7.zip
dbuslib: Add decorator for property only ifaces
The built-in Introspect method in dbus-python doesn't find interfaces if the @method or @signal decorators aren't used (property-only interfaces). Use this decorator on classes derived from dbus.service.Object to help the dbus-python provided Introspect method find these interfaces. Change-Id: Icaf6fc3a32ce44a653a440ae5ca531cf67a4e1cf Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
-rw-r--r--obmc/dbuslib/bindings.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/obmc/dbuslib/bindings.py b/obmc/dbuslib/bindings.py
index 006270b..ea0da5c 100644
--- a/obmc/dbuslib/bindings.py
+++ b/obmc/dbuslib/bindings.py
@@ -123,6 +123,41 @@ class DbusProperties(dbus.service.Object):
pass
+def add_interfaces_to_class(cls, ifaces):
+ """
+ The built-in Introspect method in dbus-python doesn't find
+ interfaces if the @method or @signal decorators aren't used
+ (property-only interfaces). Use this method on a class
+ derived from dbus.service.Object to help the dbus-python provided
+ Introspect method find these interfaces.
+
+ Arguments:
+ cls -- The dbus.service.Object superclass to add interfaces to.
+ ifaces -- The property-only interfaces to add to the class.
+ """
+
+ for iface in ifaces:
+ class_table_key = '{}.{}'.format(cls.__module__, cls.__name__)
+ cls._dbus_class_table[class_table_key].setdefault(iface, {})
+
+
+def add_interfaces(ifaces):
+ """
+ A class decorator for add_interfaces_to_class.
+ """
+
+ def decorator(cls):
+ undecorated = cls.__init__
+
+ def ctor(obj, *a, **kw):
+ undecorated(obj, *a, **kw)
+ add_interfaces_to_class(cls, ifaces)
+
+ cls.__init__ = ctor
+ return cls
+ return decorator
+
+
class DbusObjectManager(dbus.service.Object):
def __init__(self, **kw):
super(DbusObjectManager, self).__init__(**kw)
OpenPOWER on IntegriCloud