如何在dbus信号中将结构作为参数传递? [英] How to Pass a structure as a parameter in a dbus signal?
问题描述
如何通过命令行将结构作为参数传递给dbus信号?
How to pass a structure as a parameter to a dbus signal through command line?
Dbus-send --system --type = signal / com.example。 signal_name字符串: hello
Dbus-send --system --type=signal / com.example.signal_name string:"hello"
在字符串的地方,我想传递结构foo。
In the place of string, I want to pass structure foo.
typedef enum {MODE1, MODE2, MODE3} MODE;
typedef enum {TYPE1, TYPE2} TYPE;
struct foo
{
MODE mode;
TYPE type;
};
推荐答案
首先,您需要弄清楚如何表示结构作为 D总线值。它最可能的表示形式是(uu)
类型的值,其中第一个 u
是 mode
(使用很好C枚举值到整数的定义和稳定映射),第二个 u
是类型
。
Firstly, you need to work out how to represent that structure as a D-Bus value. Its most likely representation would be as a value of type (uu)
where the first u
is the mode
(using some well-defined and stable mapping of C enum values to integers) and the second u
is the type
.
第二,您需要弄清楚如何在命令行上编写该代码。但是, dbus-send
目前不支持结构,因此无法使用 dbus-send
。我建议使用 gdbus
而是按照此StackOverflow问题 。
Secondly, you need to work out how to write that on the command line. However, dbus-send
doesn’t currently support structs, so it’s not possible using dbus-send
. I suggest using gdbus
instead, as per this StackOverflow question.
这篇关于如何在dbus信号中将结构作为参数传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!