GDBusProxy

GDBusProxy — Client-side proxies

Synopsis


#include <gio/gio.h>

enum                GDBusProxyFlags;
                    GDBusProxy;
                    GDBusProxyClass;
void                g_dbus_proxy_new                    (GDBusConnection *connection,
                                                         GDBusProxyFlags flags,
                                                         GDBusInterfaceInfo *info,
                                                         const gchar *name,
                                                         const gchar *object_path,
                                                         const gchar *interface_name,
                                                         GCancellable *cancellable,
                                                         GAsyncReadyCallback callback,
                                                         gpointer user_data);
GDBusProxy *        g_dbus_proxy_new_finish             (GAsyncResult *res,
                                                         GError **error);
GDBusProxy *        g_dbus_proxy_new_sync               (GDBusConnection *connection,
                                                         GDBusProxyFlags flags,
                                                         GDBusInterfaceInfo *info,
                                                         const gchar *name,
                                                         const gchar *object_path,
                                                         const gchar *interface_name,
                                                         GCancellable *cancellable,
                                                         GError **error);
void                g_dbus_proxy_new_for_bus            (GBusType bus_type,
                                                         GDBusProxyFlags flags,
                                                         GDBusInterfaceInfo *info,
                                                         const gchar *name,
                                                         const gchar *object_path,
                                                         const gchar *interface_name,
                                                         GCancellable *cancellable,
                                                         GAsyncReadyCallback callback,
                                                         gpointer user_data);
GDBusProxy *        g_dbus_proxy_new_for_bus_finish     (GAsyncResult *res,
                                                         GError **error);
GDBusProxy *        g_dbus_proxy_new_for_bus_sync       (GBusType bus_type,
                                                         GDBusProxyFlags flags,
                                                         GDBusInterfaceInfo *info,
                                                         const gchar *name,
                                                         const gchar *object_path,
                                                         const gchar *interface_name,
                                                         GCancellable *cancellable,
                                                         GError **error);
GDBusProxyFlags     g_dbus_proxy_get_flags              (GDBusProxy *proxy);
GDBusConnection *   g_dbus_proxy_get_connection         (GDBusProxy *proxy);
const gchar *       g_dbus_proxy_get_name               (GDBusProxy *proxy);
gchar *             g_dbus_proxy_get_name_owner         (GDBusProxy *proxy);
const gchar *       g_dbus_proxy_get_object_path        (GDBusProxy *proxy);
const gchar *       g_dbus_proxy_get_interface_name     (GDBusProxy *proxy);
gint                g_dbus_proxy_get_default_timeout    (GDBusProxy *proxy);
void                g_dbus_proxy_set_default_timeout    (GDBusProxy *proxy,
                                                         gint timeout_msec);
GVariant *          g_dbus_proxy_get_cached_property    (GDBusProxy *proxy,
                                                         const gchar *property_name);
void                g_dbus_proxy_set_cached_property    (GDBusProxy *proxy,
                                                         const gchar *property_name,
                                                         GVariant *value);
gchar **            g_dbus_proxy_get_cached_property_names
                                                        (GDBusProxy *proxy);
void                g_dbus_proxy_set_interface_info     (GDBusProxy *proxy,
                                                         GDBusInterfaceInfo *info);
GDBusInterfaceInfo * g_dbus_proxy_get_interface_info    (GDBusProxy *proxy);
void                g_dbus_proxy_call                   (GDBusProxy *proxy,
                                                         const gchar *method_name,
                                                         GVariant *parameters,
                                                         GDBusCallFlags flags,
                                                         gint timeout_msec,
                                                         GCancellable *cancellable,
                                                         GAsyncReadyCallback callback,
                                                         gpointer user_data);
GVariant *          g_dbus_proxy_call_finish            (GDBusProxy *proxy,
                                                         GAsyncResult *res,
                                                         GError **error);
