【问题标题】:GLib-GIO-CRITICAL error While invoking a method on dbus interface在 dbus 接口上调用方法时出现 GLib-GIO-CRITICAL 错误
【发布时间】:2015-05-11 00:32:34
【问题描述】:

我正在使用 lgi 动态 Lua 绑定到基于 GObject 的库,以通过 dbus 在应用程序之间进行通信。以下是我的应用程序的 method_call 的 dbus-send 命令输出的一部分。

方法返回 sender=:1.2 -> dest=:1.19 reply_serial=2

数组[

  dict entry(
     string "XYZ"
     variant             int32 1
  )

  dict entry(
     string "ABC"
     variant             int32 0
  )
  dict entry(
     string "EFG"
     variant             string "str"
  )
  dict entry(
     string "HIJ"
     variant             string "8c011401-4836-4889-8fa5-32ddb894a97a"
  )
  dict entry(
     string "KLM"
     variant             string "dummy"
  )

现在我想在上面的输出中设置“DEF”值,其签名为“a{sv}”。下面是我写的代码:

local lgi=require 'lgi'
local Gio=lgi.require 'Gio'
local GLib=lgi.GLib
local db=require 'debugger'

local factory=function()
        return Gio.bus_get_sync(Gio.BusType.SYSTEM)
end

local bus=factory()

local j=GLib.Variant.new('s','value')
local k2=GLib.Variant('a{sv}',{DEF=j})

str,err=bus:call_sync('org.destination','/my/application/obj_path','org.destination.path','Method_name',k2,nil,Gio.DBusConnectionFlags.NONE,-1)
     if err then
          print(err)
     else
          print(str)
     end

当我运行上述脚本时,我遇到了以下错误:

(进程:19120):GLib-GIO-CRITICAL **:g_dbus_connection_call_sync_internal:断言'(参数== NULL)|| g_variant_is_of_type(参数,G_VARIANT_TYPE_TUPLE)'失败。

如何设置上述值?我在哪里做错了?有人可以帮我吗?

提前致谢。

【问题讨论】:

    标签: lua dbus gobject


    【解决方案1】:

    该错误非常清楚地告诉您问题所在。 call_sync 的“参数”参数(C API 中的 g_dbus_connection_call_sync)需要是一个元组。你提供了一本字典。更改 k2 使其成为元组变体。

    【讨论】:

    • 从您的回答中,我了解到 'a{sv}' 是一本字典。所以我将 k2 传递给 local final=GLib.Variant.new_tuple({k2}) ,然后将它传递给 call_sync 它就可以工作了。谢谢你的回答
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-16
    • 2016-11-16
    相关资源
    最近更新 更多