## Creating proxies for well-known names

dbus-glib lets you create proxy objects for well-known names, like the following example:

    1
    2
    3
    4
    proxy = dbus_g_proxy_new_for_name (system_bus_connection,
                                       "org.freedesktop.Accounts",
                                       "/org/freedesktop/Accounts",
                                       "org.freedesktop.Accounts");

For a DBusGProxy constructed like this, method calls will be sent to the current owner of the name, and that owner can change over time.

The same can be achieved with GDBusProxy:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    error = NULL;
    proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
                                           G_DBUS_PROXY_FLAGS_NONE,
                                           NULL, /* GDBusInterfaceInfo */
                                           "org.freedesktop.Accounts",
                                           "/org/freedesktop/Accounts",
                                           "org.freedesktop.Accounts",
                                           NULL, /* GCancellable */
                                           &error);

For an added layer of safety, you can specify what D-Bus interface the proxy is expected to conform to by using the GDBusInterfaceInfo type. Additionally, GDBusProxy loads, caches and tracks changes to the D-Bus properties on the remote object. It also sets up match rules so D-Bus signals from the remote object are delivered locally.

The GDBusProxy type normally isn't used directly - instead proxies subclassing GDBusProxy generated by gdbus-codegen is used, see the section called “Using gdbus-codegen”