问题
How to pass a structure as a parameter to a dbus signal through command line?
Dbus-send --system --type=signal / com.example.signal_name string:"hello"
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;
};
回答1:
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
.
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.
来源:https://stackoverflow.com/questions/57506251/how-to-pass-a-structure-as-a-parameter-in-a-dbus-signal