Index · Directives · Python · libudev · gudev systemd 218

Name

sd_bus_message_append — Attach parts of message based on a format string

Synopsis

#include <systemd/sd-bus.h>
int sd_bus_message_append(sd_bus_message *m,
 const char *types,
 ...);
 

Description

The sd_bus_message_append function appends a sequence of items to message m. The format string types describes the types of arguments that follow.

The format string is composed of the elements shown in the table below. It contains zero or more single "complete types". Each complete type may be one of the basic types or a fully described container type. A container type may be a structure, a variant type code, an array with its element type, or a dictionary with its entry type. The format string is NUL-terminated.

In case of a basic type, one argument of the corresponding type is expected.

A structure is denoted by a sequence of complete types between "(" and ")". This sequence cannot be empty — it must contain at least one type. Arguments corresponding to this nested sequence follow the same rules as if they were not nested.

A variant is denoted by "v". Correspoding arguments must include a format string denoting a complete type, and following that, arguments corresponding to the specified type.

An array is denoted by "a" followed by a complete type. Corresponding arguments must include the size of the array, and then repeated this number of times, arguments corresponding to the nested type.

A dictionary is an array of dictionary entries, denoted by "a" followed by a pair of complete types between "{" and "}". The first of those types must be a basic type. Corresponding arguments must include the size of the dictionary, and then repeated this number of times, arguments corresponding to each of the two nested types.

Table 1. Item format specifiers

SpecifierConstantDescriptionSize
"y"SD_BUS_TYPE_BYTEunsigned integer1 byte
"b"SD_BUS_TYPE_BOOLEANboolean4 bytes
"n"SD_BUS_TYPE_INT16signed integer2 bytes
"q"SD_BUS_TYPE_UINT16unsigned integer2 bytes
"i"SD_BUS_TYPE_INT32signed integer4 bytes
"u"SD_BUS_TYPE_UINT32unsigned integer4 bytes
"x"SD_BUS_TYPE_INT64signed integer8 bytes
"t"SD_BUS_TYPE_UINT64unsigned integer8 bytes
"d"SD_BUS_TYPE_DOUBLEfloating-point8 bytes
"s"SD_BUS_TYPE_STRINGUnicode stringvariable
"o"SD_BUS_TYPE_OBJECT_PATHobject pathvariable
"g"SD_BUS_TYPE_SIGNATUREsignaturevariable
"h"SD_BUS_TYPE_UNIX_FDUNIX file descriptor4 bytes
"a"SD_BUS_TYPE_ARRAYarraydetermined by array type and size
"v"SD_BUS_TYPE_VARIANTvariantdetermined by the type argument
"("SD_BUS_TYPE_STRUCT_BEGINarray startdetermined by the nested types
")"SD_BUS_TYPE_STRUCT_ENDarray end
"{"SD_BUS_TYPE_DICT_ENTRY_BEGINdictionary entry startdetermined by the nested types
"}"SD_BUS_TYPE_DICT_ENTRY_ENDdictionary entry end

Types string grammar

types ::= complete_type*
complete_type ::= basic_type | variant | structure | array | dictionary
basic_type ::= "y" | "n" | "q" | "u" | "i" | "x" | "t" | "d" |
               "b" | "h" |
               "s" | "o" | "g"
variant ::= "v"
structure ::= "(" complete_type+ ")"
array ::= "a" complete_type
dictionary ::= "a" "{" basic_type complete_type "}"

Examples

Append a single basic type (the string "a string"):

sd_bus_message *m;
...
sd_bus_message_append(m, "s", "a string");

Append all types of integers:

uint8_t y = 1;
int16_t n = 2;
uint16_t q = 3;
int32_t i = 4;
uint32_t u = 5;
int32_t x = 6;
uint32_t t = 7;
double d = 8.0;
sd_bus_message_append(m, "ynqiuxtd", y, n, q, i, u, x, t, d);

Append a structure composed of string and a D-Bus path:

sd_bus_message_append(m, "(so)", "a string", "/a/path");

Append an array of UNIX file descriptors:

sd_bus_message_append(m, "ah", 3, STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO);

Append a variant, with the real type "g" (signature), and value "sdbusisgood":

sd_bus_message_append(m, "v", "g", "sdbusisgood");

Append a dictionary containing the mapping {1=>"a", 2=>"b", 3=>""}:

sd_bus_message_append(m, "a{is}", 3, 1, "a", 2, "b", 3, NULL);
     

Return Value

On success, this call returns 0 or a positive integer. On failure, this call returns a negative errno-style error code.

Errors

Returned errors may indicate the following problems:

-EINVAL

Specified parameter is invalid.

-EPERM

Message has been sealed.

-ESTALE

Message is in invalid state.

-ENXIO

Message cannot be appended to.

-ENOMEM

Memory allocation failed.

Notes

sd_bus_open_user() and other functions described here are available as a shared library, which can be compiled and linked to with the libsystemd-bus pkg-config(1) file.

See Also

systemd(1), sd-bus(3), sd_bus_new(3), sd_bus_ref(3), sd_bus_unref(3), ssh(1), systemd-machined.service(8), machinectl(1)