GVariant *          g_dbus_proxy_call_sync              (GDBusProxy *proxy,
                                                         const gchar *method_name,
                                                         GVariant *parameters,
                                                         GDBusCallFlags flags,
                                                         gint timeout_msec,
                                                         GCancellable *cancellable,
                                                         GError **error);

Description

GDBusProxy is a base class used for proxies to access a D-Bus interface on a remote object. A GDBusProxy can be constructed for both well-known and unique names.

By default, GDBusProxy will cache all properties (and listen to changes) of the remote object, and proxy all signals that gets emitted. This behaviour can be changed by passing suitable GDBusProxyFlags when the proxy is created. If the proxy is for a well-known name, the property cache is flushed when the name owner vanishes and reloaded when a name owner appears.

If a GDBusProxy is used for a well-known name, the owner of the name is tracked and can be read from "g-name-owner". Connect to the "notify" signal to get notified of changes. Additionally, only signals and property changes emitted from the current name owner are considered and calls are always sent to the current name owner. This avoids a number of race conditions when the name is lost by one owner and claimed by another. However, if no name owner currently exists, then calls will be sent to the well-known name which may result in the message bus launching an owner (unless G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START is set).

The generic "g-properties-changed" and "g-signal" signals are not very convenient to work with. Therefore, the recommended way of working with proxies is to subclass GDBusProxy, and have more natural properties and signals in your derived class.

A GDBusProxy instance can be used from multiple threads but note that all signals (e.g. "g-signal", "g-properties" and "notify") are emitted in the thread-default main loop of the thread where the instance was constructed.

See Example 17, “GDBusProxy subclass example” for an example.

Example 10. GDBusProxy for a well-known-name

#include <gio/gio.h>

static gchar *opt_name         = NULL;
static gchar *opt_object_path  = NULL;
static gchar *opt_interface    = NULL;
static gboolean opt_system_bus = FALSE;
static gboolean opt_no_auto_start = FALSE;
static gboolean opt_no_properties = FALSE;

static GOptionEntry opt_entries[] =
{
  { "name", 'n', 0, G_OPTION_ARG_STRING, &opt_name, "Name of the remote object to watch", NULL },
  { "object-path", 'o', 0, G_OPTION_ARG_STRING, &opt_object_path, "Object path of the remote object", NULL },
  { "interface", 'i', 0, G_OPTION_ARG_STRING, &opt_interface, "D-Bus interface of remote object", NULL },
  { "system-bus", 's', 0, G_OPTION_ARG_NONE, &opt_system_bus, "Use the system-bus instead of the session-bus", NULL },
  { "no-auto-start", 'a', 0, G_OPTION_ARG_NONE, &opt_no_auto_start, "Don't instruct the bus to launch an owner for the name", NULL},
  { "no-properties", 'p', 0, G_OPTION_ARG_NONE, &opt_no_properties, "Do not load properties", NULL},
  { NULL}
};

static GMainLoop *loop = NULL;

static void
print_properties (GDBusProxy *proxy)
{
  gchar **property_names;
  guint n;

  g_print ("    properties:\n");

  property_names = g_dbus_proxy_get_cached_property_names (proxy);
  for (n = 0; property_names != NULL && property_names[n] != NULL; n++)
    {
      const gchar *key = property_names[n];
      GVariant *value;
      gchar *value_str;
      value = g_dbus_proxy_get_cached_property (proxy, key);
      value_str = g_variant_print (value, TRUE);
      g_print ("      %s -> %s\n", key, value_str);
      g_variant_unref (value);
      g_free (value_str);
    }
  g_strfreev (property_names);
}

