我有一个 D-Bus 方法,它接收将字符串映射到结构的字典作为输入:
<method name="myMethod">
<arg name="input_dict" type="a{s(ss)}" direction="in"/>
...
</method>
我试图使用 busctl 调用这种方法但没有成功。到目前为止,我已经尝试使用以下参数:
busctl call ${SERVICE} ${OBJECT} ${INTERFACE} myMethod "a{s(ss)}" 1 "str1" \( "str2" "str3" \)
busctl call ${SERVICE} ${OBJECT} ${INTERFACE} myMethod "a{s(ss)}" 1 str1 str2 str3
busctl call ${SERVICE} ${OBJECT} ${INTERFACE} myMethod "a{s(ss)}" str1 str2 str3
busctl call ${SERVICE} ${OBJECT} ${INTERFACE} myMethod "a{s(ss)}" 1 str1 '(ss)' str2 str3
busctl call ${SERVICE} ${OBJECT} ${INTERFACE} myMethod "a{s(ss)}" 1 str1 \(ss\) str2 str3
busctl call ${SERVICE} ${OBJECT} ${INTERFACE} myMethod "a{s(ss)}" 1 str1 "ss" str2 str3
busctl call ${SERVICE} ${OBJECT} ${INTERFACE} myMethod "a{s(ss)}" 1 str1 \"ss\" str2 str3
busctl call ${SERVICE} ${OBJECT} ${INTERFACE} myMethod "a{s(ss)}" 1 str1 \(str2 str3\)
busctl call ${SERVICE} ${OBJECT} ${INTERFACE} myMethod "a{s(ss)}" 1 str1 \(ss\) \(str2 str3\)
根据通话,我收到不同的错误:
No such method 'WakeUp' in interface 'com.verisure.cuxscored.DECT' at object path '/com/verisure/cuxscored/dect' (signature 'a{s(ss)}')
Too many parameters for signature.
因此,我的问题是:使用 busctl 时如何将参数传递给 myMethod?
编辑
感谢ukBaz的回答,我得到了洞察力。我也有一个 getter 方法,我之前调用过,我得到的结果与 ukBaz 的有点不同:
<method name="myGetMethod">
<arg name="output_dict" type="a{s(ss)}" direction="out"/>
...
</method>
运行 busctl 命令它给了我这个:
a(s(ss)) 1 "str1" "str2" "str3"
注意与预期解决方案的区别(a(s(ss))
而不是a{s(ss)}
,括号而不是大括号)。如果我做对了,那么输出应该被解释为一个包含一个字符串的结构数组,以及另一个包含两个字符串的结构。
我不太确定为什么结果不同,但我已经克服了使用 getter 的输出直接作为另一种方法的输入的问题:
busctl call ${SERVICE} ${OBJECT} ${INTERFACE} myMethod `busctl call ${SERVICE} ${OBJECT} ${INTERFACE} myGetMethod`
同样,如果我“按原样”使用 myGetMethod 的输出,该方法也可以工作:
busctl call ${SERVICE} ${OBJECT} ${INTERFACE} myMethod "a(s(ss))" 1 "str1" "str2" "str3"
所以剩下的唯一问题是为什么 D-bus 方法返回一个结构数组,即使它被声明为返回一个字典。
编辑 2
如果我运行 dbusctl introspect,这就是我得到的:
NAME TYPE SIGNATURE RESULT/VALUE FLAGS
${INTERFACE} interface - - -
.myGetMethod method - a{s(ss)} -
.myMethod method a{s(ss)} - -
...
作为一个问题,我也尝试过使用 D-Feet,但没有更好的结果。我调用了一个返回 a{s(ss)} 类型值的方法,D-Feet 返回以下结构:
[('str1', ('str2', 'str3'))]
如果我然后使用相同的结构在 D-Feet 上调用 myMethod,我得到一个 DBus.Error.UnknownMethod:
No '
"such method 'myMethod' in interface '${INTERFACE}' at object "
"path '${OBJECT}' (signature 'a{s(ss)}') (19)")
但是,如果我使用参数、大括号等,我会收到不同的错误消息,但我无法让该方法正常工作。那么,在使用 D-Feet 时,将这种参数传递给 myMethod 的适当方式是什么?