如何将 a{sv} 参数传递给 gdbus?

如何将 a{sv} 参数传递给 gdbus?

我在以字典格式(字符串,变量)传递函数参数时遇到问题;我尝试在 gnome 中运行截屏视频,并启动该函数,我需要传递以下参数:

-method name="Screencast"-
  -arg type="s" direction="in" name="file_template"/-
  -arg type="a{sv}" direction="in" name="options"/-
  -arg type="b" direction="in" name="flash"/-
  -arg type="b" direction="out" name="success"/-
  -arg type="s" direction="out" name="filename_used"/-
-/method-

这是我的呼吁:

~$ gdbus call --session --dest org.gnome.Shell.Screencast --object-path /org/gnome/Shell/Screencast --method org.gnome.Shell.Screencast.Screencast "test_ %d_ %t.webm" {dict:string:variant:"draw-cursor",true,"framerate",35,pipeline,"vp8enc min_quantizer=13 max_quantizer=13 cpu-used=5 deadline=1000000 threads=%T ! queue ! webmmux"}

这是错误输出:“a{sv}”:0-33:无法解析为“a{sv}”类型的值。语法错误吗?谢谢

答案1

a{sv} 应表示为:

"{'String': <'variant_value'>, 'String2': <'variant_value'>}"

为了解决这个问题,我在某些对象接口上调用了 org.freedesktop.DBus.Properties.GetAll,因为它返回了{sv}。

例如,wpa_supplicant 中的 CreateInterface 方法采用{sv}:

gdbus call -y -d fi.w1.wpa_supplicant1 -o /fi/w1/wpa_supplicant1 -m fi.w1.wpa_supplicant1.CreateInterface "{'Ifname': <'wlan0'>}"

或者添加多个接口(字符串:变量的真正数组):

"{'Ifname': <'wlan0'>, 'Ifname': <'wlan1'>}"

相关内容