Gio.DBusConnection

g GObject.GInterface GObject.GInterface Gio.AsyncInitable Gio.AsyncInitable GObject.GInterface->Gio.AsyncInitable Gio.Initable Gio.Initable GObject.GInterface->Gio.Initable GObject.Object GObject.Object Gio.DBusConnection Gio.DBusConnection GObject.Object->Gio.DBusConnection Gio.AsyncInitable->Gio.DBusConnection Gio.Initable->Gio.DBusConnection

Subclasses:

None

Methods

Inherited:

GObject.Object (37), Gio.AsyncInitable (4), Gio.Initable (2)

Structs:

GObject.ObjectClass (5)

class

new (stream, guid, flags, observer, cancellable, callback, *user_data)

class

new_finish (res)

class

new_for_address (address, flags, observer, cancellable, callback, *user_data)

class

new_for_address_finish (res)

class

new_for_address_sync (address, flags, observer, cancellable)

class

new_sync (stream, guid, flags, observer, cancellable)

add_filter (filter_function, *user_data)

call (bus_name, object_path, interface_name, method_name, parameters, reply_type, flags, timeout_msec, cancellable, callback, *user_data)

call_finish (res)

call_sync (bus_name, object_path, interface_name, method_name, parameters, reply_type, flags, timeout_msec, cancellable)

call_with_unix_fd_list (bus_name, object_path, interface_name, method_name, parameters, reply_type, flags, timeout_msec, fd_list, cancellable, callback, *user_data)

call_with_unix_fd_list_finish (res)

call_with_unix_fd_list_sync (bus_name, object_path, interface_name, method_name, parameters, reply_type, flags, timeout_msec, fd_list, cancellable)

close (cancellable, callback, *user_data)

close_finish (res)

close_sync (cancellable)

emit_signal (destination_bus_name, object_path, interface_name, signal_name, parameters)

export_action_group (object_path, action_group)

export_menu_model (object_path, menu)

flush (cancellable, callback, *user_data)

flush_finish (res)

flush_sync (cancellable)

get_capabilities ()

get_exit_on_close ()

get_flags ()

get_guid ()

get_last_serial ()

get_peer_credentials ()

get_stream ()

get_unique_name ()

is_closed ()

register_object (object_path, interface_info, method_call_closure, get_property_closure, set_property_closure)

register_subtree (object_path, vtable, flags, user_data, user_data_free_func)

remove_filter (filter_id)

send_message (message, flags)

send_message_with_reply (message, flags, timeout_msec, cancellable, callback, *user_data)

send_message_with_reply_finish (res)

send_message_with_reply_sync (message, flags, timeout_msec, cancellable)

set_exit_on_close (exit_on_close)

signal_subscribe (sender, interface_name, member, object_path, arg0, flags, callback, *user_data)

signal_unsubscribe (subscription_id)

start_message_processing ()

unexport_action_group (export_id)

unexport_menu_model (export_id)

unregister_object (registration_id)

unregister_subtree (registration_id)

Virtual Methods

Inherited:

GObject.Object (7), Gio.AsyncInitable (2), Gio.Initable (1)

Properties

Name

Type

Flags

Short Description

address

str

w/co

authentication-observer

Gio.DBusAuthObserver

w/co

capabilities

Gio.DBusCapabilityFlags

r

closed

bool

r

exit-on-close

bool

r/w

flags

Gio.DBusConnectionFlags

r/w/co

guid

str

r/w/co

stream

Gio.IOStream

r/w/co

unique-name

str

r

Signals

Inherited:

GObject.Object (1)

Name

Short Description

closed

Emitted when the connection is closed.

Fields

Inherited:

GObject.Object (1)

Class Details

class Gio.DBusConnection(**kwargs)
Bases:

GObject.Object, Gio.AsyncInitable, Gio.Initable

Abstract:

No

The GDBusConnection type is used for D-Bus connections to remote peers such as a message buses.

It is a low-level API that offers a lot of flexibility. For instance, it lets you establish a connection over any transport that can by represented as a [class`Gio`.IOStream].

This class is rarely used directly in D-Bus clients. If you are writing a D-Bus client, it is often easier to use the [func`Gio`.bus_own_name], [func`Gio`.bus_watch_name] or [func`Gio`.DBusProxy.new_for_bus] APIs.

As an exception to the usual GLib rule that a particular object must not be used by two threads at the same time, GDBusConnection``s methods may be called from any thread. This is so that [func`Gio`.bus\_get] and [func`Gio`.bus\_get\_sync] can safely return the same ``GDBusConnection when called from any thread.

Most of the ways to obtain a GDBusConnection automatically initialize it (i.e. connect to D-Bus): for instance, [func`Gio`.DBusConnection.new] and [func`Gio`.bus_get], and the synchronous versions of those methods, give you an initialized connection. Language bindings for GIO should use [func`Gio`.Initable.new] or [func`Gio`.AsyncInitable.new_async], which also initialize the connection.

If you construct an uninitialized GDBusConnection, such as via [ctor`GObject`.Object.new], you must initialize it via [method`Gio`.Initable.init] or [method`Gio`.AsyncInitable.init_async] before using its methods or properties. Calling methods or accessing properties on a GDBusConnection that has not completed initialization successfully is considered to be invalid, and leads to undefined behaviour. In particular, if initialization fails with a GError, the only valid thing you can do with that GDBusConnection is to free it with [method`GObject`.Object.unref].