static void
on_properties_changed (GDBusProxy          *proxy,
                       GVariant            *changed_properties,
                       const gchar* const  *invalidated_properties,
                       gpointer             user_data)
{
  /* Note that we are guaranteed that changed_properties and
   * invalidated_properties are never NULL
   */

  if (g_variant_n_children (changed_properties) > 0)
    {
      GVariantIter *iter;
      const gchar *key;
      GVariant *value;

      g_print (" *** Properties Changed:\n");
      g_variant_get (changed_properties,
                     "a{sv}",
                     &iter);
      while (g_variant_iter_loop (iter, "{&sv}", &key, &value))
        {
          gchar *value_str;
          value_str = g_variant_print (value, TRUE);
          g_print ("      %s -> %s\n", key, value_str);
          g_free (value_str);
        }
      g_variant_iter_free (iter);
    }

  if (g_strv_length ((GStrv) invalidated_properties) > 0)
    {
      guint n;
      g_print (" *** Properties Invalidated:\n");
      for (n = 0; invalidated_properties[n] != NULL; n++)
        {
          const gchar *key = invalidated_properties[n];
          g_print ("      %s\n", key);
        }
    }
}

static void
on_signal (GDBusProxy *proxy,
           gchar      *sender_name,
           gchar      *signal_name,
           GVariant   *parameters,
           gpointer    user_data)
{
  gchar *parameters_str;

  parameters_str = g_variant_print (parameters, TRUE);
  g_print (" *** Received Signal: %s: %s\n",
           signal_name,
           parameters_str);
  g_free (parameters_str);
}

static void
print_proxy (GDBusProxy *proxy)
{
  gchar *name_owner;

  name_owner = g_dbus_proxy_get_name_owner (proxy);
  if (name_owner != NULL)
    {
      g_print ("+++ Proxy object points to remote object owned by %s\n"
               "    bus:          %s\n"
               "    name:         %s\n"
               "    object path:  %s\n"
               "    interface:    %s\n",
               name_owner,
               opt_system_bus ? "System Bus" : "Session Bus",
               opt_name,
               opt_object_path,
               opt_interface);
      print_properties (proxy);
    }
  else
    {
      g_print ("--- Proxy object is inert - there is no name owner for the name\n"
               "    bus:          %s\n"
               "    name:         %s\n"
               "    object path:  %s\n"
               "    interface:    %s\n",
               opt_system_bus ? "System Bus" : "Session Bus",
               opt_name,
               opt_object_path,
               opt_interface);
    }
  g_free (name_owner);
}

static void
on_name_owner_notify (GObject    *object,
                      GParamSpec *pspec,
                      gpointer    user_data)
{
  GDBusProxy *proxy = G_DBUS_PROXY (object);
  print_proxy (proxy);
}

int
main (int argc, char *argv[])
{
  GOptionContext *opt_context;
  GError *error;
  GDBusProxyFlags flags;
  GDBusProxy *proxy;

  g_type_init ();

  loop = NULL;
  proxy = NULL;

  opt_context = g_option_context_new ("g_bus_watch_proxy() example");
  g_option_context_set_summary (opt_context,
                                "Example: to watch the object of gdbus-example-server, use:\n"
                                "\n"
                                "  ./gdbus-example-watch-proxy -n org.gtk.GDBus.TestServer  \\\n"
                                "                              -o /org/gtk/GDBus/TestObject \\\n"
                                "                              -i org.gtk.GDBus.TestInterface");
  g_option_context_add_main_entries (opt_context, opt_entries, NULL);
  error = NULL;
  if (!g_option_context_parse (opt_context, &argc, &argv, &error))
    {
      g_printerr ("Error parsing options: %s\n", error->message);
      goto out;
    }
  if (opt_name == NULL || opt_object_path == NULL || opt_interface == NULL)
    {
      g_printerr ("Incorrect usage, try --help.\n");
      goto out;
    }

  flags = G_DBUS_PROXY_FLAGS_NONE;
  if (opt_no_properties)
    flags |= G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES;
  if (opt_no_auto_start)
    flags |= G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START;

  loop = g_main_loop_new (NULL, FALSE);

  error = NULL;
  proxy = g_dbus_proxy_new_for_bus_sync (opt_system_bus ? G_BUS_TYPE_SYSTEM : G_BUS_TYPE_SESSION,
                                         flags,
                                         NULL, /* GDBusInterfaceInfo */
                                         opt_name,
                                         opt_object_path,
                                         opt_interface,
                                         NULL, /* GCancellable */
                                         &error);
  if (proxy == NULL)
    {
      g_printerr ("Error creating proxy: %s\n", error->message);
      g_error_free (error);
      goto out;
    }

  g_signal_connect (proxy,
                    "g-properties-changed",
                    G_CALLBACK (on_properties_changed),
                    NULL);
  g_signal_connect (proxy,
                    "g-signal",
                    G_CALLBACK (on_signal),
                    NULL);
  g_signal_connect (proxy,
                    "notify::g-name-owner",
                    G_CALLBACK (on_name_owner_notify),
                    NULL);
  print_proxy (proxy);

  g_main_loop_run (loop);

 out:
  if (proxy != NULL)
    g_object_unref (proxy);
  if (loop != NULL)
    g_main_loop_unref (loop);
  g_option_context_free (opt_context);
  g_free (opt_name);
  g_free (opt_object_path);
  g_free (opt_interface);

  return 0;
}


