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

use*_*771 9 gnome bash dbus screencast

我在以字典格式(字符串,变体)传递函数的参数时遇到问题;我尝试在 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-
Run Code Online (Sandbox Code Playgroud)

这是我的电话:

~$ 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"}
Run Code Online (Sandbox Code Playgroud)

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

apo*_*ort 9

a{sv} 应表示为:

"{'String': <'variant_value'>, 'String2': <'variant_value'>}"
Run Code Online (Sandbox Code Playgroud)

为了解决这个问题,我在某个对象接口上调用了 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'>}"
Run Code Online (Sandbox Code Playgroud)

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

"{'Ifname': <'wlan0'>, 'Ifname': <'wlan1'>}"
Run Code Online (Sandbox Code Playgroud)