DBusConnection


Object Hierarchy:

GLib.DBusConnection GLib.DBusConnection GLib.DBusConnection GLib.Object GLib.Object GLib.Object->GLib.DBusConnection GLib.AsyncInitable GLib.AsyncInitable GLib.AsyncInitable->GLib.DBusConnection GLib.Initable GLib.Initable GLib.Initable->GLib.DBusConnection

Description:

[ CCode ( type_id = "g_dbus_connection_get_type ()" ) ]
[ Version ( since = "2.26" ) ]
public class DBusConnection : Object, AsyncInitable, Initable

The DBusConnection 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 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 g_bus_own_name, g_bus_watch_name or create_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, DBusConnection's methods may be called from any thread. This is so that @get and get_sync can safely return the same DBusConnection when called from any thread.

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

If you construct an uninitialized DBusConnection, such as via @new, you must initialize it via init or init_async before using its methods or properties. Calling methods or accessing properties on a DBusConnection that has not completed initialization successfully is considered to be invalid, and leads to undefined behaviour. In particular, if initialization fails with a Error, the only valid thing you can do with that DBusConnection is to free it with unref.

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

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

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

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

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

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

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

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

Example: Using extra D-Bus hooks with a GLib.Application::

public class MyApplication : Application {
private MyApplication () {
Object (application_id: "org.example.application", flags: 0);
set_inactivity_timeout (10000);
}

public override void activate () {
// NOTE: when doing a longer-lasting action here that returns
// to the mainloop, you should use g_application_hold() and
// g_application_release() to keep the application alive until
// the action is completed.
print ("Activated\n");
}

public override bool dbus_register (DBusConnection connection, string object_path) throws Error {
// We must chain up to the parent class:
base.dbus_register (connection, object_path);

// Now we can do our own stuff here. For example, we could export some D-Bus objects
return true;
}

public override void dbus_unregister (DBusConnection connection, string object_path) {
// Do our own stuff here, e.g. unexport any D-Bus objects we exported in the dbus_register
// hook above. Be sure to check that we actually did export them, since the hook
// above might have returned early due to the parent class' hook returning false!

base.dbus_unregister (connection, object_path);
}

public static int main (string[] args) {
MyApplication app = new MyApplication ();
int status = app.run (args);
return status;
}
}

valac --pkg gio-2.0 GLib.Application.3.vala

Namespace: GLib
Package: gio-2.0

Content:

Properties:

Static methods:

Creation methods:

Methods:

Signals:

Inherited Members:

All known members inherited from class GLib.Object
All known members inherited from interface GLib.AsyncInitable
All known members inherited from interface GLib.Initable



2022 vala-language.org