An example D-Bus server

Here is an example for a D-Bus server: gdbus-example-server.c

An example for exporting a subtree

Here is an example for exporting a subtree: gdbus-example-subtree.c

An example for file descriptor passing

Here is an example for passing UNIX file descriptors: gdbus-unix-fd-client.c

An example for exporting a GObject.Object

Here is an example for exporting a GObject.Object: gdbus-example-export.c

New in version 2.26.

classmethod new(stream, guid, flags, observer, cancellable, callback, *user_data)[source]
Parameters:

Asynchronously sets up a D-Bus connection for exchanging D-Bus messages with the end represented by stream.

If stream is a Gio.SocketConnection, then the corresponding Gio.Socket will be put into non-blocking mode.

The D-Bus connection will interact with stream from a worker thread. As a result, the caller should not interact with stream after this method has been called, except by calling GObject.Object.unref() on it.

If observer is not None it may be used to control the authentication process.

When the operation is finished, callback will be invoked. You can then call Gio.DBusConnection.new_finish() to get the result of the operation.

This is an asynchronous failable constructor. See Gio.DBusConnection.new_sync() for the synchronous version.

New in version 2.26.

classmethod new_finish(res)[source]
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult obtained from the Gio.AsyncReadyCallback passed to Gio.DBusConnection.new().

Raises:

GLib.Error

Returns:

a Gio.DBusConnection or None if error is set. Free with GObject.Object.unref().

Return type:

Gio.DBusConnection

Finishes an operation started with Gio.DBusConnection.new().

New in version 2.26.

classmethod new_for_address(address, flags, observer, cancellable, callback, *user_data)[source]
Parameters:

Asynchronously connects and sets up a D-Bus client connection for exchanging D-Bus messages with an endpoint specified by address which must be in the D-Bus address format.

This constructor can only be used to initiate client-side connections - use Gio.DBusConnection.new() if you need to act as the server. In particular, flags cannot contain the Gio.DBusConnectionFlags.AUTHENTICATION_SERVER, Gio.DBusConnectionFlags.AUTHENTICATION_ALLOW_ANONYMOUS or Gio.DBusConnectionFlags.AUTHENTICATION_REQUIRE_SAME_USER flags.

When the operation is finished, callback will be invoked. You can then call Gio.DBusConnection.new_for_address_finish() to get the result of the operation.

If observer is not None it may be used to control the authentication process.

This is an asynchronous failable constructor. See Gio.DBusConnection.new_for_address_sync() for the synchronous version.

New in version 2.26.

classmethod new_for_address_finish(res)[source]
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult obtained from the Gio.AsyncReadyCallback passed to Gio.DBusConnection.new()

Raises:

GLib.Error

Returns:

a Gio.DBusConnection or None if error is set. Free with GObject.Object.unref().

Return type:

Gio.DBusConnection

Finishes an operation started with Gio.DBusConnection.new_for_address().

New in version 2.26.

