我正在研究现有 C 项目的 Python 克隆。C-Project 连接到自定义 DBus 并在那里提供一个对象来获取回调。
我尝试使用 Python 来复制它,其代码基本上可以归结为:
def vtable_method_call_cb(connection, sender, object_path, interface_name, method_name, parameters, invocation, user_data):
print('vtable_method_call_cb: %s' % method_name)
connection = Gio.DBusConnection.new_for_address_sync(
"unix:abstract=gstswitch",
Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT,
None,
None)
node_info = Gio.DBusNodeInfo.new_for_xml(introspection_xml)
vtable = Gio.DBusInterfaceVTable()
vtable.method_call(vtable_method_call_cb)
vtable.get_property(None)
vtable.set_property(None)
connection.register_object(
"/info/duzy/gst/switch/SwitchUI",
node_info.interfaces[0],
vtable,
None,
None)
vtable.method_call在调用时创建 vtable 时代码失败(get_property但当我注释一个调用时也失败)以下日志/回溯:
** (process:18062): WARNING **: Field method_call: Interface type 2 should have is_pointer set
Traceback (most recent call last):
File "moo.py", line 69, in <module>
vtable.method_call(vtable_method_call_cb)
RuntimeError: unable to get the value
我无法找到register_object()在 python 中使用的代码,所以我不确定 Gio 的这一部分是否应该可用,或者它是否不完整。