Details

enum GDBusProxyFlags

typedef enum
{
  G_DBUS_PROXY_FLAGS_NONE = 0,
  G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES = (1<<0),
  G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS = (1<<1),
  G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START = (1<<2)
} GDBusProxyFlags;

Flags used when constructing an instance of a GDBusProxy derived class.

G_DBUS_PROXY_FLAGS_NONE

No flags set.

G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES

Don't load properties.

G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS

Don't connect to signals on the remote object.

G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START

If not set and the proxy if for a well-known name, then request the bus to launch an owner for the name if no-one owns the name. This flag can only be used in proxies for well-known names.

Since 2.26


GDBusProxy

typedef struct {
} GDBusProxy;

The GDBusProxy structure contains only private data and should only be accessed using the provided API.

Since 2.26


GDBusProxyClass

typedef struct {
  /* Signals */
  void (*g_properties_changed) (GDBusProxy          *proxy,
                                GVariant            *changed_properties,
                                const gchar* const  *invalidated_properties);
  void (*g_signal)             (GDBusProxy          *proxy,
                                const gchar         *sender_name,
                                const gchar         *signal_name,
                                GVariant            *parameters);
} GDBusProxyClass;

Class structure for GDBusProxy.

g_properties_changed ()

Signal class handler for the "g-properties-changed" signal.

g_signal ()

Signal class handler for the "g-signal" signal.

Since 2.26


g_dbus_proxy_new ()

void                g_dbus_proxy_new                    (GDBusConnection *connection,
                                                         GDBusProxyFlags flags,
                                                         GDBusInterfaceInfo *info,
                                                         const gchar *name,
                                                         const gchar *object_path,
                                                         const gchar *interface_name,
                                                         GCancellable *cancellable,
                                                         GAsyncReadyCallback callback,
                                                         gpointer user_data);

Creates a proxy for accessing interface_name on the remote object at object_path owned by name at connection and asynchronously loads D-Bus properties unless the G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES flag is used. Connect to the "g-properties-changed" signal to get notified about property changes.

If the G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS flag is not set, also sets up match rules for signals. Connect to the "g-signal" signal to handle signals from the remote object.

If name is a well-known name and the G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START flag isn't set and no name owner currently exists, the message bus will be requested to launch a name owner for the name.

This is a failable asynchronous constructor - when the proxy is ready, callback will be invoked and you can use g_dbus_proxy_new_finish() to get the result.

See g_dbus_proxy_new_sync() and for a synchronous version of this constructor.

See Example 10, “GDBusProxy for a well-known-name” for an example of how GDBusProxy can be used.

connection :

A GDBusConnection.

flags :

Flags used when constructing the proxy.

info :

A GDBusInterfaceInfo specifying the minimal interface that proxy conforms to or NULL.. allow-none.

