首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >向ConnMan注册RequestInput函数的正确方法是什么?

向ConnMan注册RequestInput函数的正确方法是什么?
EN

Stack Overflow用户
提问于 2020-06-23 03:49:35
回答 1查看 97关注 0票数 0

我正在实现C应用程序,它应该能够通过GDbus使用ConnMan连接到外部Wi-Fi保护的接入点。到目前为止,我发现代理必须在"net.connman.Agent“接口上使用RequestInput回调注册,以便在连接到受保护的接入点时提供密码。我按如下方式注册代理:

代码语言:javascript
复制
GDBusMessage* methodCallMessage = g_dbus_message_new_method_call("net.connman", "/", "net.connman.Manager", "RegisterAgent");

g_dbus_message_set_body(methodCallMessage, g_variant_new ("(o)", "/test/agent"));
g_dbus_connection_send_message(connection, methodCallMessage, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, &error);

另外,我已经注册了如下接口:

代码语言:javascript
复制
guint registration_id = g_dbus_connection_register_object (connection,
                                                           "/test/agent",
                                                           introspection_data->interfaces[0],
                                                           &interface_vtable,
                                                           NULL,
                                                           NULL,
                                                           NULL);

其中introspection_data是从XML代码生成的,如下所示:

代码语言:javascript
复制
static const gchar introspection_xml[] =
"<node>"
"  <interface name='net.connman.Agent'>"
"    <method name='RequestInput'>"
"      <arg type='oa{sv}' name='service' direction='in'/>"
"      <arg type='a{sv}' name='fields' direction='out'/>"
"    </method>"
"  </interface>"
"</node>";
    
introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);

interface_vtable的定义如下:

代码语言:javascript
复制
static const GDBusInterfaceVTable interface_vtable =
{
  handle_method_call,
  nullptr,
  nullptr
};

static void
handle_method_call (GDBusConnection       *connection,
                    const gchar           *sender,
                    const gchar           *object_path,
                    const gchar           *interface_name,
                    const gchar           *method_name,
                    GVariant              *parameters,
                    GDBusMethodInvocation *invocation,
                    gpointer               user_data)
{
    printf("Method called!\n");
}

目前,我没有在我的处理程序方法中处理任何输入,只想看看它是否被调用。但是,当我在受保护的服务上调用"Connect“(在”Scan“之后获得)时,我得到了以下输出:

代码语言:javascript
复制
Call D-Bus method with reply: object = /net/connman/service/wifi_f8c091152c85_52696e6a692773206950686f6e65_managed_psk, interface = net.connman.Service, method name = Connect

(process:2929): GLib-CRITICAL **: 12:43:00.606: g_variant_type_checked_: assertion 'g_variant_type_string_is_valid (type_string)' failed

(process:2929): GLib-CRITICAL **: 12:43:00.606: g_variant_type_is_subtype_of: assertion 'g_variant_type_check (supertype)' failed

(process:2929): GLib-CRITICAL **: 12:43:00.606: g_variant_type_dup_string: assertion 'g_variant_type_check (type)' failed
Replied with error = 'GDBus.Error:net.connman.Error.InvalidArguments: Invalid arguments'

据我所知,这可能是RequestInput签名的问题,但我只看到在不同的文章/代码示例中提到的输入为'oa{sv}‘,输出为'a{sv}’。

以前有没有人遇到过这样的错误?

任何建议和解决方案都将不胜感激。

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-23 20:38:02

我自己找到了解决方案。看起来签名确实是错的,正确的签名如下:

代码语言:javascript
复制
static const gchar introspection_xml[] =
  "<node>"
  "  <interface name='net.connman.Agent'>"
  "    <method name='RequestInput'>"
  "      <arg name='service' type='o' direction='in'/>"
  "      <arg name='fields' type='a{sv}' direction='in'/>"
  "      <arg name='fields' type='a{sv}' direction='out'/>"
  "    </method>"
  "  </interface>"
  "</node>";
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62522388

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档