DBusConnection
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
Here is an example for exporting a #GObject: gdbus-example-export.c
Skipped during bindings generation
parameter
out_fd_list
: out_fd_list: Out parameter is not supportedparameter
out_fd_list
: out_fd_list: Out parameter is not supportedmethod
register_object
: g_dbus_connection_register_object is shadowedBy register_object_with_closuresparameter
user_data
: gpointerparameter
out_serial
: out_serial: Out parameter is not supportedparameter
out_serial
: out_serial: Out parameter is not supportedparameter
out_serial
: out_serial: Out parameter is not supportedmethod
address
: Property has no getter nor settermethod
authentication-observer
: Property has no getter nor settermethod
closed
: Property has no getter nor setter
Since
2.26
Constructors
Finishes an operation started with g_dbus_connection_new().
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.
Synchronously sets up a D-Bus connection for exchanging D-Bus messages with the end represented by @stream.
Properties
Flags from the #GDBusCapabilityFlags enumeration representing connection features negotiated with the other peer.
A boolean specifying whether the process will be terminated (by calling raise(SIGTERM)
) if the connection is closed by the remote peer.
Flags from the #GDBusConnectionFlags enumeration.
The unique name as assigned by the message bus or null if the connection is not open or not a message bus connection.
Functions
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.
Asynchronously invokes the @method_name method on the
Finishes an operation started with g_dbus_connection_call().
Synchronously invokes the @method_name method on the
Like g_dbus_connection_call() but also takes a #GUnixFDList object.
Closes @connection. 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 #GDBusConnection:exit-on-close).
Finishes an operation started with g_dbus_connection_close().
Synchronously closes @connection. The calling thread is blocked until this is done. See g_dbus_connection_close() for the asynchronous version of this method and more details about what it does.
Emitted when the connection is closed.
Exports @action_group on @connection at @object_path.
Exports @menu on @connection at @object_path.
Asynchronously flushes @connection, that is, writes all queued outgoing message to the transport and then flushes the transport (using g_output_stream_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.
Finishes an operation started with g_dbus_connection_flush().
Synchronously flushes @connection. The calling thread is blocked until this is done. See g_dbus_connection_flush() for the asynchronous version of this method and more details about what it does.
Gets the capabilities negotiated with the remote peer
Gets whether the process is terminated when @connection is closed by the remote peer. See #GDBusConnection:exit-on-close for more details.
Gets the flags used to construct this connection
Retrieves the last serial number assigned to a #GDBusMessage on the current thread. This includes messages sent via both low-level API such as g_dbus_connection_send_message() as well as high-level API such as g_dbus_connection_emit_signal(), g_dbus_connection_call() or g_dbus_proxy_call().
Gets the credentials of the authenticated peer. This will always return null unless @connection acted as a server (e.g. %G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_SERVER was passed) when set up and the client passed credentials as part of the authentication process.
Gets the unique name of @connection as assigned by the message bus. This can also be used to figure out if @connection is a message bus connection.
Initializes the object implementing the interface.
Starts asynchronous initialization of the object implementing the interface. This must be done before any real use of the object after initial construction. If the object also implements #GInitable you can optionally call g_initable_init() instead.
Finishes asynchronous initialization and returns the result. See g_async_initable_init_async().
Finishes the async construction for the various g_async_initable_new calls, returning the created object or null on error.
Version of g_dbus_connection_register_object() using closures instead of a #GDBusInterfaceVTable for easier binding in other languages.
Removes a filter.
Finishes an operation started with g_dbus_connection_send_message_with_reply().
Sets whether the process should be terminated when @connection is closed by the remote peer. See #GDBusConnection:exit-on-close for more details.
Subscribes to signals on @connection and invokes @callback whenever the signal is received. Note that @callback will be invoked in the g-main-context-push-thread-default of the thread you are calling this method from.
Unsubscribes from signals.
If @connection was created with %G_DBUS_CONNECTION_FLAGS_DELAY_MESSAGE_PROCESSING, this method starts processing messages. Does nothing on if @connection wasn't created with this flag or if the method has already been called.
Reverses the effect of a previous call to method@Gio.DBusConnection.export_action_group.
Reverses the effect of a previous call to g_dbus_connection_export_menu_model().
Unregisters an object.
Unregisters a subtree.