问题描述
我在几个地方搜索了这个问题的答案,但是我找不到一致的解决方案,其中有些太旧而且不清楚。
I searched for an answer to this question in several places, but I could not find a consistent solution, and some are too old and unclear.
我有一个classe,其中dbus的接口路径是在运行时生成的,因此我需要使用正确的接口导出方法,例如:
I have a classe where the interface path for dbus is generated in runtime, so I need to export methods with the properly interface, for example:
我的服务的一个实例使用interface启动dbus br.example.MyInterface.Number1
,第二个服务实例以 br.example.MyInterface.Number2
启动dbus。 ,因此每种方法的修饰符将为:
One instance of my service start dbus with interface br.example.MyInterface.Number1
, and a second instance of service start dbus with br.example.MyInterface.Number2
, so the decorator for each method will be:
br.example.MyInterface.Number1
;和
br.example.MyInterface.Number2
无法使用静态装饰器(例如 @ dbus.service.method('com.example.MyInterface.Number1')
,因为它们是不同的。
Cannot make this work with static decorator like @dbus.service.method('com.example.MyInterface.Number1')
, because they are distincts.
如何我可以在运行时使用python将方法导出到dbus吗?
How can I export methods to dbus in runtime using python?
推荐答案
@dbus.service.method('com.example.MyInterface.Number%d' % (instancenum,))
这篇关于如何在没有静态装饰器的情况下使用python动态将方法导出到dbus?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!