name :

A bus name (well-known or unique) or NULL if connection is not a message bus connection.. allow-none.

object_path :

An object path.

interface_name :

A D-Bus interface name.

cancellable :

A GCancellable or NULL.

callback :

Callback function to invoke when the proxy is ready.

user_data :

User data to pass to callback.

Since 2.26


g_dbus_proxy_new_finish ()

GDBusProxy *        g_dbus_proxy_new_finish             (GAsyncResult *res,
                                                         GError **error);

Finishes creating a GDBusProxy.

res :

A GAsyncResult obtained from the GAsyncReadyCallback function passed to g_dbus_proxy_new().

error :

Return location for error or NULL.

Returns :

A GDBusProxy or NULL if error is set. Free with g_object_unref().

Since 2.26


g_dbus_proxy_new_sync ()

GDBusProxy *        g_dbus_proxy_new_sync               (GDBusConnection *connection,
                                                         GDBusProxyFlags flags,
                                                         GDBusInterfaceInfo *info,
                                                         const gchar *name,
                                                         const gchar *object_path,
                                                         const gchar *interface_name,
                                                         GCancellable *cancellable,
                                                         GError **error);

Creates a proxy for accessing interface_name on the remote object at object_path owned by name at connection and synchronously loads D-Bus properties unless the G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES flag is used.

If the G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS flag is not set, also sets up match rules for signals. Connect to the "g-signal" signal to handle signals from the remote object.

If name is a well-known name and the G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START flag isn't set and no name owner currently exists, the message bus will be requested to launch a name owner for the name.

This is a synchronous failable constructor. See g_dbus_proxy_new() and g_dbus_proxy_new_finish() for the asynchronous version.

See Example 10, “GDBusProxy for a well-known-name” for an example of how GDBusProxy can be used.

connection :

A GDBusConnection.

flags :

Flags used when constructing the proxy.

info :

A GDBusInterfaceInfo specifying the minimal interface that proxy conforms to or NULL.. allow-none.

name :

A bus name (well-known or unique) or NULL if connection is not a message bus connection.. allow-none.

object_path :

An object path.

interface_name :

A D-Bus interface name.

cancellable :

A GCancellable or NULL.. allow-none.

error :

Return location for error or NULL.. allow-none.

Returns :

A GDBusProxy or NULL if error is set. Free with g_object_unref().

Since 2.26


g_dbus_proxy_new_for_bus ()

void                g_dbus_proxy_new_for_bus            (GBusType bus_type,
                                                         GDBusProxyFlags flags,
                                                         GDBusInterfaceInfo *info,
                                                         const gchar *name,
                                                         const gchar *object_path,
                                                         const gchar *interface_name,
                                                         GCancellable *cancellable,
                                                         GAsyncReadyCallback callback,
                                                         gpointer user_data);

Like g_dbus_proxy_new() but takes a GBusType instead of a GDBusConnection.

See Example 10, “GDBusProxy for a well-known-name” for an example of how GDBusProxy can be used.

bus_type :

A GBusType.

flags :

Flags used when constructing the proxy.

info :

A GDBusInterfaceInfo specifying the minimal interface that proxy conforms to or NULL.. allow-none.

name :

A bus name (well-known or unique).

object_path :

An object path.

interface_name :

A D-Bus interface name.

cancellable :

A GCancellable or NULL.

callback :

Callback function to invoke when the proxy is ready.

user_data :

User data to pass to callback.

Since 2.26


g_dbus_proxy_new_for_bus_finish ()

GDBusProxy *        g_dbus_proxy_new_for_bus_finish     (GAsyncResult *res,
                                                         GError **error);

Finishes creating a GDBusProxy.

res :

A GAsyncResult obtained from the GAsyncReadyCallback function passed to g_dbus_proxy_new_for_bus().

error :

Return location for error or NULL.

Returns :

A GDBusProxy or NULL if error is set. Free with g_object_unref().

