Python Dbus:如何导出接口属性
在所有PythonDBUS文档中都有关于如何导出对象、接口、信号的信息,但没有关于如何导出接口属性的信息Python Dbus:如何导出接口属性,python,dbus,Python,Dbus,在所有PythonDBUS文档中都有关于如何导出对象、接口、信号的信息,但没有关于如何导出接口属性的信息 有什么办法吗 在Python中实现D-Bus属性绝对是可能的!D-Bus属性只是特定接口上的方法,即org.freedesktop.DBus.properties。定义了接口;您可以在类上实现它,就像实现任何其他D-Bus接口一样: # Untested, just off the top of my head import dbus MY_INTERFACE = 'com.exampl
有什么办法吗 在Python中实现D-Bus属性绝对是可能的!D-Bus属性只是特定接口上的方法,即
org.freedesktop.DBus.properties
。定义了接口;您可以在类上实现它,就像实现任何其他D-Bus接口一样:
# Untested, just off the top of my head
import dbus
MY_INTERFACE = 'com.example.Foo'
class Foo(dbus.service.object):
# …
@dbus.service.method(interface=dbus.PROPERTIES_IFACE,
in_signature='ss', out_signature='v')
def Get(self, interface_name, property_name):
return self.GetAll(interface_name)[property_name]
@dbus.service.method(interface=dbus.PROPERTIES_IFACE,
in_signature='s', out_signature='a{sv}')
def GetAll(self, interface_name):
if interface_name == MY_INTERFACE:
return { 'Blah': self.blah,
# …
}
else:
raise dbus.exceptions.DBusException(
'com.example.UnknownInterface',
'The Foo object does not implement the %s interface'
% interface_name)
@dbus.service.method(interface=dbus.PROPERTIES_IFACE,
in_signature='ssv'):
def Set(self, interface_name, property_name, new_value):
# validate the property name and value, update internal state…
self.PropertiesChanged(interface_name,
{ property_name: new_value }, [])
@dbus.service.signal(interface=dbus.PROPERTIES_IFACE,
signature='sa{sv}as')
def PropertiesChanged(self, interface_name, changed_properties,
invalidated_properties):
pass
dbus-python应该使实现属性变得更容易,但目前它最多只能进行少量维护
如果有人喜欢潜入并帮助修理这样的东西,他们将是最受欢迎的。即使在文档中添加此样板文件的扩展版本也是一个开始,因为这是一个非常常见的问题。如果您感兴趣,可以将修补程序发送到或附加到Bug。我认为此示例不起作用,因为: ''' 可以通过调用org.freedesktop.DBus.Introspectable.Introspect来确定可用属性及其是否可写,请参阅“org.freedesktop.DBus.Introspectable”部分。 ''' 在自省数据中,属性缺失:
我使用dbus-python-1.1.1您所说的“导出接口属性”到底是什么意思?我的意思是创建一个dbus属性。但是最近我发现python是不可能的。我贡献了我的代码来添加属性。实现内省是可选的,主要是为了交互式调试的好处:使用API的应用程序应该已经知道它期望的API。因此,未包含在内省数据中的属性并不理想,但不应成为主要问题。(您可能可以手动扩展内省接口的实现,以包括属性。)