Class

GioDBusConnection

Description [src]

final class Gio.DBusConnection : GObject.Object {
  /* No available fields */
}

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 GIOStream.

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 g_bus_own_name(), g_bus_watch_name() or g_dbus_proxy_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, GDBusConnections methods may be called from any thread. This is so that g_bus_get() and g_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, g_dbus_connection_new() and g_bus_get(), and the synchronous versions of those methods, give you an initialized connection. Language bindings for GIO should use g_initable_new() or g_async_initable_new_async(), which also initialize the connection.

If you construct an uninitialized GDBusConnection, such as via g_object_new(), you must initialize it via g_initable_init() or g_async_initable_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 g_object_unref().

An example D-Bus server # {#gdbus-server}

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

An example for exporting a subtree # {#gdbus-subtree-server}

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

An example for file descriptor passing # {#gdbus-unix-fd-client}

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

An example for exporting a GObject # {#gdbus-export}

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

Available since:2.26

Hierarchy

hierarchy this GDBusConnection implements_0 GAsyncInitable this--implements_0 implements_1 GInitable this--implements_1 ancestor_0 GObject ancestor_0--this

Ancestors

Constructors

g_dbus_connection_new_finish

Finishes an operation started with g_dbus_connection_new().

Available since: 2.26

g_dbus_connection_new_for_address_finish

Finishes an operation started with g_dbus_connection_new_for_address().

Available since: 2.26

g_dbus_connection_new_for_address_sync

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.

Available since: 2.26

g_dbus_connection_new_sync

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

Available since: 2.26

Functions

g_dbus_connection_new

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

Available since: 2.26

g_dbus_connection_new_for_address

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.

Available since: 2.26

Instance methods

g_dbus_connection_add_filter

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.

Available since: 2.26

g_dbus_connection_call

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

Available since: 2.26

g_dbus_connection_call_finish

Finishes an operation started with g_dbus_connection_call().

Available since: 2.26

g_dbus_connection_call_sync

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

Available since: 2.26

g_dbus_connection_call_with_unix_fd_list

Like g_dbus_connection_call() but also takes a GUnixFDList object.

Available since: 2.30

g_dbus_connection_call_with_unix_fd_list_finish

Finishes an operation started with g_dbus_connection_call_with_unix_fd_list().

Available since: 2.30

g_dbus_connection_call_with_unix_fd_list_sync

Like g_dbus_connection_call_sync() but also takes and returns GUnixFDList objects. See g_dbus_connection_call_with_unix_fd_list() and g_dbus_connection_call_with_unix_fd_list_finish() for more details.

Available since: 2.30

g_dbus_connection_close

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).

Available since: 2.26

g_dbus_connection_close_finish

Finishes an operation started with g_dbus_connection_close().

Available since: 2.26

g_dbus_connection_close_sync

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.

Available since: 2.26

g_dbus_connection_emit_signal

Emits a signal.

Available since: 2.26

g_dbus_connection_export_action_group

Exports action_group on connection at object_path.

Available since: 2.32

g_dbus_connection_export_menu_model

Exports menu on connection at object_path.

Available since: 2.32

g_dbus_connection_flush

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.

Available since: 2.26

g_dbus_connection_flush_finish

Finishes an operation started with g_dbus_connection_flush().

Available since: 2.26

g_dbus_connection_flush_sync

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.

Available since: 2.26

g_dbus_connection_get_capabilities

Gets the capabilities negotiated with the remote peer.

Available since: 2.26

g_dbus_connection_get_exit_on_close

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

Available since: 2.26

g_dbus_connection_get_flags

Gets the flags used to construct this connection.

Available since: 2.60

g_dbus_connection_get_guid

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

Available since: 2.26

g_dbus_connection_get_last_serial

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().

Available since: 2.34

g_dbus_connection_get_peer_credentials

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.

Available since: 2.26

g_dbus_connection_get_stream

Gets the underlying stream used for IO.

Available since: 2.26

g_dbus_connection_get_unique_name

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.

Available since: 2.26

g_dbus_connection_is_closed

Gets whether connection is closed.

Available since: 2.26

g_dbus_connection_register_object

Registers callbacks for exported objects at object_path with the D-Bus interface that is described in interface_info.

Available since: 2.26

g_dbus_connection_register_object_with_closures

Version of g_dbus_connection_register_object() using closures instead of a GDBusInterfaceVTable for easier binding in other languages.

Available since: 2.46

g_dbus_connection_register_subtree

Registers a whole subtree of dynamic objects.

Available since: 2.26

g_dbus_connection_remove_filter

Removes a filter.

Available since: 2.26

g_dbus_connection_send_message

Asynchronously sends message to the peer represented by connection.

Available since: 2.26

g_dbus_connection_send_message_with_reply

Asynchronously sends message to the peer represented by connection.

Available since: 2.26

g_dbus_connection_send_message_with_reply_finish

Finishes an operation started with g_dbus_connection_send_message_with_reply().

Available since: 2.26

g_dbus_connection_send_message_with_reply_sync

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

Available since: 2.26

g_dbus_connection_set_exit_on_close

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

Available since: 2.26

g_dbus_connection_signal_subscribe

Subscribes to signals on connection and invokes callback with a whenever the signal is received. Note that callback will be invoked in the [thread-default main context][g-main-context-push-thread-default] of the thread you are calling this method from.

Available since: 2.26

g_dbus_connection_signal_unsubscribe

Unsubscribes from signals.

Available since: 2.26

g_dbus_connection_start_message_processing

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.

Available since: 2.26

g_dbus_connection_unexport_action_group

Reverses the effect of a previous call to g_dbus_connection_export_action_group().

Available since: 2.32

g_dbus_connection_unexport_menu_model

Reverses the effect of a previous call to g_dbus_connection_export_menu_model().

Available since: 2.32

g_dbus_connection_unregister_object

Unregisters an object.

Available since: 2.26

g_dbus_connection_unregister_subtree

Unregisters a subtree.

Available since: 2.26

Methods inherited from GObject (43)
Methods inherited from GAsyncInitable (3)
g_async_initable_init_async

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.

Available since: 2.22

g_async_initable_init_finish

Finishes asynchronous initialization and returns the result. See g_async_initable_init_async().

Available since: 2.22

g_async_initable_new_finish

Finishes the async construction for the various g_async_initable_new calls, returning the created object or NULL on error.

Available since: 2.22

Methods inherited from GInitable (1)
g_initable_init

Initializes the object implementing the interface.

Available since: 2.22

Properties

Gio.DBusConnection:address

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

Available since: 2.26

Gio.DBusConnection:authentication-observer

A GDBusAuthObserver object to assist in the authentication process or NULL.

Available since: 2.26

Gio.DBusConnection:capabilities

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

Available since: 2.26

Gio.DBusConnection:closed

A boolean specifying whether the connection has been closed.

Available since: 2.26

Gio.DBusConnection: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.

Available since: 2.26

Gio.DBusConnection:flags

Flags from the GDBusConnectionFlags enumeration.

Available since: 2.26

Gio.DBusConnection:guid

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

Available since: 2.26

Gio.DBusConnection:stream

The underlying GIOStream used for I/O.

Available since: 2.26

Gio.DBusConnection:unique-name

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

Available since: 2.26

Signals

Gio.DBusConnection::closed

Emitted when the connection is closed.

Available since: 2.26

Signals inherited from GObject (1)