Since 2.26


g_dbus_proxy_new_for_bus_sync ()

GDBusProxy *        g_dbus_proxy_new_for_bus_sync       (GBusType bus_type,
                                                         GDBusProxyFlags flags,
                                                         GDBusInterfaceInfo *info,
                                                         const gchar *name,
                                                         const gchar *object_path,
                                                         const gchar *interface_name,
                                                         GCancellable *cancellable,
                                                         GError **error);

Like g_dbus_proxy_new_sync() but takes a GBusType instead of a GDBusConnection.

See Example 10, “GDBusProxy for a well-known-name” for an example of how GDBusProxy can be used.

bus_type :

A GBusType.

flags :

Flags used when constructing the proxy.

info :

allow-none. allow-none.

name :

A bus name (well-known or unique).

object_path :

An object path.

interface_name :

A D-Bus interface name.

cancellable :

A GCancellable or NULL.

error :

Return location for error or NULL.

Returns :

A GDBusProxy or NULL if error is set. Free with g_object_unref().

Since 2.26


g_dbus_proxy_get_flags ()

GDBusProxyFlags     g_dbus_proxy_get_flags              (GDBusProxy *proxy);

Gets the flags that proxy was constructed with.

proxy :

A GDBusProxy.

Returns :

Flags from the GDBusProxyFlags enumeration.

Since 2.26


g_dbus_proxy_get_connection ()

GDBusConnection *   g_dbus_proxy_get_connection         (GDBusProxy *proxy);

Gets the connection proxy is for.

proxy :

A GDBusProxy.

Returns :

A GDBusConnection owned by proxy. Do not free.. transfer none.

Since 2.26


g_dbus_proxy_get_name ()

const gchar *       g_dbus_proxy_get_name               (GDBusProxy *proxy);

Gets the name that proxy was constructed for.

proxy :

A GDBusProxy.

Returns :

A string owned by proxy. Do not free.

Since 2.26


g_dbus_proxy_get_name_owner ()

gchar *             g_dbus_proxy_get_name_owner         (GDBusProxy *proxy);

The unique name that owns the name that proxy is for or NULL if no-one currently owns that name. You may connect to the "notify" signal to track changes to the "g-name-owner" property.

proxy :

A GDBusProxy.

Returns :

The name owner or NULL if no name owner exists. Free with g_free().

Since 2.26


g_dbus_proxy_get_object_path ()

const gchar *       g_dbus_proxy_get_object_path        (GDBusProxy *proxy);

Gets the object path proxy is for.

proxy :

A GDBusProxy.

Returns :

A string owned by proxy. Do not free.

Since 2.26


g_dbus_proxy_get_interface_name ()

const gchar *       g_dbus_proxy_get_interface_name     (GDBusProxy *proxy);

Gets the D-Bus interface name proxy is for.

proxy :

A GDBusProxy.

Returns :

A string owned by proxy. Do not free.

Since 2.26


g_dbus_proxy_get_default_timeout ()

gint                g_dbus_proxy_get_default_timeout    (GDBusProxy *proxy);

Gets the timeout to use if -1 (specifying default timeout) is passed as timeout_msec in the g_dbus_proxy_call() and g_dbus_proxy_call_sync() functions.

See the "g-default-timeout" property for more details.

proxy :

A GDBusProxy.

Returns :

Timeout to use for proxy.

Since 2.26


g_dbus_proxy_set_default_timeout ()

void                g_dbus_proxy_set_default_timeout    (GDBusProxy *proxy,
                                                         gint timeout_msec);

Sets the timeout to use if -1 (specifying default timeout) is passed as timeout_msec in the g_dbus_proxy_call() and g_dbus_proxy_call_sync() functions.

See the "g-default-timeout" property for more details.

proxy :

A GDBusProxy.

timeout_msec :

Timeout in milliseconds.

Since 2.26


g_dbus_proxy_get_cached_property ()

