Making and parsing messages¶
The core of Jeepney is code to build, serialise and deserialise D-Bus messages.
Making messages¶
D-Bus has four message types. Three, method call, method return and error, are used in a request-reply pattern. The fourth, signal, is a broadcast message with no reply.
- Method call messages are most conveniently made with a message generator
class, which can be autogenerated. One layer down from this
is
new_method_call()
, which takes aDBusAddress
object. - Method return and error messages are made with
new_method_return()
andnew_error()
, passing the method call message which they are replying to. - signal messages are made with
new_signal()
, which takes aDBusAddress
representing the sender.
All of these return a Message
object. Message.serialise()
converts it to bytes, but none of these core methods ever send a message.
See the integration layer for that.
Signatures¶
D-Bus is strongly typed, and every message has a signature describing the body
data. These are strings using characters such as i
for a signed 32-bit
integer. See the DBus specification
for the full list.
Jeepney does not try to guess or discover the signature when you build a message: your code must explicitly specify a signature for every message. However, Jeepney can help you write this code: see Generating D-Bus wrappers.
D-Bus types are converted to and from native Python objects as follows:
- All the D-Bus integer types are represented as Python
int
, including BYTE when it’s not in an array. - BOOLEAN is
bool
. - DOUBLE is
float
. - STRING, OBJECT_PATH and SIGNATURE are all
str
. - ARRAY is
list
, except that an array of BYTE is abytes
object, and an array of DICT_ENTRY is adict
. - STRUCT is
tuple
. - VARIANT is a 2-tuple
(signature, data)
. E.g. to put a string into a variant field, you would pass the data("s", "my string")
. - UNIX_FD are converted from objects with a
.fileno()
method or plain integers, and converted toFileDescriptor
objects. See Sending & receiving file descriptors for more details.