我在尝试注册以使用gdbusC 中的库从 wpa_supplicant 的 p2p dbus 接口接收“InvitationReceived”信号时遇到问题。
我可以很好地创建到 P2P dbus 接口的代理连接并在其上调用方法,但是当我尝试将信号处理程序连接到代理时,我只是收到以下错误消息,指出信号无效(代码中的相关输出样本):
(进程:6764):GLib-GObject-WARNING **:/tmp/buildd/glib2.0-2.42.1/./gobject/gsignal.c:2461:信号'InvitationReceived'对于类型的实例'0x909ae0'无效'GDBusProxy'
这很奇怪,因为“InvitationReceived”是wpa_supplicant dbus api定义的信号名称。
代码示例:
static void on_wpa_ready (GObject *source_object,
GAsyncResult *res,
gpointer user_data) {
g_print("on_wpa_ready\n");
GError *error = NULL;
GVariant *output;
GDBusProxy *p2p_proxy = g_dbus_proxy_new_for_bus_finish(res, &error);
if (error) {
g_print("proxy finish error: %s\n", error->message);
g_error_free(error);
return;
}
/* call p2p_listen */
g_clear_error(&error);
output = NULL;
output = g_dbus_proxy_call_sync(p2p_proxy,
"Listen",
g_variant_new("(i)", 0), //params
G_DBUS_CALL_FLAGS_NONE,
10, //timeout_msec
NULL,
&error
);
if (error) {
g_print("Listen call error: %s\n", error->message);
g_error_free(error);
g_print("continuing...\n");
}
else {
/* it gets to this print stmt, so the method was able to be called */
g_print("Listen successful\n");
}
/* register for signal from p2p device */
/* THIS IS WHERE THE ERROR IS */
error = NULL;
g_signal_connect(p2p_proxy,
"InvitationReceived",
G_CALLBACK(on_signal), // stub func that does something simple
NULL);
}
int main (int argc, char **argv) {
GMainLoop *loop;
/* connect to wpa_supplicant p2p dbus interface */
g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
"fi.w1.wpa_supplicant1", //name,
"/fi/w1/wpa_supplicant1/Interfaces/0", //object_path,
"fi.w1.wpa_supplicant1.Interface.P2PDevice", //interface_name,
NULL,
on_wpa_ready, //callback,
NULL);
);
loop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(loop);
}
是否有一些特殊的路径需要附加到信号名称中?还是我应该使用与用于调用方法的代理不同的代理来注册信号处理程序?