GVariant *          g_dbus_proxy_get_cached_property    (GDBusProxy *proxy,
                                                         const gchar *property_name);

Looks up the value for a property from the cache. This call does no blocking IO.

If proxy has an expected interface (see "g-interface-info"), then property_name (for existence) is checked against it.

proxy :

A GDBusProxy.

property_name :

Property name.

Returns :

A reference to the GVariant instance that holds the value for property_name or NULL if the value is not in the cache. The returned reference must be freed with g_variant_unref().

Since 2.26


g_dbus_proxy_set_cached_property ()

void                g_dbus_proxy_set_cached_property    (GDBusProxy *proxy,
                                                         const gchar *property_name,
                                                         GVariant *value);

If value is not NULL, sets the cached value for the property with name property_name to the value in value.

If value is NULL, then the cached value is removed from the property cache.

If proxy has an expected interface (see "g-interface-info"), then property_name (for existence) and value (for the type) is checked against it.

If the value GVariant is floating, it is consumed. This allows convenient 'inline' use of g_variant_new(), e.g.

 g_dbus_proxy_set_cached_property (proxy,
                                   "SomeProperty",
                                   g_variant_new ("(si)",
                                                 "A String",
                                                 42));

Normally you will not need to use this method since proxy is tracking changes using the org.freedesktop.DBus.Properties.PropertiesChanged D-Bus signal. However, for performance reasons an object may decide to not use this signal for some properties and instead use a proprietary out-of-band mechanism to transmit changes.

As a concrete example, consider an object with a property ChatroomParticipants which is an array of strings. Instead of transmitting the same (long) array every time the property changes, it is more efficient to only transmit the delta using e.g. signals ChatroomParticipantJoined(String name) and ChatroomParticipantParted(String name).

proxy :

A GDBusProxy

property_name :

Property name.

value :

Value for the property or NULL to remove it from the cache.. allow-none.

Since 2.26


g_dbus_proxy_get_cached_property_names ()

gchar **            g_dbus_proxy_get_cached_property_names
                                                        (GDBusProxy *proxy);

Gets the names of all cached properties on proxy.

proxy :

A GDBusProxy.

Returns :

A NULL-terminated array of strings or NULL if proxy has no cached properties. Free the returned array with g_strfreev().

Since 2.26


g_dbus_proxy_set_interface_info ()

void                g_dbus_proxy_set_interface_info     (GDBusProxy *proxy,
                                                         GDBusInterfaceInfo *info);

Ensure that interactions with proxy conform to the given interface. For example, when completing a method call, if the type signature of the message isn't what's expected, the given GError is set. Signals that have a type signature mismatch are simply dropped.

See the "g-interface-info" property for more details.

proxy :

A GDBusProxy

info :

Minimum interface this proxy conforms to or NULL to unset.. allow-none.

Since 2.26


g_dbus_proxy_get_interface_info ()

GDBusInterfaceInfo * g_dbus_proxy_get_interface_info    (GDBusProxy *proxy);

Returns the GDBusInterfaceInfo, if any, specifying the minimal interface that proxy conforms to.

See the "g-interface-info" property for more details.

proxy :

A GDBusProxy

Returns :

A GDBusInterfaceInfo or NULL. Do not unref the returned object, it is owned by proxy.

Since 2.26


g_dbus_proxy_call ()

void                g_dbus_proxy_call                   (GDBusProxy *proxy,
                                                         const gchar *method_name,
                                                         GVariant *parameters,
                                                         GDBusCallFlags flags,
                                                         gint timeout_msec,
                                                         GCancellable *cancellable,
                                                         GAsyncReadyCallback callback,
                                                         gpointer user_data);

Asynchronously invokes the method_name method on proxy.

If method_name contains any dots, then name is split into interface and method name parts. This allows using proxy for invoking methods on other interfaces.