classmethod new_for_address_sync(address, flags, observer, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

a Gio.DBusConnection or None if error is set. Free with GObject.Object.unref().

Return type:

Gio.DBusConnection

Synchronously connects and sets up a D-Bus client connection for exchanging D-Bus messages with an endpoint specified by address which must be in the D-Bus address format.

This constructor can only be used to initiate client-side connections - use Gio.DBusConnection.new_sync() if you need to act as the server. In particular, flags cannot contain the Gio.DBusConnectionFlags.AUTHENTICATION_SERVER, Gio.DBusConnectionFlags.AUTHENTICATION_ALLOW_ANONYMOUS or Gio.DBusConnectionFlags.AUTHENTICATION_REQUIRE_SAME_USER flags.

This is a synchronous failable constructor. See Gio.DBusConnection.new_for_address() for the asynchronous version.

If observer is not None it may be used to control the authentication process.

New in version 2.26.

classmethod new_sync(stream, guid, flags, observer, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

a Gio.DBusConnection or None if error is set. Free with GObject.Object.unref().

Return type:

Gio.DBusConnection

Synchronously sets up a D-Bus connection for exchanging D-Bus messages with the end represented by stream.

If stream is a Gio.SocketConnection, then the corresponding Gio.Socket will be put into non-blocking mode.

The D-Bus connection will interact with stream from a worker thread. As a result, the caller should not interact with stream after this method has been called, except by calling GObject.Object.unref() on it.

If observer is not None it may be used to control the authentication process.

This is a synchronous failable constructor. See Gio.DBusConnection.new() for the asynchronous version.

New in version 2.26.

add_filter(filter_function, *user_data)[source]
Parameters:
Returns:

a filter identifier that can be used with Gio.DBusConnection.remove_filter()

Return type:

int

Adds a message filter. Filters are handlers that are run on all incoming and outgoing messages, prior to standard dispatch. Filters are run in the order that they were added. The same handler can be added as a filter more than once, in which case it will be run more than once. Filters added during a filter callback won’t be run on the message being processed. Filter functions are allowed to modify and even drop messages.

Note that filters are run in a dedicated message handling thread so they can’t block and, generally, can’t do anything but signal a worker thread. Also note that filters are rarely needed - use API such as Gio.DBusConnection.send_message_with_reply(), Gio.DBusConnection.signal_subscribe() or Gio.DBusConnection.call() instead.

If a filter consumes an incoming message the message is not dispatched anywhere else - not even the standard dispatch machinery (that API such as Gio.DBusConnection.signal_subscribe() and Gio.DBusConnection.send_message_with_reply() relies on) will see the message. Similarly, if a filter consumes an outgoing message, the message will not be sent to the other peer.

If user_data_free_func is non-None, it will be called (in the thread-default main context of the thread you are calling this method from) at some point after user_data is no longer needed. (It is not guaranteed to be called synchronously when the filter is removed, and may be called after self has been destroyed.)

New in version 2.26.

call(bus_name, object_path, interface_name, method_name, parameters, reply_type, flags, timeout_msec, cancellable, callback, *user_data)[source]
Parameters:

Asynchronously invokes the method_name method on the interface_name D-Bus interface on the remote object at object_path owned by bus_name.

If self is closed then the operation will fail with Gio.IOErrorEnum.CLOSED. If cancellable is canceled, the operation will fail with Gio.IOErrorEnum.CANCELLED. If parameters contains a value not compatible with the D-Bus protocol, the operation fails with Gio.IOErrorEnum.INVALID_ARGUMENT.

If reply_type is non-None then the reply will be checked for having this type and an error will be raised if it does not match. Said another way, if you give a reply_type then any non-None return value will be of this type. Unless it’s %G_VARIANT_TYPE_UNIT, the reply_type will be a tuple containing one or more values.

If the parameters GLib.Variant is floating, it is consumed. This allows convenient ‘inline’ use of g_variant_new(), e.g.:

g_dbus_connection_call (connection,
"org.freedesktop.StringThings",
"/org/freedesktop/StringThings",
"org.freedesktop.StringThings",
"TwoStrings",
g_variant_new ("(ss)",
               "Thing One",
               "Thing Two"),
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
(GAsyncReadyCallback) two_strings_done,
NULL);

This is an asynchronous method. When the operation is finished, callback will be invoked in the thread-default main context of the thread you are calling this method from. You can then call Gio.DBusConnection.call_finish() to get the result of the operation. See Gio.DBusConnection.call_sync() for the synchronous version of this function.

If callback is None then the D-Bus method call message will be sent with the Gio.DBusMessageFlags.NO_REPLY_EXPECTED flag set.

New in version 2.26.

call_finish(res)[source]
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult obtained from the Gio.AsyncReadyCallback passed to Gio.DBusConnection.call()

Raises:

GLib.Error

Returns:

None if error is set. Otherwise a non-floating GLib.Variant tuple with return values. Free with GLib.Variant.unref().

Return type:

GLib.Variant

Finishes an operation started with Gio.DBusConnection.call().

New in version 2.26.

call_sync(bus_name, object_path, interface_name, method_name, parameters, reply_type, flags, timeout_msec, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

None if error is set. Otherwise a non-floating GLib.Variant tuple with return values. Free with GLib.Variant.unref().

Return type:

GLib.Variant

Synchronously invokes the method_name method on the interface_name D-Bus interface on the remote object at object_path owned by bus_name.

If self is closed then the operation will fail with Gio.IOErrorEnum.CLOSED. If cancellable is canceled, the operation will fail with Gio.IOErrorEnum.CANCELLED. If parameters contains a value not compatible with the D-Bus protocol, the operation fails with Gio.IOErrorEnum.INVALID_ARGUMENT.

If reply_type is non-None then the reply will be checked for having this type and an error will be raised if it does not match. Said another way, if you give a reply_type then any non-None return value will be of this type.

If the parameters GLib.Variant is floating, it is consumed. This allows convenient ‘inline’ use of g_variant_new(), e.g.:

g_dbus_connection_call_sync (connection,
"org.freedesktop.StringThings",
"/org/freedesktop/StringThings",
"org.freedesktop.StringThings",
"TwoStrings",
g_variant_new ("(ss)",
               "Thing One",
               "Thing Two"),
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);

The calling thread is blocked until a reply is received. See Gio.DBusConnection.call() for the asynchronous version of this method.

New in version 2.26.

call_with_unix_fd_list(bus_name, object_path, interface_name, method_name, parameters, reply_type, flags, timeout_msec, fd_list, cancellable, callback, *user_data)[source]
Parameters:

Like Gio.DBusConnection.call() but also takes a Gio.UnixFDList object.

The file descriptors normally correspond to %G_VARIANT_TYPE_HANDLE values in the body of the message. For example, if a message contains two file descriptors, fd_list would have length 2, and g_variant_new_handle (0) and g_variant_new_handle (1) would appear somewhere in the body of the message (not necessarily in that order!) to represent the file descriptors at indexes 0 and 1 respectively.

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 in this way by a value of type %G_VARIANT_TYPE_HANDLE in the body of the message.

This method is only available on UNIX.

New in version 2.30.

call_with_unix_fd_list_finish(res)[source]
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult obtained from the Gio.AsyncReadyCallback passed to Gio.DBusConnection.call_with_unix_fd_list()

Raises:

GLib.Error

Returns:

None if error is set. Otherwise a non-floating GLib.Variant tuple with return values. Free with GLib.Variant.unref().

out_fd_list:

return location for a Gio.UnixFDList or None

Return type:

(GLib.Variant, out_fd_list: Gio.UnixFDList)

Finishes an operation started with Gio.DBusConnection.call_with_unix_fd_list().

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 (*out_fd_list, 5, ...).

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 in this way by a value of type %G_VARIANT_TYPE_HANDLE in the body of the message.

New in version 2.30.

call_with_unix_fd_list_sync(bus_name, object_path, interface_name, method_name, parameters, reply_type, flags, timeout_msec, fd_list, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

None if error is set. Otherwise a non-floating GLib.Variant tuple with return values. Free with GLib.Variant.unref().

out_fd_list:

return location for a Gio.UnixFDList or None

Return type:

(GLib.Variant, out_fd_list: Gio.UnixFDList)

Like Gio.DBusConnection.call_sync() but also takes and returns Gio.UnixFDList objects. See Gio.DBusConnection.call_with_unix_fd_list() and Gio.DBusConnection.call_with_unix_fd_list_finish() for more details.

This method is only available on UNIX.

New in version 2.30.

close(cancellable, callback, *user_data)[source]
Parameters:

Closes self. Note that this never causes the process to exit (this might only happen if the other end of a shared message bus connection disconnects, see Gio.DBusConnection :exit-on-close).

Once the connection is closed, operations such as sending a message will return with the error Gio.IOErrorEnum.CLOSED. Closing a connection will not automatically flush the connection so queued messages may be lost. Use Gio.DBusConnection.flush() if you need such guarantees.

If self is already closed, this method fails with Gio.IOErrorEnum.CLOSED.

When self has been closed, the Gio.DBusConnection ::closed signal is emitted in the thread-default main context of the thread that self was constructed in.

This is an asynchronous method. When the operation is finished, callback will be invoked in the thread-default main context of the thread you are calling this method from. You can then call Gio.DBusConnection.close_finish() to get the result of the operation. See Gio.DBusConnection.close_sync() for the synchronous version.

New in version 2.26.

close_finish(res)[source]
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult obtained from the Gio.AsyncReadyCallback passed to Gio.DBusConnection.close()

Raises:

GLib.Error

Returns:

True if the operation succeeded, False if error is set

Return type:

bool

Finishes an operation started with Gio.DBusConnection.close().

New in version 2.26.

close_sync(cancellable)[source]
Parameters:

cancellable (Gio.Cancellable or None) – a Gio.Cancellable or None

Raises:

GLib.Error

Returns:

True if the operation succeeded, False if error is set

Return type:

bool

Synchronously closes self. The calling thread is blocked until this is done. See Gio.DBusConnection.close() for the asynchronous version of this method and more details about what it does.

New in version 2.26.

emit_signal(destination_bus_name, object_path, interface_name, signal_name, parameters)[source]
Parameters:
  • destination_bus_name (str or None) – the unique bus name for the destination for the signal or None to emit to all listeners

  • object_path (str) – path of remote object

  • interface_name (str) – D-Bus interface to emit a signal on

  • signal_name (str) – the name of the signal to emit

  • parameters (GLib.Variant or None) – a GLib.Variant tuple with parameters for the signal or None if not passing parameters

Raises:

GLib.Error

Returns:

True unless error is set

Return type:

bool

Emits a signal.

If the parameters GLib.Variant is floating, it is consumed.

This can only fail if parameters is not compatible with the D-Bus protocol (Gio.IOErrorEnum.INVALID_ARGUMENT), or if self has been closed (Gio.IOErrorEnum.CLOSED).

New in version 2.26.

export_action_group(object_path, action_group)[source]
Parameters:
Raises:

GLib.Error

Returns:

the ID of the export (never zero), or 0 in case of failure

Return type:

int

Exports action_group on self at object_path.

The implemented D-Bus API should be considered private. It is subject to change in the future.

A given object path can only have one action group exported on it. If this constraint is violated, the export will fail and 0 will be returned (with error set accordingly).

You can unexport the action group using Gio.DBusConnection.unexport_action_group() with the return value of this function.

The thread default main context is taken at the time of this call. All incoming action activations and state change requests are reported from this context. Any changes on the action group that cause it to emit signals must also come from this same context. Since incoming action activations and state change requests are rather likely to cause changes on the action group, this effectively limits a given action group to being exported from only one main context.

New in version 2.32.

export_menu_model(object_path, menu)[source]
Parameters:
Raises:

GLib.Error

Returns:

the ID of the export (never zero), or 0 in case of failure

Return type:

int

Exports menu on self at object_path.

The implemented D-Bus API should be considered private. It is subject to change in the future.

An object path can only have one menu model exported on it. If this constraint is violated, the export will fail and 0 will be returned (with error set accordingly).

Exporting menus with sections containing more than Gio.MENU_EXPORTER_MAX_SECTION_SIZE items is not supported and results in undefined behavior.

You can unexport the menu model using Gio.DBusConnection.unexport_menu_model() with the return value of this function.

New in version 2.32.

flush(cancellable, callback, *user_data)[source]
Parameters:

Asynchronously flushes self, that is, writes all queued outgoing message to the transport and then flushes the transport (using Gio.OutputStream.flush_async()). This is useful in programs that wants to emit a D-Bus signal and then exit immediately. Without flushing the connection, there is no guaranteed that the message has been sent to the networking buffers in the OS kernel.

This is an asynchronous method. When the operation is finished, callback will be invoked in the thread-default main context of the thread you are calling this method from. You can then call Gio.DBusConnection.flush_finish() to get the result of the operation. See Gio.DBusConnection.flush_sync() for the synchronous version.

New in version 2.26.

flush_finish(res)[source]
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult obtained from the Gio.AsyncReadyCallback passed to Gio.DBusConnection.flush()

Raises:

GLib.Error

Returns:

True if the operation succeeded, False if error is set

Return type:

bool

Finishes an operation started with Gio.DBusConnection.flush().

New in version 2.26.

flush_sync(cancellable)[source]
Parameters:

cancellable (Gio.Cancellable or None) – a Gio.Cancellable or None

Raises:

GLib.Error

Returns:

True if the operation succeeded, False if error is set

Return type:

bool

Synchronously flushes self. The calling thread is blocked until this is done. See Gio.DBusConnection.flush() for the asynchronous version of this method and more details about what it does.

New in version 2.26.

get_capabilities()[source]
Returns:

zero or more flags from the Gio.DBusCapabilityFlags enumeration

Return type:

Gio.DBusCapabilityFlags

Gets the capabilities negotiated with the remote peer

New in version 2.26.

get_exit_on_close()[source]
Returns:

whether the process is terminated when self is closed by the remote peer

Return type:

bool

Gets whether the process is terminated when self is closed by the remote peer. See Gio.DBusConnection :exit-on-close for more details.

New in version 2.26.

get_flags()[source]
Returns:

zero or more flags from the Gio.DBusConnectionFlags enumeration

Return type:

Gio.DBusConnectionFlags

Gets the flags used to construct this connection

New in version 2.60.

get_guid()[source]
Returns:

The GUID. Do not free this string, it is owned by self.

Return type:

str

The GUID of the peer performing the role of server when authenticating. See Gio.DBusConnection :guid for more details.

New in version 2.26.

get_last_serial()[source]
Returns:

the last used serial or zero when no message has been sent within the current thread

Return type:

int

Retrieves the last serial number assigned to a Gio.DBusMessage on the current thread. This includes messages sent via both low-level API such as Gio.DBusConnection.send_message() as well as high-level API such as Gio.DBusConnection.emit_signal(), Gio.DBusConnection.call() or Gio.DBusProxy.call().

New in version 2.34.

get_peer_credentials()[source]
Returns:

a Gio.Credentials or None if not available. Do not free this object, it is owned by self.

Return type:

Gio.Credentials or None

Gets the credentials of the authenticated peer. This will always return None unless self acted as a server (e.g. Gio.DBusConnectionFlags.AUTHENTICATION_SERVER was passed) when set up and the client passed credentials as part of the authentication process.

In a message bus setup, the message bus is always the server and each application is a client. So this method will always return None for message bus clients.

New in version 2.26.

get_stream()[source]
Returns:

the stream used for IO

Return type:

Gio.IOStream

Gets the underlying stream used for IO.

While the Gio.DBusConnection is active, it will interact with this stream from a worker thread, so it is not safe to interact with the stream directly.

New in version 2.26.

get_unique_name()[source]
Returns:

the unique name or None if self is not a message bus connection. Do not free this string, it is owned by self.

Return type:

str or None

Gets the unique name of self as assigned by the message bus. This can also be used to figure out if self is a message bus connection.

New in version 2.26.

is_closed()[source]
Returns:

True if the connection is closed, False otherwise

Return type:

bool

Gets whether self is closed.

New in version 2.26.

register_object(object_path, interface_info, method_call_closure, get_property_closure, set_property_closure)[source]
Parameters:
Raises:

GLib.Error

Returns:

0 if error is set, otherwise a registration ID (never 0) that can be used with Gio.DBusConnection.unregister_object() .

Return type:

int

Version of Gio.DBusConnection.register_object() using closures instead of a Gio.DBusInterfaceVTable for easier binding in other languages.

New in version 2.46.

register_subtree(object_path, vtable, flags, user_data, user_data_free_func)[source]
Parameters:
Raises:

GLib.Error

Returns:

0 if error is set, otherwise a subtree registration ID (never 0) that can be used with Gio.DBusConnection.unregister_subtree()

Return type:

int

Registers a whole subtree of dynamic objects.

The enumerate and introspection functions in vtable are used to convey, to remote callers, what nodes exist in the subtree rooted by object_path.

When handling remote calls into any node in the subtree, first the enumerate function is used to check if the node exists. If the node exists or the Gio.DBusSubtreeFlags.DISPATCH_TO_UNENUMERATED_NODES flag is set the introspection function is used to check if the node supports the requested method. If so, the dispatch function is used to determine where to dispatch the call. The collected Gio.DBusInterfaceVTable and object will be used to call into the interface vtable for processing the request.

All calls into user-provided code will be invoked in the thread-default main context of the thread you are calling this method from.

If an existing subtree is already registered at object_path or then error is set to Gio.IOErrorEnum.EXISTS.

Note that it is valid to register regular objects (using Gio.DBusConnection.register_object()) in a subtree registered with Gio.DBusConnection.register_subtree() - if so, the subtree handler is tried as the last resort. One way to think about a subtree handler is to consider it a fallback handler for object paths not registered via Gio.DBusConnection.register_object() or other bindings.

Note that vtable will be copied so you cannot change it after registration.

See this server for an example of how to use this method.

New in version 2.26.

remove_filter(filter_id)[source]
Parameters:

filter_id (int) – an identifier obtained from Gio.DBusConnection.add_filter()

Removes a filter.

Note that since filters run in a different thread, there is a race condition where it is possible that the filter will be running even after calling Gio.DBusConnection.remove_filter(), so you cannot just free data that the filter might be using. Instead, you should pass a GLib.DestroyNotify to Gio.DBusConnection.add_filter(), which will be called when it is guaranteed that the data is no longer needed.

New in version 2.26.

send_message(message, flags)[source]
Parameters:
Raises:

GLib.Error

Returns:

True if the message was well-formed and queued for transmission, False if error is set

out_serial:

return location for serial number assigned to message when sending it or None

Return type:

(bool, out_serial: int)

Asynchronously sends message to the peer represented by self.

Unless flags contain the Gio.DBusSendMessageFlags.PRESERVE_SERIAL flag, the serial number will be assigned by self and set on message via Gio.DBusMessage.set_serial(). If out_serial is not None, then the serial number used will be written to this location prior to submitting the message to the underlying transport. While it has a volatile qualifier, this is a historical artifact and the argument passed to it should not be volatile.

If self is closed then the operation will fail with Gio.IOErrorEnum.CLOSED. If message is not well-formed, the operation fails with Gio.IOErrorEnum.INVALID_ARGUMENT.

See this server and client for an example of how to use this low-level API to send and receive UNIX file descriptors.

Note that message must be unlocked, unless flags contain the Gio.DBusSendMessageFlags.PRESERVE_SERIAL flag.

New in version 2.26.

send_message_with_reply(message, flags, timeout_msec, cancellable, callback, *user_data)[source]
Parameters:
Returns:

return location for serial number assigned to message when sending it or None

Return type:

out_serial: int

Asynchronously sends message to the peer represented by self.

Unless flags contain the Gio.DBusSendMessageFlags.PRESERVE_SERIAL flag, the serial number will be assigned by self and set on message via Gio.DBusMessage.set_serial(). If out_serial is not None, then the serial number used will be written to this location prior to submitting the message to the underlying transport. While it has a volatile qualifier, this is a historical artifact and the argument passed to it should not be volatile.

If self is closed then the operation will fail with Gio.IOErrorEnum.CLOSED. If cancellable is canceled, the operation will fail with Gio.IOErrorEnum.CANCELLED. If message is not well-formed, the operation fails with Gio.IOErrorEnum.INVALID_ARGUMENT.

This is an asynchronous method. When the operation is finished, callback will be invoked in the thread-default main context of the thread you are calling this method from. You can then call Gio.DBusConnection.send_message_with_reply_finish() to get the result of the operation. See Gio.DBusConnection.send_message_with_reply_sync() for the synchronous version.

Note that message must be unlocked, unless flags contain the Gio.DBusSendMessageFlags.PRESERVE_SERIAL flag.

See this server and client for an example of how to use this low-level API to send and receive UNIX file descriptors.

New in version 2.26.

send_message_with_reply_finish(res)[source]
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult obtained from the Gio.AsyncReadyCallback passed to Gio.DBusConnection.send_message_with_reply()

Raises:

GLib.Error

Returns:

a locked Gio.DBusMessage or None if error is set

Return type:

Gio.DBusMessage

Finishes an operation started with Gio.DBusConnection.send_message_with_reply().

Note that error is only set if a local in-process error occurred. That is to say that the returned Gio.DBusMessage object may be of type Gio.DBusMessageType.ERROR. Use Gio.DBusMessage.to_gerror() to transcode this to a GLib.Error.

See this server and client for an example of how to use this low-level API to send and receive UNIX file descriptors.

New in version 2.26.

send_message_with_reply_sync(message, flags, timeout_msec, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

a locked Gio.DBusMessage that is the reply to message or None if error is set

out_serial:

return location for serial number assigned to message when sending it or None

Return type:

(Gio.DBusMessage, out_serial: int)

Synchronously sends message to the peer represented by self and blocks the calling thread until a reply is received or the timeout is reached. See Gio.DBusConnection.send_message_with_reply() for the asynchronous version of this method.

Unless flags contain the Gio.DBusSendMessageFlags.PRESERVE_SERIAL flag, the serial number will be assigned by self and set on message via Gio.DBusMessage.set_serial(). If out_serial is not None, then the serial number used will be written to this location prior to submitting the message to the underlying transport. While it has a volatile qualifier, this is a historical artifact and the argument passed to it should not be volatile.

If self is closed then the operation will fail with Gio.IOErrorEnum.CLOSED. If cancellable is canceled, the operation will fail with Gio.IOErrorEnum.CANCELLED. If message is not well-formed, the operation fails with Gio.IOErrorEnum.INVALID_ARGUMENT.

Note that error is only set if a local in-process error occurred. That is to say that the returned Gio.DBusMessage object may be of type Gio.DBusMessageType.ERROR. Use Gio.DBusMessage.to_gerror() to transcode this to a GLib.Error.

See this server and client for an example of how to use this low-level API to send and receive UNIX file descriptors.

Note that message must be unlocked, unless flags contain the Gio.DBusSendMessageFlags.PRESERVE_SERIAL flag.

New in version 2.26.

set_exit_on_close(exit_on_close)[source]
Parameters:

exit_on_close (bool) – whether the process should be terminated when self is closed by the remote peer

Sets whether the process should be terminated when self is closed by the remote peer. See Gio.DBusConnection :exit-on-close for more details.

Note that this function should be used with care. Most modern UNIX desktops tie the notion of a user session with the session bus, and expect all of a user’s applications to quit when their bus connection goes away. If you are setting exit_on_close to False for the shared session bus connection, you should make sure that your application exits when the user session ends.

New in version 2.26.

signal_subscribe(sender, interface_name, member, object_path, arg0, flags, callback, *user_data)[source]
Parameters:
  • sender (str or None) – sender name to match on (unique or well-known name) or None to listen from all senders

  • interface_name (str or None) – D-Bus interface name to match on or None to match on all interfaces

  • member (str or None) – D-Bus signal name to match on or None to match on all signals

  • object_path (str or None) – object path to match on or None to match on all object paths

  • arg0 (str or None) – contents of first string argument to match on or None to match on all kinds of arguments

  • flags (Gio.DBusSignalFlags) – Gio.DBusSignalFlags describing how arg0 is used in subscribing to the signal

  • callback (Gio.DBusSignalCallback) – callback to invoke when there is a signal matching the requested data

  • user_data (object or None) – user data to pass to callback

Returns:

a subscription identifier that can be used with Gio.DBusConnection.signal_unsubscribe()

Return type:

int

Subscribes to signals on self and invokes callback whenever the signal is received. Note that callback will be invoked in the thread-default main context of the thread you are calling this method from.

If self is not a message bus connection, sender must be None.

If sender is a well-known name note that callback is invoked with the unique name for the owner of sender, not the well-known name as one would expect. This is because the message bus rewrites the name. As such, to avoid certain race conditions, users should be tracking the name owner of the well-known name and use that when processing the received signal.

If one of Gio.DBusSignalFlags.MATCH_ARG0_NAMESPACE or Gio.DBusSignalFlags.MATCH_ARG0_PATH are given, arg0 is interpreted as part of a namespace or path. The first argument of a signal is matched against that part as specified by D-Bus.

If user_data_free_func is non-None, it will be called (in the thread-default main context of the thread you are calling this method from) at some point after user_data is no longer needed. (It is not guaranteed to be called synchronously when the signal is unsubscribed from, and may be called after self has been destroyed.)

As callback is potentially invoked in a different thread from where it’s emitted, it’s possible for this to happen after Gio.DBusConnection.signal_unsubscribe() has been called in another thread. Due to this, user_data should have a strong reference which is freed with user_data_free_func, rather than pointing to data whose lifecycle is tied to the signal subscription. For example, if a GObject.Object is used to store the subscription ID from Gio.DBusConnection.signal_subscribe(), a strong reference to that GObject.Object must be passed to user_data, and GObject.Object.unref() passed to user_data_free_func. You are responsible for breaking the resulting reference count cycle by explicitly unsubscribing from the signal when dropping the last external reference to the GObject.Object. Alternatively, a weak reference may be used.

It is guaranteed that if you unsubscribe from a signal using Gio.DBusConnection.signal_unsubscribe() from the same thread which made the corresponding Gio.DBusConnection.signal_subscribe() call, callback will not be invoked after Gio.DBusConnection.signal_unsubscribe() returns.

The returned subscription identifier is an opaque value which is guaranteed to never be zero.

This function can never fail.

New in version 2.26.

signal_unsubscribe(subscription_id)[source]
Parameters:

subscription_id (int) – a subscription id obtained from Gio.DBusConnection.signal_subscribe()

Unsubscribes from signals.

Note that there may still be D-Bus traffic to process (relating to this signal subscription) in the current thread-default GLib.MainContext after this function has returned. You should continue to iterate the GLib.MainContext until the GLib.DestroyNotify function passed to Gio.DBusConnection.signal_subscribe() is called, in order to avoid memory leaks through callbacks queued on the GLib.MainContext after it’s stopped being iterated. Alternatively, any idle source with a priority lower than GLib.PRIORITY_DEFAULT that was scheduled after unsubscription, also indicates that all resources of this subscription are released.

New in version 2.26.

start_message_processing()[source]

If self was created with Gio.DBusConnectionFlags.DELAY_MESSAGE_PROCESSING, this method starts processing messages. Does nothing on if self wasn’t created with this flag or if the method has already been called.

New in version 2.26.

unexport_action_group(export_id)[source]
Parameters:

export_id (int) – the ID from Gio.DBusConnection.export_action_group()

Reverses the effect of a previous call to Gio.DBusConnection.export_action_group().

It is an error to call this function with an ID that wasn’t returned from Gio.DBusConnection.export_action_group() or to call it with the same ID more than once.

New in version 2.32.

unexport_menu_model(export_id)[source]
Parameters:

export_id (int) – the ID from Gio.DBusConnection.export_menu_model()

Reverses the effect of a previous call to Gio.DBusConnection.export_menu_model().

It is an error to call this function with an ID that wasn’t returned from Gio.DBusConnection.export_menu_model() or to call it with the same ID more than once.

New in version 2.32.

unregister_object(registration_id)[source]
Parameters:

registration_id (int) – a registration id obtained from Gio.DBusConnection.register_object()

Returns:

True if the object was unregistered, False otherwise

Return type:

bool

Unregisters an object.

New in version 2.26.

unregister_subtree(registration_id)[source]
Parameters:

registration_id (int) – a subtree registration id obtained from Gio.DBusConnection.register_subtree()

Returns:

True if the subtree was unregistered, False otherwise

Return type:

bool

Unregisters a subtree.

New in version 2.26.

Signal Details

Gio.DBusConnection.signals.closed(d_bus_connection, remote_peer_vanished, error)
Signal Name:

closed

Flags:

RUN_LAST

Parameters:
  • d_bus_connection (Gio.DBusConnection) – The object which received the signal

  • remote_peer_vanished (bool) – True if connection is closed because the remote peer closed its end of the connection

  • error (GLib.Error or None) – a GLib.Error with more details about the event or None

Emitted when the connection is closed.

The cause of this event can be

  • If Gio.DBusConnection.close() is called. In this case remote_peer_vanished is set to False and error is None.

  • If the remote peer closes the connection. In this case remote_peer_vanished is set to True and error is set.

  • If the remote peer sends invalid or malformed data. In this case remote_peer_vanished is set to False and error is set.

Upon receiving this signal, you should give up your reference to connection. You are guaranteed that this signal is emitted only once.

New in version 2.26.

Property Details

Gio.DBusConnection.props.address
Name:

address

Type:

str

Default Value:

None

Flags:

WRITABLE, CONSTRUCT_ONLY

A D-Bus address specifying potential endpoints that can be used when establishing the connection.

New in version 2.26.

Gio.DBusConnection.props.authentication_observer
Name:

authentication-observer

Type:

Gio.DBusAuthObserver

Default Value:

None

Flags:

WRITABLE, CONSTRUCT_ONLY

A Gio.DBusAuthObserver object to assist in the authentication process or None.

New in version 2.26.

Gio.DBusConnection.props.capabilities
Name:

capabilities

Type:

Gio.DBusCapabilityFlags

Default Value:

Gio.DBusCapabilityFlags.NONE

Flags:

READABLE

Flags from the Gio.DBusCapabilityFlags enumeration representing connection features negotiated with the other peer.

New in version 2.26.

Gio.DBusConnection.props.closed
Name:

closed

Type:

bool

Default Value:

False

Flags:

READABLE

A boolean specifying whether the connection has been closed.

New in version 2.26.

Gio.DBusConnection.props.exit_on_close
Name:

exit-on-close

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

A boolean specifying whether the process will be terminated (by calling raise(SIGTERM)) if the connection is closed by the remote peer.

Note that Gio.DBusConnection objects returned by Gio.bus_get_finish() and Gio.bus_get_sync() will (usually) have this property set to True.

New in version 2.26.

Gio.DBusConnection.props.flags
Name:

flags

Type:

Gio.DBusConnectionFlags

Default Value:

Gio.DBusConnectionFlags.NONE

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

Flags from the Gio.DBusConnectionFlags enumeration.

New in version 2.26.

Gio.DBusConnection.props.guid
Name:

guid

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The GUID of the peer performing the role of server when authenticating.

If you are constructing a Gio.DBusConnection and pass Gio.DBusConnectionFlags.AUTHENTICATION_SERVER in the Gio.DBusConnection :flags property then you **must** also set this property to a valid guid.

If you are constructing a Gio.DBusConnection and pass Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT in the Gio.DBusConnection :flags property you will be able to read the GUID of the other peer here after the connection has been successfully initialized.

Note that the D-Bus specification uses the term ‘UUID’ to refer to this, whereas GLib consistently uses the term ‘GUID’ for historical reasons.

Despite its name, the format of Gio.DBusConnection :guid does not follow RFC 4122 or the Microsoft GUID format.

New in version 2.26.

Gio.DBusConnection.props.stream
Name:

stream

Type:

Gio.IOStream

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The underlying Gio.IOStream used for I/O.

If this is passed on construction and is a Gio.SocketConnection, then the corresponding Gio.Socket will be put into non-blocking mode.

While the Gio.DBusConnection is active, it will interact with this stream from a worker thread, so it is not safe to interact with the stream directly.

New in version 2.26.

Gio.DBusConnection.props.unique_name
Name:

unique-name

Type:

str

Default Value:

None

Flags:

READABLE

The unique name as assigned by the message bus or None if the connection is not open or not a message bus connection.

New in version 2.26.