GDBusProxy - 获取就绪回调中的输入参数
问题描述:
我正在使用gdbus-codegen
来生成代码。但基本上,我想获得传递给内部参数GAsyncReadyCallback callback
。GDBusProxy - 获取就绪回调中的输入参数
我不想使用gpointer user_data
,因为我需要它为this
指针。
我该怎么做?
https://developer.gnome.org/gio/stable/GDBusProxy.html#g-dbus-proxy-call
答
你可以使用
struct CallbackArguments {
YourClass *that;
GVariant *call_params;
}
,并通过CallbackArguments
为user_data
。
你是否建议动态地为CallbackArguments分配内存并在回调中销毁它?保证回调是否被调用? –
标准方法是动态分配这个闭包,是的;并在回调中销毁它。只要[GMainContext'](https://developer.gnome.org/glib/stable/glib-The-Main-Event-Loop.html)迭代到足够的范围内,回调函数就保证只调用一次操作完成。 这是所有使用['GAsyncResult'](https://developer.gnome.org/gio/stable/GAsyncResult.html)的异步操作都可以处理的习惯用法。 –