If the GDBusConnection associated with proxy is closed then the operation will fail with G_IO_ERROR_CLOSED. If cancellable is canceled, the operation will fail with G_IO_ERROR_CANCELLED. If parameters contains a value not compatible with the D-Bus protocol, the operation fails with G_IO_ERROR_INVALID_ARGUMENT.

If the parameters GVariant is floating, it is consumed. This allows convenient 'inline' use of g_variant_new(), e.g.:

 g_dbus_proxy_call (proxy,
                    "TwoStrings",
                    g_variant_new ("(ss)",
                                   "Thing One",
                                   "Thing Two"),
                    G_DBUS_CALL_FLAGS_NONE,
                    -1,
                    NULL,
                    (GAsyncReadyCallback) two_strings_done,
                    &data);

This is an asynchronous method. When the operation is finished, callback will be invoked in the thread-default main loop of the thread you are calling this method from. You can then call g_dbus_proxy_call_finish() to get the result of the operation. See g_dbus_proxy_call_sync() for the synchronous version of this method.

proxy :

A GDBusProxy.

method_name :

Name of method to invoke.

parameters :

A GVariant tuple with parameters for the signal or NULL if not passing parameters.. allow-none.

flags :

Flags from the GDBusCallFlags enumeration.

timeout_msec :

The timeout in milliseconds (with G_MAXINT meaning "infinite") or -1 to use the proxy default timeout.

cancellable :

A GCancellable or NULL.

callback :

A GAsyncReadyCallback to call when the request is satisfied or NULL if you don't care about the result of the method invocation.

user_data :

The data to pass to callback.

Since 2.26


g_dbus_proxy_call_finish ()

GVariant *          g_dbus_proxy_call_finish            (GDBusProxy *proxy,
                                                         GAsyncResult *res,
                                                         GError **error);

Finishes an operation started with g_dbus_proxy_call().

proxy :

A GDBusProxy.

res :

A GAsyncResult obtained from the GAsyncReadyCallback passed to g_dbus_proxy_call().

error :

Return location for error or NULL.

Returns :

NULL if error is set. Otherwise a GVariant tuple with return values. Free with g_variant_unref().

Since 2.26


g_dbus_proxy_call_sync ()

GVariant *          g_dbus_proxy_call_sync              (GDBusProxy *proxy,
                                                         const gchar *method_name,
                                                         GVariant *parameters,
                                                         GDBusCallFlags flags,
                                                         gint timeout_msec,
                                                         GCancellable *cancellable,
                                                         GError **error);

Synchronously invokes the method_name method on proxy.

If method_name contains any dots, then name is split into interface and method name parts. This allows using proxy for invoking methods on other interfaces.

If the GDBusConnection associated with proxy is disconnected then the operation will fail with G_IO_ERROR_CLOSED. If cancellable is canceled, the operation will fail with G_IO_ERROR_CANCELLED. If parameters contains a value not compatible with the D-Bus protocol, the operation fails with G_IO_ERROR_INVALID_ARGUMENT.

If the parameters GVariant is floating, it is consumed. This allows convenient 'inline' use of g_variant_new(), e.g.:

 g_dbus_proxy_call_sync (proxy,
                         "TwoStrings",
                         g_variant_new ("(ss)",
                                        "Thing One",
                                        "Thing Two"),
                         G_DBUS_CALL_FLAGS_NONE,
                         -1,
                         NULL,
                         &error);

The calling thread is blocked until a reply is received. See g_dbus_proxy_call() for the asynchronous version of this method.

proxy :

A GDBusProxy.

method_name :

Name of method to invoke.

parameters :

allow-none. allow-none.

flags :

Flags from the GDBusCallFlags enumeration.

timeout_msec :

The timeout in milliseconds (with G_MAXINT meaning "infinite") or -1 to use the proxy default timeout.

cancellable :

A GCancellable or NULL.

error :

Return location for error or NULL.

Returns :

NULL if error is set. Otherwise a GVariant tuple with return values. Free with g_variant_unref().

Since 2.26