Gio.DBusConnection¶
- Subclasses:
None
Methods¶
- Inherited:
GObject.Object (37), Gio.AsyncInitable (4), Gio.Initable (2)
- Structs:
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Properties¶
Name |
Type |
Flags |
Short Description |
---|---|---|---|
w/co |
|||
w/co |
|||
r |
|||
r |
|||
r/w |
|||
r/w/co |
|||
r/w/co |
|||
r/w/co |
|||
r |
Signals¶
- Inherited:
Name |
Short Description |
---|---|
Emitted when the connection is closed. |
Fields¶
- Inherited:
Class Details¶
- class Gio.DBusConnection(**kwargs)¶
- Bases:
- 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 aGDBusConnection
that has not completed initialization successfully is considered to be invalid, and leads to undefined behaviour. In particular, if initialization fails with aGError
, the only valid thing you can do with thatGDBusConnection
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.cNew in version 2.26.
- classmethod new(stream, guid, flags, observer, cancellable, callback, *user_data)[source]¶
- Parameters:
stream (
Gio.IOStream
) – aGio.IOStream
guid (
str
orNone
) – the GUID to use if authenticating as a server orNone
flags (
Gio.DBusConnectionFlags
) – flags describing how to make the connectionobserver (
Gio.DBusAuthObserver
orNone
) – aGio.DBusAuthObserver
orNone
cancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
orNone
callback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfied
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 correspondingGio.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
) – aGio.AsyncResult
obtained from theGio.AsyncReadyCallback
passed toGio.DBusConnection.new
().- Raises:
- Returns:
a
Gio.DBusConnection
orNone
if error is set. Free withGObject.Object.unref
().- Return type:
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:
address (
str
) – a D-Bus addressflags (
Gio.DBusConnectionFlags
) – flags describing how to make the connectionobserver (
Gio.DBusAuthObserver
orNone
) – aGio.DBusAuthObserver
orNone
cancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
orNone
callback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfied
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 theGio.DBusConnectionFlags.AUTHENTICATION_SERVER
,Gio.DBusConnectionFlags.AUTHENTICATION_ALLOW_ANONYMOUS
orGio.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
) – aGio.AsyncResult
obtained from theGio.AsyncReadyCallback
passed toGio.DBusConnection.new
()- Raises:
- Returns:
a
Gio.DBusConnection
orNone
if error is set. Free withGObject.Object.unref
().- Return type:
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:
address (
str
) – a D-Bus addressflags (
Gio.DBusConnectionFlags
) – flags describing how to make the connectionobserver (
Gio.DBusAuthObserver
orNone
) – aGio.DBusAuthObserver
orNone
cancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
orNone
- Raises:
- Returns:
a
Gio.DBusConnection
orNone
if error is set. Free withGObject.Object.unref
().- Return type:
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 theGio.DBusConnectionFlags.AUTHENTICATION_SERVER
,Gio.DBusConnectionFlags.AUTHENTICATION_ALLOW_ANONYMOUS
orGio.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:
stream (
Gio.IOStream
) – aGio.IOStream
guid (
str
orNone
) – the GUID to use if authenticating as a server orNone
flags (
Gio.DBusConnectionFlags
) – flags describing how to make the connectionobserver (
Gio.DBusAuthObserver
orNone
) – aGio.DBusAuthObserver
orNone
cancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
orNone
- Raises:
- Returns:
a
Gio.DBusConnection
orNone
if error is set. Free withGObject.Object.unref
().- Return type:
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 correspondingGio.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:
filter_function (
Gio.DBusMessageFilterFunction
) – a filter functionuser_data (
object
orNone
) – user data to pass to filter_function
- Returns:
a filter identifier that can be used with
Gio.DBusConnection.remove_filter
()- Return type:
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
() orGio.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
() andGio.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:
bus_name (
str
orNone
) – a unique or well-known bus name orNone
if self is not a message bus connectionobject_path (
str
) – path of remote objectinterface_name (
str
) – D-Bus interface to invoke method onmethod_name (
str
) – the name of the method to invokeparameters (
GLib.Variant
orNone
) – aGLib.Variant
tuple with parameters for the method orNone
if not passing parametersreply_type (
GLib.VariantType
orNone
) – the expected type of the reply (which will be a tuple), orNone
flags (
Gio.DBusCallFlags
) – flags from theGio.DBusCallFlags
enumerationtimeout_msec (
int
) – the timeout in milliseconds, -1 to use the default timeout orGObject.G_MAXINT
for no timeoutcancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
orNone
callback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfied orNone
if you don’t care about the result of the method invocation
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 withGio.IOErrorEnum.CANCELLED
. If parameters contains a value not compatible with the D-Bus protocol, the operation fails withGio.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 callGio.DBusConnection.call_finish
() to get the result of the operation. SeeGio.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 theGio.DBusMessageFlags.NO_REPLY_EXPECTED
flag set.New in version 2.26.
- call_finish(res)[source]¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
obtained from theGio.AsyncReadyCallback
passed toGio.DBusConnection.call
()- Raises:
- Returns:
None
if error is set. Otherwise a non-floatingGLib.Variant
tuple with return values. Free withGLib.Variant.unref
().- Return type:
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:
bus_name (
str
orNone
) – a unique or well-known bus name orNone
if self is not a message bus connectionobject_path (
str
) – path of remote objectinterface_name (
str
) – D-Bus interface to invoke method onmethod_name (
str
) – the name of the method to invokeparameters (
GLib.Variant
orNone
) – aGLib.Variant
tuple with parameters for the method orNone
if not passing parametersreply_type (
GLib.VariantType
orNone
) – the expected type of the reply, orNone
flags (
Gio.DBusCallFlags
) – flags from theGio.DBusCallFlags
enumerationtimeout_msec (
int
) – the timeout in milliseconds, -1 to use the default timeout orGObject.G_MAXINT
for no timeoutcancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
orNone
- Raises:
- Returns:
None
if error is set. Otherwise a non-floatingGLib.Variant
tuple with return values. Free withGLib.Variant.unref
().- Return type:
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 withGio.IOErrorEnum.CANCELLED
. If parameters contains a value not compatible with the D-Bus protocol, the operation fails withGio.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:
bus_name (
str
orNone
) – a unique or well-known bus name orNone
if self is not a message bus connectionobject_path (
str
) – path of remote objectinterface_name (
str
) – D-Bus interface to invoke method onmethod_name (
str
) – the name of the method to invokeparameters (
GLib.Variant
orNone
) – aGLib.Variant
tuple with parameters for the method orNone
if not passing parametersreply_type (
GLib.VariantType
orNone
) – the expected type of the reply, orNone
flags (
Gio.DBusCallFlags
) – flags from theGio.DBusCallFlags
enumerationtimeout_msec (
int
) – the timeout in milliseconds, -1 to use the default timeout orGObject.G_MAXINT
for no timeoutfd_list (
Gio.UnixFDList
orNone
) – aGio.UnixFDList
orNone
cancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
orNone
callback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfied orNone
if you don’t * care about the result of the method invocation
Like
Gio.DBusConnection.call
() but also takes aGio.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)
andg_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
) – aGio.AsyncResult
obtained from theGio.AsyncReadyCallback
passed toGio.DBusConnection.call_with_unix_fd_list
()- Raises:
- Returns:
None
if error is set. Otherwise a non-floatingGLib.Variant
tuple with return values. Free withGLib.Variant.unref
().- out_fd_list:
return location for a
Gio.UnixFDList
orNone
- 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 byg_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:
bus_name (
str
orNone
) – a unique or well-known bus name orNone
if self is not a message bus connectionobject_path (
str
) – path of remote objectinterface_name (
str
) – D-Bus interface to invoke method onmethod_name (
str
) – the name of the method to invokeparameters (
GLib.Variant
orNone
) – aGLib.Variant
tuple with parameters for the method orNone
if not passing parametersreply_type (
GLib.VariantType
orNone
) – the expected type of the reply, orNone
flags (
Gio.DBusCallFlags
) – flags from theGio.DBusCallFlags
enumerationtimeout_msec (
int
) – the timeout in milliseconds, -1 to use the default timeout orGObject.G_MAXINT
for no timeoutfd_list (
Gio.UnixFDList
orNone
) – aGio.UnixFDList
orNone
cancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
orNone
- Raises:
- Returns:
None
if error is set. Otherwise a non-floatingGLib.Variant
tuple with return values. Free withGLib.Variant.unref
().- out_fd_list:
return location for a
Gio.UnixFDList
orNone
- Return type:
(
GLib.Variant
, out_fd_list:Gio.UnixFDList
)
Like
Gio.DBusConnection.call_sync
() but also takes and returnsGio.UnixFDList
objects. SeeGio.DBusConnection.call_with_unix_fd_list
() andGio.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:
cancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
orNone
callback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfied orNone
if you don’t care about the result
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. UseGio.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 thethread-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 callGio.DBusConnection.close_finish
() to get the result of the operation. SeeGio.DBusConnection.close_sync
() for the synchronous version.New in version 2.26.
- close_finish(res)[source]¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
obtained from theGio.AsyncReadyCallback
passed toGio.DBusConnection.close
()- Raises:
- Returns:
- Return type:
Finishes an operation started with
Gio.DBusConnection.close
().New in version 2.26.
- close_sync(cancellable)[source]¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
orNone
- Raises:
- Returns:
- Return type:
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
orNone
) – the unique bus name for the destination for the signal orNone
to emit to all listenersobject_path (
str
) – path of remote objectinterface_name (
str
) – D-Bus interface to emit a signal onsignal_name (
str
) – the name of the signal to emitparameters (
GLib.Variant
orNone
) – aGLib.Variant
tuple with parameters for the signal orNone
if not passing parameters
- Raises:
- Returns:
True
unless error is set- Return type:
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:
object_path (
str
) – a D-Bus object pathaction_group (
Gio.ActionGroup
) – aGio.ActionGroup
- Raises:
- Returns:
the ID of the export (never zero), or 0 in case of failure
- Return type:
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.
- Parameters:
object_path (
str
) – a D-Bus object pathmenu (
Gio.MenuModel
) – aGio.MenuModel
- Raises:
- Returns:
the ID of the export (never zero), or 0 in case of failure
- Return type:
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:
cancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
orNone
callback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfied orNone
if you don’t care about the result
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 callGio.DBusConnection.flush_finish
() to get the result of the operation. SeeGio.DBusConnection.flush_sync
() for the synchronous version.New in version 2.26.
- flush_finish(res)[source]¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
obtained from theGio.AsyncReadyCallback
passed toGio.DBusConnection.flush
()- Raises:
- Returns:
- Return type:
Finishes an operation started with
Gio.DBusConnection.flush
().New in version 2.26.
- flush_sync(cancellable)[source]¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
orNone
- Raises:
- Returns:
- Return type:
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:
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:
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:
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:
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:
Retrieves the last serial number assigned to a
Gio.DBusMessage
on the current thread. This includes messages sent via both low-level API such asGio.DBusConnection.send_message
() as well as high-level API such asGio.DBusConnection.emit_signal
(),Gio.DBusConnection.call
() orGio.DBusProxy.call
().New in version 2.34.
- get_peer_credentials()[source]¶
- Returns:
a
Gio.Credentials
orNone
if not available. Do not free this object, it is owned by self.- Return type:
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:
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:
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.
- register_object(object_path, interface_info, method_call_closure, get_property_closure, set_property_closure)[source]¶
- Parameters:
object_path (
str
) – The object path to register at.interface_info (
Gio.DBusInterfaceInfo
) – Introspection data for the interface.method_call_closure (
GObject.Closure
orNone
) –GObject.Closure
for handling incoming method calls.get_property_closure (
GObject.Closure
orNone
) –GObject.Closure
for getting a property.set_property_closure (
GObject.Closure
orNone
) –GObject.Closure
for setting a property.
- Raises:
- Returns:
0 if error is set, otherwise a registration ID (never 0) that can be used with
Gio.DBusConnection.unregister_object
() .- Return type:
Version of
Gio.DBusConnection.register_object
() using closures instead of aGio.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:
object_path (
str
) – the object path to register the subtree atvtable (
Gio.DBusSubtreeVTable
) – aGio.DBusSubtreeVTable
to enumerate, introspect and dispatch nodes in the subtreeflags (
Gio.DBusSubtreeFlags
) – flags used to fine tune the behavior of the subtreeuser_data (
object
orNone
) – data to pass to functions in vtableuser_data_free_func (
GLib.DestroyNotify
) – function to call when the subtree is unregistered
- Raises:
- Returns:
0 if error is set, otherwise a subtree registration ID (never 0) that can be used with
Gio.DBusConnection.unregister_subtree
()- Return type:
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 collectedGio.DBusInterfaceVTable
andobject
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 withGio.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 viaGio.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 fromGio.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 aGLib.DestroyNotify
toGio.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:
message (
Gio.DBusMessage
) – aGio.DBusMessage
flags (
Gio.DBusSendMessageFlags
) – flags affecting how the message is sent
- Raises:
- 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:
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 viaGio.DBusMessage.set_serial
(). If out_serial is notNone
, then the serial number used will be written to this location prior to submitting the message to the underlying transport. While it has avolatile
qualifier, this is a historical artifact and the argument passed to it should not bevolatile
.If self is closed then the operation will fail with
Gio.IOErrorEnum.CLOSED
. If message is not well-formed, the operation fails withGio.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:
message (
Gio.DBusMessage
) – aGio.DBusMessage
flags (
Gio.DBusSendMessageFlags
) – flags affecting how the message is senttimeout_msec (
int
) – the timeout in milliseconds, -1 to use the default timeout orGObject.G_MAXINT
for no timeoutcancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
orNone
callback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfied orNone
if you don’t care about the result
- 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 viaGio.DBusMessage.set_serial
(). If out_serial is notNone
, then the serial number used will be written to this location prior to submitting the message to the underlying transport. While it has avolatile
qualifier, this is a historical artifact and the argument passed to it should not bevolatile
.If self is closed then the operation will fail with
Gio.IOErrorEnum.CLOSED
. If cancellable is canceled, the operation will fail withGio.IOErrorEnum.CANCELLED
. If message is not well-formed, the operation fails withGio.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 callGio.DBusConnection.send_message_with_reply_finish
() to get the result of the operation. SeeGio.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
) – aGio.AsyncResult
obtained from theGio.AsyncReadyCallback
passed toGio.DBusConnection.send_message_with_reply
()- Raises:
- Returns:
a locked
Gio.DBusMessage
orNone
if error is set- Return type:
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 typeGio.DBusMessageType.ERROR
. UseGio.DBusMessage.to_gerror
() to transcode this to aGLib.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:
message (
Gio.DBusMessage
) – aGio.DBusMessage
flags (
Gio.DBusSendMessageFlags
) – flags affecting how the message is sent.timeout_msec (
int
) – the timeout in milliseconds, -1 to use the default timeout orGObject.G_MAXINT
for no timeoutcancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
orNone
- Raises:
- Returns:
a locked
Gio.DBusMessage
that is the reply to message orNone
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 viaGio.DBusMessage.set_serial
(). If out_serial is notNone
, then the serial number used will be written to this location prior to submitting the message to the underlying transport. While it has avolatile
qualifier, this is a historical artifact and the argument passed to it should not bevolatile
.If self is closed then the operation will fail with
Gio.IOErrorEnum.CLOSED
. If cancellable is canceled, the operation will fail withGio.IOErrorEnum.CANCELLED
. If message is not well-formed, the operation fails withGio.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 typeGio.DBusMessageType.ERROR
. UseGio.DBusMessage.to_gerror
() to transcode this to aGLib.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
orNone
) – sender name to match on (unique or well-known name) orNone
to listen from all sendersinterface_name (
str
orNone
) – D-Bus interface name to match on orNone
to match on all interfacesmember (
str
orNone
) – D-Bus signal name to match on orNone
to match on all signalsobject_path (
str
orNone
) – object path to match on orNone
to match on all object pathsarg0 (
str
orNone
) – contents of first string argument to match on orNone
to match on all kinds of argumentsflags (
Gio.DBusSignalFlags
) –Gio.DBusSignalFlags
describing how arg0 is used in subscribing to the signalcallback (
Gio.DBusSignalCallback
) – callback to invoke when there is a signal matching the requested data
- Returns:
a subscription identifier that can be used with
Gio.DBusConnection.signal_unsubscribe
()- Return type:
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
orGio.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 aGObject.Object
is used to store the subscription ID fromGio.DBusConnection.signal_subscribe
(), a strong reference to thatGObject.Object
must be passed to user_data, andGObject.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 theGObject.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 correspondingGio.DBusConnection.signal_subscribe
() call, callback will not be invoked afterGio.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 fromGio.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 theGLib.MainContext
until theGLib.DestroyNotify
function passed toGio.DBusConnection.signal_subscribe
() is called, in order to avoid memory leaks through callbacks queued on theGLib.MainContext
after it’s stopped being iterated. Alternatively, any idle source with a priority lower thanGLib.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 fromGio.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.
- Parameters:
export_id (
int
) – the ID fromGio.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 fromGio.DBusConnection.register_object
()- Returns:
- Return type:
Unregisters an object.
New in version 2.26.
Signal Details¶
- Gio.DBusConnection.signals.closed(d_bus_connection, remote_peer_vanished, error)¶
- Signal Name:
closed
- Flags:
- Parameters:
d_bus_connection (
Gio.DBusConnection
) – The object which received the signalremote_peer_vanished (
bool
) –True
if connection is closed because the remote peer closed its end of the connectionerror (
GLib.Error
orNone
) – aGLib.Error
with more details about the event orNone
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 toFalse
and error isNone
.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:
- Default Value:
- Flags:
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:
- Default Value:
- Flags:
A
Gio.DBusAuthObserver
object to assist in the authentication process orNone
.New in version 2.26.
- Gio.DBusConnection.props.capabilities¶
- Name:
capabilities
- Type:
- Default Value:
- Flags:
Flags from the
Gio.DBusCapabilityFlags
enumeration representing connection features negotiated with the other peer.New in version 2.26.
- Gio.DBusConnection.props.closed¶
-
A boolean specifying whether the connection has been closed.
New in version 2.26.
- Gio.DBusConnection.props.exit_on_close¶
-
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 byGio.bus_get_finish
() andGio.bus_get_sync
() will (usually) have this property set toTrue
.New in version 2.26.
- Gio.DBusConnection.props.flags¶
- Name:
flags
- Type:
- Default Value:
- Flags:
Flags from the
Gio.DBusConnectionFlags
enumeration.New in version 2.26.
- Gio.DBusConnection.props.guid¶
- Name:
guid
- Type:
- Default Value:
- Flags:
The GUID of the peer performing the role of server when authenticating.
If you are constructing a
Gio.DBusConnection
and passGio.DBusConnectionFlags.AUTHENTICATION_SERVER
in theGio.DBusConnection
:flags
property then you **must** also set this property to a valid guid.If you are constructing a
Gio.DBusConnection
and passGio.DBusConnectionFlags.AUTHENTICATION_CLIENT
in theGio.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:
- Default Value:
- Flags:
The underlying
Gio.IOStream
used for I/O.If this is passed on construction and is a
Gio.SocketConnection
, then the correspondingGio.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.