Search code examples
luadbusgobject

GLib-GIO-CRITICAL error While invoking a method on dbus interface


I am using lgi dynamic Lua binding to GObject based libraries to communicate between applications through dbus.Below is some portion of output of the dbus-send command for the method_call of my application.

method return sender=:1.2 -> dest=:1.19 reply_serial=2

array [

  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"
  )

Now I want to set the "DEF" value in the above output which has signature as 'a{sv}'. Below is the code I wrote to do the same:

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

When I run the above script I am facing the following error:

(process:19120): GLib-GIO-CRITICAL **: g_dbus_connection_call_sync_internal: assertion '(parameters == NULL) || g_variant_is_of_type (parameters, G_VARIANT_TYPE_TUPLE)' failed.

How to set the above value ? Where am I doing wrong ? Can someone help me ?

Thanks in advance.


Solution

  • The error tells you pretty clearly what the problem is. The "parameter" argument to call_sync (g_dbus_connection_call_sync in the C API) needs to be a tuple. You have provided a dictionary. Change k2 so that it is a tuple variant.