0

writing generalized set() and get() method of MsgArg for different device types.

asked 2014-11-03 03:09:59 -0800

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

MsgArg outArg[2];
    struct device{
        char dev_name[256];
        char    dev_type[256];
        uint32_t    dev_status;
    };
 struct device arr[MAX_DEVICES];
 outArg[0].Set("a(ssu)",5,arr);

 QStatus status = MethodReply(msg, outArg,1);

when writing the above code getting signature error.Does not match with the expected signatures.

Is setting the Array of structure is allowed or I have to put here only premitive types.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-11-07 12:58:04 -0800

georgen gravatar image

updated 2014-11-07 13:06:59 -0800

When building an array that contains another container you make an array of MsgArgs that each hold the inner container then place them in the array;

MsgArg outArg[1];
struct device{
    char dev_name[256];
    char    dev_type[256];
    uint32_t    dev_status;
};
struct device arr[MAX_DEVICES];
MsgArg struct_elements[MAX_DEVICES];
for(size_t i = 0; i < MAX_DEVICES; ++i) {
    struct_elements[i].Set("(ssu)", arr[i].dev_name, arr[i].dev_type, arr[i].dev_status);
}


outArg[0].Set("a(ssu)", MAX_DEVICES, struct_elements);
QStatus status = MethodReply(msg, outArg,1);

Works the same way when reading the structs out of the array;

MsgArg *struct_elements_out;
size_t struct_elements_len;

arg.Get("a(ssu)", &struct_elements_len, &struct_elements_out);

Read the struct elements from the struct_elements_out array.

edit flag offensive delete publish link more
Login/Signup to Answer

Question Tools

Follow
1 follower

Stats

Asked: 2014-11-03 03:09:59 -0800

Seen: 65 times

Last updated: Nov 07 '14