Gio.DBusMessage¶
class — extends GObject.Object
A type for representing D-Bus messages that can be sent or received
on a DBusConnection.
Constructors¶
new¶
Creates a new empty DBusMessage.
new_from_blob¶
@classmethod
def new_from_blob(cls, blob: list[int], capabilities: DBusCapabilityFlags | int) -> DBusMessage
Creates a new DBusMessage from the data stored at blob. The byte
order that the message was in can be retrieved using
DBusMessage.get_byte_order.
If the blob cannot be parsed, contains invalid fields, or contains invalid
headers, IOErrorEnum.INVALID_ARGUMENT will be returned.
Parameters:
blob— A blob representing a binary D-Bus message.capabilities— ADBusCapabilityFlagsdescribing what protocol features are supported.
new_method_call¶
@classmethod
def new_method_call(cls, name: str | None, path: str, interface_: str | None, method: str) -> DBusMessage
Creates a new DBusMessage for a method call.
Parameters:
name— A valid D-Bus name orNone.path— A valid object path.interface_— A valid D-Bus interface name orNone.method— A valid method name.
new_signal¶
Creates a new DBusMessage for a signal emission.
Parameters:
path— A valid object path.interface_— A valid D-Bus interface name.signal— A valid signal name.
Methods¶
copy¶
Copies message. The copy is a deep copy and the returned
DBusMessage is completely identical except that it is guaranteed
to not be locked.
This operation can fail if e.g. message contains file descriptors
and the per-process or system-wide open files limit is reached.
get_arg0¶
Convenience to get the first item in the body of message.
See DBusMessage.get_arg0_path for returning object-path-typed
arg0 values.
get_arg0_path¶
Convenience to get the first item in the body of message.
See DBusMessage.get_arg0 for returning string-typed arg0 values.
get_body¶
Gets the body of a message.
get_byte_order¶
Gets the byte order of message.
get_destination¶
Convenience getter for the DBusMessageHeaderField.DESTINATION header field.
get_error_name¶
Convenience getter for the DBusMessageHeaderField.ERROR_NAME header field.
get_flags¶
Gets the flags for message.
get_header¶
Gets a header field on message.
The caller is responsible for checking the type of the returned GLib.Variant
matches what is expected.
Parameters:
header_field— A 8-bit unsigned integer (typically a value from theDBusMessageHeaderFieldenumeration)
get_header_fields¶
Gets an array of all header fields on message that are set.
get_interface¶
Convenience getter for the DBusMessageHeaderField.INTERFACE header field.
get_locked¶
Checks whether message is locked. To monitor changes to this
value, connect to the GObject.Object::notify signal to listen for changes
on the DBusMessage:locked property.
get_member¶
Convenience getter for the DBusMessageHeaderField.MEMBER header field.
get_message_type¶
Gets the type of message.
get_num_unix_fds¶
Convenience getter for the DBusMessageHeaderField.NUM_UNIX_FDS header field.
get_path¶
Convenience getter for the DBusMessageHeaderField.PATH header field.
get_reply_serial¶
Convenience getter for the DBusMessageHeaderField.REPLY_SERIAL header field.
get_sender¶
Convenience getter for the DBusMessageHeaderField.SENDER header field.
get_serial¶
Gets the serial for message.
get_signature¶
Convenience getter for the DBusMessageHeaderField.SIGNATURE header field.
This will always be non-None, but may be an empty string.
get_unix_fd_list¶
Gets the UNIX file descriptors associated with message, if any.
This method is only available on UNIX.
The file descriptors normally correspond to G_VARIANT_TYPE_HANDLE
values in the body of the message. For example,
if GLib.Variant.get_handle returns 5, that is intended to be a reference
to the file descriptor that can be accessed by
g_unix_fd_list_get (list, 5, ...).
lock¶
If message is locked, does nothing. Otherwise locks the message.
new_method_error_literal¶
Creates a new DBusMessage that is an error reply to method_call_message.
Parameters:
error_name— A valid D-Bus error name.error_message— The D-Bus error message.
new_method_reply¶
Creates a new DBusMessage that is a reply to method_call_message.
print¶
Produces a human-readable multi-line description of message.
The contents of the description has no ABI guarantees, the contents and formatting is subject to change at any time. Typical output looks something like this:
Flags: none
Version: 0
Serial: 4
Headers:
path -> objectpath '/org/gtk/GDBus/TestObject'
interface -> 'org.gtk.GDBus.TestInterface'
member -> 'GimmeStdout'
destination -> ':1.146'
Body: ()
UNIX File Descriptors:
(none)
Flags: no-reply-expected
Version: 0
Serial: 477
Headers:
reply-serial -> uint32 4
destination -> ':1.159'
sender -> ':1.146'
num-unix-fds -> uint32 1
Body: ()
UNIX File Descriptors:
fd 12: dev=0:10,mode=020620,ino=5,uid=500,gid=5,rdev=136:2,size=0,atime=1273085037,mtime=1273085851,ctime=1272982635
Parameters:
indent— Indentation level.
set_body¶
Sets the body message. As a side-effect the
DBusMessageHeaderField.SIGNATURE header field is set to the
type string of body (or cleared if body is None).
If body is floating, message assumes ownership of body.
Parameters:
body— EitherNoneor aGLib.Variantthat is a tuple.
set_byte_order¶
Sets the byte order of message.
Parameters:
byte_order— The byte order.
set_destination¶
Convenience setter for the DBusMessageHeaderField.DESTINATION header field.
Parameters:
value— The value to set.
set_error_name¶
Convenience setter for the DBusMessageHeaderField.ERROR_NAME header field.
Parameters:
value— The value to set.
set_flags¶
Sets the flags to set on message.
Parameters:
flags— Flags formessagethat are set (typically values from theDBusMessageFlagsenumeration bitwise ORed together).
set_header¶
def set_header(self, header_field: DBusMessageHeaderField | int, value: GLib.Variant | None = ...) -> None
Sets a header field on message.
If value is floating, message assumes ownership of value.
Parameters:
header_field— A 8-bit unsigned integer (typically a value from theDBusMessageHeaderFieldenumeration)value— AGLib.Variantto set the header field orNoneto clear the header field.
set_interface¶
Convenience setter for the DBusMessageHeaderField.INTERFACE header field.
Parameters:
value— The value to set.
set_member¶
Convenience setter for the DBusMessageHeaderField.MEMBER header field.
Parameters:
value— The value to set.
set_message_type¶
Sets message to be of type.
Parameters:
type— A 8-bit unsigned integer (typically a value from theDBusMessageTypeenumeration).
set_num_unix_fds¶
Convenience setter for the DBusMessageHeaderField.NUM_UNIX_FDS header field.
Parameters:
value— The value to set.
set_path¶
Convenience setter for the DBusMessageHeaderField.PATH header field.
Parameters:
value— The value to set.
set_reply_serial¶
Convenience setter for the DBusMessageHeaderField.REPLY_SERIAL header field.
Parameters:
value— The value to set.
set_sender¶
Convenience setter for the DBusMessageHeaderField.SENDER header field.
Parameters:
value— The value to set.
set_serial¶
Sets the serial for message.
The D-Bus specification
does not allow the serial to be zero.
Parameters:
serial— A #guint32, which must not be zero.
set_signature¶
Convenience setter for the DBusMessageHeaderField.SIGNATURE header field.
Parameters:
value— The value to set.
set_unix_fd_list¶
Sets the UNIX file descriptors associated with message. As a
side-effect the DBusMessageHeaderField.NUM_UNIX_FDS header
field is set to the number of fds in fd_list (or cleared if
fd_list is None).
This method is only available on UNIX.
When designing D-Bus APIs that are intended to be interoperable,
please note that non-GDBus implementations of D-Bus can usually only
access file descriptors if they are referenced by a value of type
G_VARIANT_TYPE_HANDLE in the body of the message.
Parameters:
fd_list— AUnixFDListorNone.
to_blob¶
Serializes message to a blob. The byte order returned by
DBusMessage.get_byte_order will be used.
Parameters:
capabilities— ADBusCapabilityFlagsdescribing what protocol features are supported.
to_gerror¶
If message is not of type DBusMessageType.ERROR does
nothing and returns False.
Otherwise this method encodes the error in message as a GLib.Error
using g_dbus_error_set_dbus_error() using the information in the
DBusMessageHeaderField.ERROR_NAME header field of message as
well as the first string item in message's body.
Static functions¶
bytes_needed¶
Utility function to calculate how many bytes are needed to
completely deserialize the D-Bus message stored at blob.
Parameters:
blob— A blob representing a binary D-Bus message.