Blame gio/gdbusproxy.c

Packit ae235b
/* GDBus - GLib D-Bus Library
Packit ae235b
 *
Packit ae235b
 * Copyright (C) 2008-2010 Red Hat, Inc.
Packit ae235b
 *
Packit ae235b
 * This library is free software; you can redistribute it and/or
Packit ae235b
 * modify it under the terms of the GNU Lesser General Public
Packit ae235b
 * License as published by the Free Software Foundation; either
Packit ae235b
 * version 2.1 of the License, or (at your option) any later version.
Packit ae235b
 *
Packit ae235b
 * This library is distributed in the hope that it will be useful,
Packit ae235b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae235b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit ae235b
 * Lesser General Public License for more details.
Packit ae235b
 *
Packit ae235b
 * You should have received a copy of the GNU Lesser General
Packit ae235b
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit ae235b
 *
Packit ae235b
 * Author: David Zeuthen <davidz@redhat.com>
Packit ae235b
 */
Packit ae235b
Packit ae235b
#include "config.h"
Packit ae235b
Packit ae235b
#include <stdlib.h>
Packit ae235b
#include <string.h>
Packit ae235b
Packit ae235b
#include "gdbusutils.h"
Packit ae235b
#include "gdbusproxy.h"
Packit ae235b
#include "gioenumtypes.h"
Packit ae235b
#include "gdbusconnection.h"
Packit ae235b
#include "gdbuserror.h"
Packit ae235b
#include "gdbusprivate.h"
Packit ae235b
#include "ginitable.h"
Packit ae235b
#include "gasyncinitable.h"
Packit ae235b
#include "gioerror.h"
Packit ae235b
#include "gtask.h"
Packit ae235b
#include "gcancellable.h"
Packit ae235b
#include "gdbusinterface.h"
Packit ae235b
#include "gasyncresult.h"
Packit ae235b
Packit ae235b
#ifdef G_OS_UNIX
Packit ae235b
#include "gunixfdlist.h"
Packit ae235b
#endif
Packit ae235b
Packit ae235b
#include "glibintl.h"
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * SECTION:gdbusproxy
Packit ae235b
 * @short_description: Client-side D-Bus interface proxy
Packit ae235b
 * @include: gio/gio.h
Packit ae235b
 *
Packit ae235b
 * #GDBusProxy is a base class used for proxies to access a D-Bus
Packit ae235b
 * interface on a remote object. A #GDBusProxy can be constructed for
Packit ae235b
 * both well-known and unique names.
Packit ae235b
 *
Packit ae235b
 * By default, #GDBusProxy will cache all properties (and listen to
Packit ae235b
 * changes) of the remote object, and proxy all signals that get
Packit ae235b
 * emitted. This behaviour can be changed by passing suitable
Packit ae235b
 * #GDBusProxyFlags when the proxy is created. If the proxy is for a
Packit ae235b
 * well-known name, the property cache is flushed when the name owner
Packit ae235b
 * vanishes and reloaded when a name owner appears.
Packit ae235b
 *
Packit ae235b
 * If a #GDBusProxy is used for a well-known name, the owner of the
Packit ae235b
 * name is tracked and can be read from
Packit ae235b
 * #GDBusProxy:g-name-owner. Connect to the #GObject::notify signal to
Packit ae235b
 * get notified of changes. Additionally, only signals and property
Packit ae235b
 * changes emitted from the current name owner are considered and
Packit ae235b
 * calls are always sent to the current name owner. This avoids a
Packit ae235b
 * number of race conditions when the name is lost by one owner and
Packit ae235b
 * claimed by another. However, if no name owner currently exists,
Packit ae235b
 * then calls will be sent to the well-known name which may result in
Packit ae235b
 * the message bus launching an owner (unless
Packit ae235b
 * %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START is set).
Packit ae235b
 *
Packit ae235b
 * The generic #GDBusProxy::g-properties-changed and
Packit ae235b
 * #GDBusProxy::g-signal signals are not very convenient to work with.
Packit ae235b
 * Therefore, the recommended way of working with proxies is to subclass
Packit ae235b
 * #GDBusProxy, and have more natural properties and signals in your derived
Packit ae235b
 * class. This [example][gdbus-example-gdbus-codegen] shows how this can
Packit ae235b
 * easily be done using the [gdbus-codegen][gdbus-codegen] tool.
Packit ae235b
 *
Packit ae235b
 * A #GDBusProxy instance can be used from multiple threads but note
Packit ae235b
 * that all signals (e.g. #GDBusProxy::g-signal, #GDBusProxy::g-properties-changed
Packit ae235b
 * and #GObject::notify) are emitted in the
Packit ae235b
 * [thread-default main context][g-main-context-push-thread-default]
Packit ae235b
 * of the thread where the instance was constructed.
Packit ae235b
 *
Packit ae235b
 * An example using a proxy for a well-known name can be found in
Packit ae235b
 * [gdbus-example-watch-proxy.c](https://git.gnome.org/browse/glib/tree/gio/tests/gdbus-example-watch-proxy.c)
Packit ae235b
 */
Packit ae235b
Packit ae235b
/* lock protecting the mutable properties: name_owner, timeout_msec,
Packit ae235b
 * expected_interface, and the properties hash table
Packit ae235b
 */
Packit ae235b
G_LOCK_DEFINE_STATIC (properties_lock);
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
G_LOCK_DEFINE_STATIC (signal_subscription_lock);
Packit ae235b
Packit ae235b
typedef struct
Packit ae235b
{
Packit ae235b
  volatile gint ref_count;
Packit ae235b
  GDBusProxy *proxy;
Packit ae235b
} SignalSubscriptionData;
Packit ae235b
Packit ae235b
static SignalSubscriptionData *
Packit ae235b
signal_subscription_ref (SignalSubscriptionData *data)
Packit ae235b
{
Packit ae235b
  g_atomic_int_inc (&data->ref_count);
Packit ae235b
  return data;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
signal_subscription_unref (SignalSubscriptionData *data)
Packit ae235b
{
Packit ae235b
  if (g_atomic_int_dec_and_test (&data->ref_count))
Packit ae235b
    {
Packit ae235b
      g_slice_free (SignalSubscriptionData, data);
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
struct _GDBusProxyPrivate
Packit ae235b
{
Packit ae235b
  GBusType bus_type;
Packit ae235b
  GDBusProxyFlags flags;
Packit ae235b
  GDBusConnection *connection;
Packit ae235b
Packit ae235b
  gchar *name;
Packit ae235b
  /* mutable, protected by properties_lock */
Packit ae235b
  gchar *name_owner;
Packit ae235b
  gchar *object_path;
Packit ae235b
  gchar *interface_name;
Packit ae235b
  /* mutable, protected by properties_lock */
Packit ae235b
  gint timeout_msec;
Packit ae235b
Packit ae235b
  guint name_owner_changed_subscription_id;
Packit ae235b
Packit ae235b
  GCancellable *get_all_cancellable;
Packit ae235b
Packit ae235b
  /* gchar* -> GVariant*, protected by properties_lock */
Packit ae235b
  GHashTable *properties;
Packit ae235b
Packit ae235b
  /* mutable, protected by properties_lock */
Packit ae235b
  GDBusInterfaceInfo *expected_interface;
Packit ae235b
Packit ae235b
  guint properties_changed_subscription_id;
Packit ae235b
  guint signals_subscription_id;
Packit ae235b
Packit ae235b
  gboolean initialized;
Packit ae235b
Packit ae235b
  /* mutable, protected by properties_lock */
Packit ae235b
  GDBusObject *object;
Packit ae235b
Packit ae235b
  SignalSubscriptionData *signal_subscription_data;
Packit ae235b
};
Packit ae235b
Packit ae235b
enum
Packit ae235b
{
Packit ae235b
  PROP_0,
Packit ae235b
  PROP_G_CONNECTION,
Packit ae235b
  PROP_G_BUS_TYPE,
Packit ae235b
  PROP_G_NAME,
Packit ae235b
  PROP_G_NAME_OWNER,
Packit ae235b
  PROP_G_FLAGS,
Packit ae235b
  PROP_G_OBJECT_PATH,
Packit ae235b
  PROP_G_INTERFACE_NAME,
Packit ae235b
  PROP_G_DEFAULT_TIMEOUT,
Packit ae235b
  PROP_G_INTERFACE_INFO
Packit ae235b
};
Packit ae235b
Packit ae235b
enum
Packit ae235b
{
Packit ae235b
  PROPERTIES_CHANGED_SIGNAL,
Packit ae235b
  SIGNAL_SIGNAL,
Packit ae235b
  LAST_SIGNAL,
Packit ae235b
};
Packit ae235b
Packit ae235b
static guint signals[LAST_SIGNAL] = {0};
Packit ae235b
Packit ae235b
static void dbus_interface_iface_init (GDBusInterfaceIface *dbus_interface_iface);
Packit ae235b
static void initable_iface_init       (GInitableIface *initable_iface);
Packit ae235b
static void async_initable_iface_init (GAsyncInitableIface *async_initable_iface);
Packit ae235b
Packit ae235b
G_DEFINE_TYPE_WITH_CODE (GDBusProxy, g_dbus_proxy, G_TYPE_OBJECT,
Packit ae235b
                         G_ADD_PRIVATE (GDBusProxy)
Packit ae235b
                         G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_INTERFACE, dbus_interface_iface_init)
Packit ae235b
                         G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init)
Packit ae235b
                         G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, async_initable_iface_init))
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_dbus_proxy_dispose (GObject *object)
Packit ae235b
{
Packit ae235b
  GDBusProxy *proxy = G_DBUS_PROXY (object);
Packit ae235b
  G_LOCK (signal_subscription_lock);
Packit ae235b
  if (proxy->priv->signal_subscription_data != NULL)
Packit ae235b
    {
Packit ae235b
      proxy->priv->signal_subscription_data->proxy = NULL;
Packit ae235b
      signal_subscription_unref (proxy->priv->signal_subscription_data);
Packit ae235b
      proxy->priv->signal_subscription_data = NULL;
Packit ae235b
    }
Packit ae235b
  G_UNLOCK (signal_subscription_lock);
Packit ae235b
Packit ae235b
  G_OBJECT_CLASS (g_dbus_proxy_parent_class)->dispose (object);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_dbus_proxy_finalize (GObject *object)
Packit ae235b
{
Packit ae235b
  GDBusProxy *proxy = G_DBUS_PROXY (object);
Packit ae235b
Packit ae235b
  g_warn_if_fail (proxy->priv->get_all_cancellable == NULL);
Packit ae235b
Packit ae235b
  if (proxy->priv->name_owner_changed_subscription_id > 0)
Packit ae235b
    g_dbus_connection_signal_unsubscribe (proxy->priv->connection,
Packit ae235b
                                          proxy->priv->name_owner_changed_subscription_id);
Packit ae235b
Packit ae235b
  if (proxy->priv->properties_changed_subscription_id > 0)
Packit ae235b
    g_dbus_connection_signal_unsubscribe (proxy->priv->connection,
Packit ae235b
                                          proxy->priv->properties_changed_subscription_id);
Packit ae235b
Packit ae235b
  if (proxy->priv->signals_subscription_id > 0)
Packit ae235b
    g_dbus_connection_signal_unsubscribe (proxy->priv->connection,
Packit ae235b
                                          proxy->priv->signals_subscription_id);
Packit ae235b
Packit ae235b
  if (proxy->priv->connection != NULL)
Packit ae235b
    g_object_unref (proxy->priv->connection);
Packit ae235b
  g_free (proxy->priv->name);
Packit ae235b
  g_free (proxy->priv->name_owner);
Packit ae235b
  g_free (proxy->priv->object_path);
Packit ae235b
  g_free (proxy->priv->interface_name);
Packit ae235b
  if (proxy->priv->properties != NULL)
Packit ae235b
    g_hash_table_unref (proxy->priv->properties);
Packit ae235b
Packit ae235b
  if (proxy->priv->expected_interface != NULL)
Packit ae235b
    {
Packit ae235b
      g_dbus_interface_info_cache_release (proxy->priv->expected_interface);
Packit ae235b
      g_dbus_interface_info_unref (proxy->priv->expected_interface);
Packit ae235b
    }
Packit ae235b
Packit ae235b
  if (proxy->priv->object != NULL)
Packit ae235b
    g_object_remove_weak_pointer (G_OBJECT (proxy->priv->object), (gpointer *) &proxy->priv->object);
Packit ae235b
Packit ae235b
  G_OBJECT_CLASS (g_dbus_proxy_parent_class)->finalize (object);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_dbus_proxy_get_property (GObject    *object,
Packit ae235b
                           guint       prop_id,
Packit ae235b
                           GValue     *value,
Packit ae235b
                           GParamSpec *pspec)
Packit ae235b
{
Packit ae235b
  GDBusProxy *proxy = G_DBUS_PROXY (object);
Packit ae235b
Packit ae235b
  switch (prop_id)
Packit ae235b
    {
Packit ae235b
    case PROP_G_CONNECTION:
Packit ae235b
      g_value_set_object (value, proxy->priv->connection);
Packit ae235b
      break;
Packit ae235b
Packit ae235b
    case PROP_G_FLAGS:
Packit ae235b
      g_value_set_flags (value, proxy->priv->flags);
Packit ae235b
      break;
Packit ae235b
Packit ae235b
    case PROP_G_NAME:
Packit ae235b
      g_value_set_string (value, proxy->priv->name);
Packit ae235b
      break;
Packit ae235b
Packit ae235b
    case PROP_G_NAME_OWNER:
Packit ae235b
      g_value_take_string (value, g_dbus_proxy_get_name_owner (proxy));
Packit ae235b
      break;
Packit ae235b
Packit ae235b
    case PROP_G_OBJECT_PATH:
Packit ae235b
      g_value_set_string (value, proxy->priv->object_path);
Packit ae235b
      break;
Packit ae235b
Packit ae235b
    case PROP_G_INTERFACE_NAME:
Packit ae235b
      g_value_set_string (value, proxy->priv->interface_name);
Packit ae235b
      break;
Packit ae235b
Packit ae235b
    case PROP_G_DEFAULT_TIMEOUT:
Packit ae235b
      g_value_set_int (value, g_dbus_proxy_get_default_timeout (proxy));
Packit ae235b
      break;
Packit ae235b
Packit ae235b
    case PROP_G_INTERFACE_INFO:
Packit ae235b
      g_value_set_boxed (value, g_dbus_proxy_get_interface_info (proxy));
Packit ae235b
      break;
Packit ae235b
Packit ae235b
    default:
Packit ae235b
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
Packit ae235b
      break;
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_dbus_proxy_set_property (GObject      *object,
Packit ae235b
                           guint         prop_id,
Packit ae235b
                           const GValue *value,
Packit ae235b
                           GParamSpec   *pspec)
Packit ae235b
{
Packit ae235b
  GDBusProxy *proxy = G_DBUS_PROXY (object);
Packit ae235b
Packit ae235b
  switch (prop_id)
Packit ae235b
    {
Packit ae235b
    case PROP_G_CONNECTION:
Packit ae235b
      proxy->priv->connection = g_value_dup_object (value);
Packit ae235b
      break;
Packit ae235b
Packit ae235b
    case PROP_G_FLAGS:
Packit ae235b
      proxy->priv->flags = g_value_get_flags (value);
Packit ae235b
      break;
Packit ae235b
Packit ae235b
    case PROP_G_NAME:
Packit ae235b
      proxy->priv->name = g_value_dup_string (value);
Packit ae235b
      break;
Packit ae235b
Packit ae235b
    case PROP_G_OBJECT_PATH:
Packit ae235b
      proxy->priv->object_path = g_value_dup_string (value);
Packit ae235b
      break;
Packit ae235b
Packit ae235b
    case PROP_G_INTERFACE_NAME:
Packit ae235b
      proxy->priv->interface_name = g_value_dup_string (value);
Packit ae235b
      break;
Packit ae235b
Packit ae235b
    case PROP_G_DEFAULT_TIMEOUT:
Packit ae235b
      g_dbus_proxy_set_default_timeout (proxy, g_value_get_int (value));
Packit ae235b
      break;
Packit ae235b
Packit ae235b
    case PROP_G_INTERFACE_INFO:
Packit ae235b
      g_dbus_proxy_set_interface_info (proxy, g_value_get_boxed (value));
Packit ae235b
      break;
Packit ae235b
Packit ae235b
    case PROP_G_BUS_TYPE:
Packit ae235b
      proxy->priv->bus_type = g_value_get_enum (value);
Packit ae235b
      break;
Packit ae235b
Packit ae235b
    default:
Packit ae235b
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
Packit ae235b
      break;
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_dbus_proxy_class_init (GDBusProxyClass *klass)
Packit ae235b
{
Packit ae235b
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
Packit ae235b
Packit ae235b
  gobject_class->dispose      = g_dbus_proxy_dispose;
Packit ae235b
  gobject_class->finalize     = g_dbus_proxy_finalize;
Packit ae235b
  gobject_class->set_property = g_dbus_proxy_set_property;
Packit ae235b
  gobject_class->get_property = g_dbus_proxy_get_property;
Packit ae235b
Packit ae235b
  /* Note that all property names are prefixed to avoid collisions with D-Bus property names
Packit ae235b
   * in derived classes */
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GDBusProxy:g-interface-info:
Packit ae235b
   *
Packit ae235b
   * Ensure that interactions with this proxy conform to the given
Packit ae235b
   * interface. This is mainly to ensure that malformed data received
Packit ae235b
   * from the other peer is ignored. The given #GDBusInterfaceInfo is
Packit ae235b
   * said to be the "expected interface".
Packit ae235b
   *
Packit ae235b
   * The checks performed are:
Packit ae235b
   * - When completing a method call, if the type signature of
Packit ae235b
   *   the reply message isn't what's expected, the reply is
Packit ae235b
   *   discarded and the #GError is set to %G_IO_ERROR_INVALID_ARGUMENT.
Packit ae235b
   *
Packit ae235b
   * - Received signals that have a type signature mismatch are dropped and
Packit ae235b
   *   a warning is logged via g_warning().
Packit ae235b
   *
Packit ae235b
   * - Properties received via the initial `GetAll()` call or via the 
Packit ae235b
   *   `::PropertiesChanged` signal (on the
Packit ae235b
   *   [org.freedesktop.DBus.Properties](http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties)
Packit ae235b
   *   interface) or set using g_dbus_proxy_set_cached_property()
Packit ae235b
   *   with a type signature mismatch are ignored and a warning is
Packit ae235b
   *   logged via g_warning().
Packit ae235b
   *
Packit ae235b
   * Note that these checks are never done on methods, signals and
Packit ae235b
   * properties that are not referenced in the given
Packit ae235b
   * #GDBusInterfaceInfo, since extending a D-Bus interface on the
Packit ae235b
   * service-side is not considered an ABI break.
Packit ae235b
   *
Packit ae235b
   * Since: 2.26
Packit ae235b
   */
Packit ae235b
  g_object_class_install_property (gobject_class,
Packit ae235b
                                   PROP_G_INTERFACE_INFO,
Packit ae235b
                                   g_param_spec_boxed ("g-interface-info",
Packit ae235b
                                                       P_("Interface Information"),
Packit ae235b
                                                       P_("Interface Information"),
Packit ae235b
                                                       G_TYPE_DBUS_INTERFACE_INFO,
Packit ae235b
                                                       G_PARAM_READABLE |
Packit ae235b
                                                       G_PARAM_WRITABLE |
Packit ae235b
                                                       G_PARAM_STATIC_NAME |
Packit ae235b
                                                       G_PARAM_STATIC_BLURB |
Packit ae235b
                                                       G_PARAM_STATIC_NICK));
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GDBusProxy:g-connection:
Packit ae235b
   *
Packit ae235b
   * The #GDBusConnection the proxy is for.
Packit ae235b
   *
Packit ae235b
   * Since: 2.26
Packit ae235b
   */
Packit ae235b
  g_object_class_install_property (gobject_class,
Packit ae235b
                                   PROP_G_CONNECTION,
Packit ae235b
                                   g_param_spec_object ("g-connection",
Packit ae235b
                                                        P_("g-connection"),
Packit ae235b
                                                        P_("The connection the proxy is for"),
Packit ae235b
                                                        G_TYPE_DBUS_CONNECTION,
Packit ae235b
                                                        G_PARAM_READABLE |
Packit ae235b
                                                        G_PARAM_WRITABLE |
Packit ae235b
                                                        G_PARAM_CONSTRUCT_ONLY |
Packit ae235b
                                                        G_PARAM_STATIC_NAME |
Packit ae235b
                                                        G_PARAM_STATIC_BLURB |
Packit ae235b
                                                        G_PARAM_STATIC_NICK));
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GDBusProxy:g-bus-type:
Packit ae235b
   *
Packit ae235b
   * If this property is not %G_BUS_TYPE_NONE, then
Packit ae235b
   * #GDBusProxy:g-connection must be %NULL and will be set to the
Packit ae235b
   * #GDBusConnection obtained by calling g_bus_get() with the value
Packit ae235b
   * of this property.
Packit ae235b
   *
Packit ae235b
   * Since: 2.26
Packit ae235b
   */
Packit ae235b
  g_object_class_install_property (gobject_class,
Packit ae235b
                                   PROP_G_BUS_TYPE,
Packit ae235b
                                   g_param_spec_enum ("g-bus-type",
Packit ae235b
                                                      P_("Bus Type"),
Packit ae235b
                                                      P_("The bus to connect to, if any"),
Packit ae235b
                                                      G_TYPE_BUS_TYPE,
Packit ae235b
                                                      G_BUS_TYPE_NONE,
Packit ae235b
                                                      G_PARAM_WRITABLE |
Packit ae235b
                                                      G_PARAM_CONSTRUCT_ONLY |
Packit ae235b
                                                      G_PARAM_STATIC_NAME |
Packit ae235b
                                                      G_PARAM_STATIC_BLURB |
Packit ae235b
                                                      G_PARAM_STATIC_NICK));
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GDBusProxy:g-flags:
Packit ae235b
   *
Packit ae235b
   * Flags from the #GDBusProxyFlags enumeration.
Packit ae235b
   *
Packit ae235b
   * Since: 2.26
Packit ae235b
   */
Packit ae235b
  g_object_class_install_property (gobject_class,
Packit ae235b
                                   PROP_G_FLAGS,
Packit ae235b
                                   g_param_spec_flags ("g-flags",
Packit ae235b
                                                       P_("g-flags"),
Packit ae235b
                                                       P_("Flags for the proxy"),
Packit ae235b
                                                       G_TYPE_DBUS_PROXY_FLAGS,
Packit ae235b
                                                       G_DBUS_PROXY_FLAGS_NONE,
Packit ae235b
                                                       G_PARAM_READABLE |
Packit ae235b
                                                       G_PARAM_WRITABLE |
Packit ae235b
                                                       G_PARAM_CONSTRUCT_ONLY |
Packit ae235b
                                                       G_PARAM_STATIC_NAME |
Packit ae235b
                                                       G_PARAM_STATIC_BLURB |
Packit ae235b
                                                       G_PARAM_STATIC_NICK));
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GDBusProxy:g-name:
Packit ae235b
   *
Packit ae235b
   * The well-known or unique name that the proxy is for.
Packit ae235b
   *
Packit ae235b
   * Since: 2.26
Packit ae235b
   */
Packit ae235b
  g_object_class_install_property (gobject_class,
Packit ae235b
                                   PROP_G_NAME,
Packit ae235b
                                   g_param_spec_string ("g-name",
Packit ae235b
                                                        P_("g-name"),
Packit ae235b
                                                        P_("The well-known or unique name that the proxy is for"),
Packit ae235b
                                                        NULL,
Packit ae235b
                                                        G_PARAM_READABLE |
Packit ae235b
                                                        G_PARAM_WRITABLE |
Packit ae235b
                                                        G_PARAM_CONSTRUCT_ONLY |
Packit ae235b
                                                        G_PARAM_STATIC_NAME |
Packit ae235b
                                                        G_PARAM_STATIC_BLURB |
Packit ae235b
                                                        G_PARAM_STATIC_NICK));
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GDBusProxy:g-name-owner:
Packit ae235b
   *
Packit ae235b
   * The unique name that owns #GDBusProxy:g-name or %NULL if no-one
Packit ae235b
   * currently owns that name. You may connect to #GObject::notify signal to
Packit ae235b
   * track changes to this property.
Packit ae235b
   *
Packit ae235b
   * Since: 2.26
Packit ae235b
   */
Packit ae235b
  g_object_class_install_property (gobject_class,
Packit ae235b
                                   PROP_G_NAME_OWNER,
Packit ae235b
                                   g_param_spec_string ("g-name-owner",
Packit ae235b
                                                        P_("g-name-owner"),
Packit ae235b
                                                        P_("The unique name for the owner"),
Packit ae235b
                                                        NULL,
Packit ae235b
                                                        G_PARAM_READABLE |
Packit ae235b
                                                        G_PARAM_STATIC_NAME |
Packit ae235b
                                                        G_PARAM_STATIC_BLURB |
Packit ae235b
                                                        G_PARAM_STATIC_NICK));
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GDBusProxy:g-object-path:
Packit ae235b
   *
Packit ae235b
   * The object path the proxy is for.
Packit ae235b
   *
Packit ae235b
   * Since: 2.26
Packit ae235b
   */
Packit ae235b
  g_object_class_install_property (gobject_class,
Packit ae235b
                                   PROP_G_OBJECT_PATH,
Packit ae235b
                                   g_param_spec_string ("g-object-path",
Packit ae235b
                                                        P_("g-object-path"),
Packit ae235b
                                                        P_("The object path the proxy is for"),
Packit ae235b
                                                        NULL,
Packit ae235b
                                                        G_PARAM_READABLE |
Packit ae235b
                                                        G_PARAM_WRITABLE |
Packit ae235b
                                                        G_PARAM_CONSTRUCT_ONLY |
Packit ae235b
                                                        G_PARAM_STATIC_NAME |
Packit ae235b
                                                        G_PARAM_STATIC_BLURB |
Packit ae235b
                                                        G_PARAM_STATIC_NICK));
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GDBusProxy:g-interface-name:
Packit ae235b
   *
Packit ae235b
   * The D-Bus interface name the proxy is for.
Packit ae235b
   *
Packit ae235b
   * Since: 2.26
Packit ae235b
   */
Packit ae235b
  g_object_class_install_property (gobject_class,
Packit ae235b
                                   PROP_G_INTERFACE_NAME,
Packit ae235b
                                   g_param_spec_string ("g-interface-name",
Packit ae235b
                                                        P_("g-interface-name"),
Packit ae235b
                                                        P_("The D-Bus interface name the proxy is for"),
Packit ae235b
                                                        NULL,
Packit ae235b
                                                        G_PARAM_READABLE |
Packit ae235b
                                                        G_PARAM_WRITABLE |
Packit ae235b
                                                        G_PARAM_CONSTRUCT_ONLY |
Packit ae235b
                                                        G_PARAM_STATIC_NAME |
Packit ae235b
                                                        G_PARAM_STATIC_BLURB |
Packit ae235b
                                                        G_PARAM_STATIC_NICK));
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GDBusProxy:g-default-timeout:
Packit ae235b
   *
Packit ae235b
   * The timeout to use if -1 (specifying default timeout) is passed
Packit ae235b
   * as @timeout_msec in the g_dbus_proxy_call() and
Packit ae235b
   * g_dbus_proxy_call_sync() functions.
Packit ae235b
   *
Packit ae235b
   * This allows applications to set a proxy-wide timeout for all
Packit ae235b
   * remote method invocations on the proxy. If this property is -1,
Packit ae235b
   * the default timeout (typically 25 seconds) is used. If set to
Packit ae235b
   * %G_MAXINT, then no timeout is used.
Packit ae235b
   *
Packit ae235b
   * Since: 2.26
Packit ae235b
   */
Packit ae235b
  g_object_class_install_property (gobject_class,
Packit ae235b
                                   PROP_G_DEFAULT_TIMEOUT,
Packit ae235b
                                   g_param_spec_int ("g-default-timeout",
Packit ae235b
                                                     P_("Default Timeout"),
Packit ae235b
                                                     P_("Timeout for remote method invocation"),
Packit ae235b
                                                     -1,
Packit ae235b
                                                     G_MAXINT,
Packit ae235b
                                                     -1,
Packit ae235b
                                                     G_PARAM_READABLE |
Packit ae235b
                                                     G_PARAM_WRITABLE |
Packit ae235b
                                                     G_PARAM_CONSTRUCT |
Packit ae235b
                                                     G_PARAM_STATIC_NAME |
Packit ae235b
                                                     G_PARAM_STATIC_BLURB |
Packit ae235b
                                                     G_PARAM_STATIC_NICK));
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GDBusProxy::g-properties-changed:
Packit ae235b
   * @proxy: The #GDBusProxy emitting the signal.
Packit ae235b
   * @changed_properties: A #GVariant containing the properties that changed
Packit ae235b
   * @invalidated_properties: A %NULL terminated array of properties that was invalidated
Packit ae235b
   *
Packit ae235b
   * Emitted when one or more D-Bus properties on @proxy changes. The
Packit ae235b
   * local cache has already been updated when this signal fires. Note
Packit ae235b
   * that both @changed_properties and @invalidated_properties are
Packit ae235b
   * guaranteed to never be %NULL (either may be empty though).
Packit ae235b
   *
Packit ae235b
   * If the proxy has the flag
Packit ae235b
   * %G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES set, then
Packit ae235b
   * @invalidated_properties will always be empty.
Packit ae235b
   *
Packit ae235b
   * This signal corresponds to the
Packit ae235b
   * `PropertiesChanged` D-Bus signal on the
Packit ae235b
   * `org.freedesktop.DBus.Properties` interface.
Packit ae235b
   *
Packit ae235b
   * Since: 2.26
Packit ae235b
   */
Packit ae235b
  signals[PROPERTIES_CHANGED_SIGNAL] = g_signal_new (I_("g-properties-changed"),
Packit ae235b
                                                     G_TYPE_DBUS_PROXY,
Packit ae235b
                                                     G_SIGNAL_RUN_LAST | G_SIGNAL_MUST_COLLECT,
Packit ae235b
                                                     G_STRUCT_OFFSET (GDBusProxyClass, g_properties_changed),
Packit ae235b
                                                     NULL,
Packit ae235b
                                                     NULL,
Packit ae235b
                                                     NULL,
Packit ae235b
                                                     G_TYPE_NONE,
Packit ae235b
                                                     2,
Packit ae235b
                                                     G_TYPE_VARIANT,
Packit ae235b
                                                     G_TYPE_STRV | G_SIGNAL_TYPE_STATIC_SCOPE);
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GDBusProxy::g-signal:
Packit ae235b
   * @proxy: The #GDBusProxy emitting the signal.
Packit ae235b
   * @sender_name: (nullable): The sender of the signal or %NULL if the connection is not a bus connection.
Packit ae235b
   * @signal_name: The name of the signal.
Packit ae235b
   * @parameters: A #GVariant tuple with parameters for the signal.
Packit ae235b
   *
Packit ae235b
   * Emitted when a signal from the remote object and interface that @proxy is for, has been received.
Packit ae235b
   *
Packit ae235b
   * Since: 2.26
Packit ae235b
   */
Packit ae235b
  signals[SIGNAL_SIGNAL] = g_signal_new (I_("g-signal"),
Packit ae235b
                                         G_TYPE_DBUS_PROXY,
Packit ae235b
                                         G_SIGNAL_RUN_LAST | G_SIGNAL_MUST_COLLECT,
Packit ae235b
                                         G_STRUCT_OFFSET (GDBusProxyClass, g_signal),
Packit ae235b
                                         NULL,
Packit ae235b
                                         NULL,
Packit ae235b
                                         NULL,
Packit ae235b
                                         G_TYPE_NONE,
Packit ae235b
                                         3,
Packit ae235b
                                         G_TYPE_STRING,
Packit ae235b
                                         G_TYPE_STRING,
Packit ae235b
                                         G_TYPE_VARIANT);
Packit ae235b
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_dbus_proxy_init (GDBusProxy *proxy)
Packit ae235b
{
Packit ae235b
  proxy->priv = g_dbus_proxy_get_instance_private (proxy);
Packit ae235b
  proxy->priv->signal_subscription_data = g_slice_new0 (SignalSubscriptionData);
Packit ae235b
  proxy->priv->signal_subscription_data->ref_count = 1;
Packit ae235b
  proxy->priv->signal_subscription_data->proxy = proxy;
Packit ae235b
  proxy->priv->properties = g_hash_table_new_full (g_str_hash,
Packit ae235b
                                                   g_str_equal,
Packit ae235b
                                                   g_free,
Packit ae235b
                                                   (GDestroyNotify) g_variant_unref);
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
static gint
Packit ae235b
property_name_sort_func (const gchar **a,
Packit ae235b
                         const gchar **b)
Packit ae235b
{
Packit ae235b
  return g_strcmp0 (*a, *b);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_proxy_get_cached_property_names:
Packit ae235b
 * @proxy: A #GDBusProxy.
Packit ae235b
 *
Packit ae235b
 * Gets the names of all cached properties on @proxy.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer full) (nullable) (array zero-terminated=1): A
Packit ae235b
 *          %NULL-terminated array of strings or %NULL if
Packit ae235b
 *          @proxy has no cached properties. Free the returned array with
Packit ae235b
 *          g_strfreev().
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
gchar **
Packit ae235b
g_dbus_proxy_get_cached_property_names (GDBusProxy  *proxy)
Packit ae235b
{
Packit ae235b
  gchar **names;
Packit ae235b
  GPtrArray *p;
Packit ae235b
  GHashTableIter iter;
Packit ae235b
  const gchar *key;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
Packit ae235b
Packit ae235b
  G_LOCK (properties_lock);
Packit ae235b
Packit ae235b
  names = NULL;
Packit ae235b
  if (g_hash_table_size (proxy->priv->properties) == 0)
Packit ae235b
    goto out;
Packit ae235b
Packit ae235b
  p = g_ptr_array_new ();
Packit ae235b
Packit ae235b
  g_hash_table_iter_init (&iter, proxy->priv->properties);
Packit ae235b
  while (g_hash_table_iter_next (&iter, (gpointer) &key, NULL))
Packit ae235b
    g_ptr_array_add (p, g_strdup (key));
Packit ae235b
  g_ptr_array_sort (p, (GCompareFunc) property_name_sort_func);
Packit ae235b
  g_ptr_array_add (p, NULL);
Packit ae235b
Packit ae235b
  names = (gchar **) g_ptr_array_free (p, FALSE);
Packit ae235b
Packit ae235b
 out:
Packit ae235b
  G_UNLOCK (properties_lock);
Packit ae235b
  return names;
Packit ae235b
}
Packit ae235b
Packit ae235b
/* properties_lock must be held for as long as you will keep the
Packit ae235b
 * returned value
Packit ae235b
 */
Packit ae235b
static const GDBusPropertyInfo *
Packit ae235b
lookup_property_info (GDBusProxy  *proxy,
Packit ae235b
                      const gchar *property_name)
Packit ae235b
{
Packit ae235b
  const GDBusPropertyInfo *info = NULL;
Packit ae235b
Packit ae235b
  if (proxy->priv->expected_interface == NULL)
Packit ae235b
    goto out;
Packit ae235b
Packit ae235b
  info = g_dbus_interface_info_lookup_property (proxy->priv->expected_interface, property_name);
Packit ae235b
Packit ae235b
 out:
Packit ae235b
  return info;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_proxy_get_cached_property:
Packit ae235b
 * @proxy: A #GDBusProxy.
Packit ae235b
 * @property_name: Property name.
Packit ae235b
 *
Packit ae235b
 * Looks up the value for a property from the cache. This call does no
Packit ae235b
 * blocking IO.
Packit ae235b
 *
Packit ae235b
 * If @proxy has an expected interface (see
Packit ae235b
 * #GDBusProxy:g-interface-info) and @property_name is referenced by
Packit ae235b
 * it, then @value is checked against the type of the property.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer full) (nullable): A reference to the #GVariant instance
Packit ae235b
 *    that holds the value for @property_name or %NULL if the value is not in
Packit ae235b
 *    the cache. The returned reference must be freed with g_variant_unref().
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
GVariant *
Packit ae235b
g_dbus_proxy_get_cached_property (GDBusProxy   *proxy,
Packit ae235b
                                  const gchar  *property_name)
Packit ae235b
{
Packit ae235b
  const GDBusPropertyInfo *info;
Packit ae235b
  GVariant *value;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
Packit ae235b
  g_return_val_if_fail (property_name != NULL, NULL);
Packit ae235b
Packit ae235b
  G_LOCK (properties_lock);
Packit ae235b
Packit ae235b
  value = g_hash_table_lookup (proxy->priv->properties, property_name);
Packit ae235b
  if (value == NULL)
Packit ae235b
    goto out;
Packit ae235b
Packit ae235b
  info = lookup_property_info (proxy, property_name);
Packit ae235b
  if (info != NULL)
Packit ae235b
    {
Packit ae235b
      const gchar *type_string = g_variant_get_type_string (value);
Packit ae235b
      if (g_strcmp0 (type_string, info->signature) != 0)
Packit ae235b
        {
Packit ae235b
          g_warning ("Trying to get property %s with type %s but according to the expected "
Packit ae235b
                     "interface the type is %s",
Packit ae235b
                     property_name,
Packit ae235b
                     type_string,
Packit ae235b
                     info->signature);
Packit ae235b
          value = NULL;
Packit ae235b
          goto out;
Packit ae235b
        }
Packit ae235b
    }
Packit ae235b
Packit ae235b
  g_variant_ref (value);
Packit ae235b
Packit ae235b
 out:
Packit ae235b
  G_UNLOCK (properties_lock);
Packit ae235b
  return value;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_proxy_set_cached_property:
Packit ae235b
 * @proxy: A #GDBusProxy
Packit ae235b
 * @property_name: Property name.
Packit ae235b
 * @value: (nullable): Value for the property or %NULL to remove it from the cache.
Packit ae235b
 *
Packit ae235b
 * If @value is not %NULL, sets the cached value for the property with
Packit ae235b
 * name @property_name to the value in @value.
Packit ae235b
 *
Packit ae235b
 * If @value is %NULL, then the cached value is removed from the
Packit ae235b
 * property cache.
Packit ae235b
 *
Packit ae235b
 * If @proxy has an expected interface (see
Packit ae235b
 * #GDBusProxy:g-interface-info) and @property_name is referenced by
Packit ae235b
 * it, then @value is checked against the type of the property.
Packit ae235b
 *
Packit ae235b
 * If the @value #GVariant is floating, it is consumed. This allows
Packit ae235b
 * convenient 'inline' use of g_variant_new(), e.g.
Packit ae235b
 * |[
Packit ae235b
 *  g_dbus_proxy_set_cached_property (proxy,
Packit ae235b
 *                                    "SomeProperty",
Packit ae235b
 *                                    g_variant_new ("(si)",
Packit ae235b
 *                                                  "A String",
Packit ae235b
 *                                                  42));
Packit ae235b
 * ]|
Packit ae235b
 *
Packit ae235b
 * Normally you will not need to use this method since @proxy
Packit ae235b
 * is tracking changes using the
Packit ae235b
 * `org.freedesktop.DBus.Properties.PropertiesChanged`
Packit ae235b
 * D-Bus signal. However, for performance reasons an object may
Packit ae235b
 * decide to not use this signal for some properties and instead
Packit ae235b
 * use a proprietary out-of-band mechanism to transmit changes.
Packit ae235b
 *
Packit ae235b
 * As a concrete example, consider an object with a property
Packit ae235b
 * `ChatroomParticipants` which is an array of strings. Instead of
Packit ae235b
 * transmitting the same (long) array every time the property changes,
Packit ae235b
 * it is more efficient to only transmit the delta using e.g. signals
Packit ae235b
 * `ChatroomParticipantJoined(String name)` and
Packit ae235b
 * `ChatroomParticipantParted(String name)`.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dbus_proxy_set_cached_property (GDBusProxy   *proxy,
Packit ae235b
                                  const gchar  *property_name,
Packit ae235b
                                  GVariant     *value)
Packit ae235b
{
Packit ae235b
  const GDBusPropertyInfo *info;
Packit ae235b
Packit ae235b
  g_return_if_fail (G_IS_DBUS_PROXY (proxy));
Packit ae235b
  g_return_if_fail (property_name != NULL);
Packit ae235b
Packit ae235b
  G_LOCK (properties_lock);
Packit ae235b
Packit ae235b
  if (value != NULL)
Packit ae235b
    {
Packit ae235b
      info = lookup_property_info (proxy, property_name);
Packit ae235b
      if (info != NULL)
Packit ae235b
        {
Packit ae235b
          if (g_strcmp0 (info->signature, g_variant_get_type_string (value)) != 0)
Packit ae235b
            {
Packit ae235b
              g_warning ("Trying to set property %s of type %s but according to the expected "
Packit ae235b
			 "interface the type is %s",
Packit ae235b
                         property_name,
Packit ae235b
                         g_variant_get_type_string (value),
Packit ae235b
                         info->signature);
Packit ae235b
              goto out;
Packit ae235b
            }
Packit ae235b
        }
Packit ae235b
      g_hash_table_insert (proxy->priv->properties,
Packit ae235b
                           g_strdup (property_name),
Packit ae235b
                           g_variant_ref_sink (value));
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      g_hash_table_remove (proxy->priv->properties, property_name);
Packit ae235b
    }
Packit ae235b
Packit ae235b
 out:
Packit ae235b
  G_UNLOCK (properties_lock);
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
static void
Packit ae235b
on_signal_received (GDBusConnection *connection,
Packit ae235b
                    const gchar     *sender_name,
Packit ae235b
                    const gchar     *object_path,
Packit ae235b
                    const gchar     *interface_name,
Packit ae235b
                    const gchar     *signal_name,
Packit ae235b
                    GVariant        *parameters,
Packit ae235b
                    gpointer         user_data)
Packit ae235b
{
Packit ae235b
  SignalSubscriptionData *data = user_data;
Packit ae235b
  GDBusProxy *proxy;
Packit ae235b
Packit ae235b
  G_LOCK (signal_subscription_lock);
Packit ae235b
  proxy = data->proxy;
Packit ae235b
  if (proxy == NULL)
Packit ae235b
    {
Packit ae235b
      G_UNLOCK (signal_subscription_lock);
Packit ae235b
      return;
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      g_object_ref (proxy);
Packit ae235b
      G_UNLOCK (signal_subscription_lock);
Packit ae235b
    }
Packit ae235b
Packit ae235b
  if (!proxy->priv->initialized)
Packit ae235b
    goto out;
Packit ae235b
Packit ae235b
  G_LOCK (properties_lock);
Packit ae235b
Packit ae235b
  if (proxy->priv->name_owner != NULL && g_strcmp0 (sender_name, proxy->priv->name_owner) != 0)
Packit ae235b
    {
Packit ae235b
      G_UNLOCK (properties_lock);
Packit ae235b
      goto out;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  if (proxy->priv->expected_interface != NULL)
Packit ae235b
    {
Packit ae235b
      const GDBusSignalInfo *info;
Packit ae235b
      info = g_dbus_interface_info_lookup_signal (proxy->priv->expected_interface, signal_name);
Packit ae235b
      if (info != NULL)
Packit ae235b
        {
Packit ae235b
          GVariantType *expected_type;
Packit ae235b
          expected_type = _g_dbus_compute_complete_signature (info->args);
Packit ae235b
          if (!g_variant_type_equal (expected_type, g_variant_get_type (parameters)))
Packit ae235b
            {
Packit ae235b
              gchar *expected_type_string = g_variant_type_dup_string (expected_type);
Packit ae235b
              g_warning ("Dropping signal %s of type %s since the type from the expected interface is %s",
Packit ae235b
                         info->name,
Packit ae235b
                         g_variant_get_type_string (parameters),
Packit ae235b
                         expected_type_string);
Packit ae235b
              g_free (expected_type_string);
Packit ae235b
              g_variant_type_free (expected_type);
Packit ae235b
              G_UNLOCK (properties_lock);
Packit ae235b
              goto out;
Packit ae235b
            }
Packit ae235b
          g_variant_type_free (expected_type);
Packit ae235b
        }
Packit ae235b
    }
Packit ae235b
Packit ae235b
  G_UNLOCK (properties_lock);
Packit ae235b
Packit ae235b
  g_signal_emit (proxy,
Packit ae235b
                 signals[SIGNAL_SIGNAL],
Packit ae235b
                 0,
Packit ae235b
                 sender_name,
Packit ae235b
                 signal_name,
Packit ae235b
                 parameters);
Packit ae235b
Packit ae235b
 out:
Packit ae235b
  if (proxy != NULL)
Packit ae235b
    g_object_unref (proxy);
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
/* must hold properties_lock */
Packit ae235b
static void
Packit ae235b
insert_property_checked (GDBusProxy  *proxy,
Packit ae235b
			 gchar *property_name,
Packit ae235b
			 GVariant *value)
Packit ae235b
{
Packit ae235b
  if (proxy->priv->expected_interface != NULL)
Packit ae235b
    {
Packit ae235b
      const GDBusPropertyInfo *info;
Packit ae235b
      info = g_dbus_interface_info_lookup_property (proxy->priv->expected_interface, property_name);
Packit ae235b
      /* Only check known properties */
Packit ae235b
      if (info != NULL)
Packit ae235b
        {
Packit ae235b
          /* Warn about properties with the wrong type */
Packit ae235b
          if (g_strcmp0 (info->signature, g_variant_get_type_string (value)) != 0)
Packit ae235b
            {
Packit ae235b
              g_warning ("Received property %s with type %s does not match expected type "
Packit ae235b
                         "%s in the expected interface",
Packit ae235b
                         property_name,
Packit ae235b
                         g_variant_get_type_string (value),
Packit ae235b
                         info->signature);
Packit ae235b
              goto invalid;
Packit ae235b
            }
Packit ae235b
        }
Packit ae235b
    }
Packit ae235b
Packit ae235b
  g_hash_table_insert (proxy->priv->properties,
Packit ae235b
		       property_name, /* adopts string */
Packit ae235b
		       value); /* adopts value */
Packit ae235b
Packit ae235b
  return;
Packit ae235b
Packit ae235b
 invalid:
Packit ae235b
  g_variant_unref (value);
Packit ae235b
  g_free (property_name);
Packit ae235b
}
Packit ae235b
Packit ae235b
typedef struct
Packit ae235b
{
Packit ae235b
  GDBusProxy *proxy;
Packit ae235b
  gchar *prop_name;
Packit ae235b
} InvalidatedPropGetData;
Packit ae235b
Packit ae235b
static void
Packit ae235b
invalidated_property_get_cb (GDBusConnection *connection,
Packit ae235b
                             GAsyncResult    *res,
Packit ae235b
                             gpointer         user_data)
Packit ae235b
{
Packit ae235b
  InvalidatedPropGetData *data = user_data;
Packit ae235b
  const gchar *invalidated_properties[] = {NULL};
Packit ae235b
  GVariantBuilder builder;
Packit ae235b
  GVariant *value = NULL;
Packit ae235b
  GVariant *unpacked_value = NULL;
Packit ae235b
Packit ae235b
  /* errors are fine, the other end could have disconnected */
Packit ae235b
  value = g_dbus_connection_call_finish (connection, res, NULL);
Packit ae235b
  if (value == NULL)
Packit ae235b
    {
Packit ae235b
      goto out;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  if (!g_variant_is_of_type (value, G_VARIANT_TYPE ("(v)")))
Packit ae235b
    {
Packit ae235b
      g_warning ("Expected type '(v)' for Get() reply, got '%s'", g_variant_get_type_string (value));
Packit ae235b
      goto out;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  g_variant_get (value, "(v)", &unpacked_value);
Packit ae235b
Packit ae235b
  /* synthesize the a{sv} in the PropertiesChanged signal */
Packit ae235b
  g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
Packit ae235b
  g_variant_builder_add (&builder, "{sv}", data->prop_name, unpacked_value);
Packit ae235b
Packit ae235b
  G_LOCK (properties_lock);
Packit ae235b
  insert_property_checked (data->proxy,
Packit ae235b
                           data->prop_name,  /* adopts string */
Packit ae235b
                           unpacked_value);  /* adopts value */
Packit ae235b
  data->prop_name = NULL;
Packit ae235b
  G_UNLOCK (properties_lock);
Packit ae235b
Packit ae235b
  g_signal_emit (data->proxy,
Packit ae235b
                 signals[PROPERTIES_CHANGED_SIGNAL], 0,
Packit ae235b
                 g_variant_builder_end (&builder), /* consumed */
Packit ae235b
                 invalidated_properties);
Packit ae235b
Packit ae235b
Packit ae235b
 out:
Packit ae235b
  if (value != NULL)
Packit ae235b
    g_variant_unref (value);
Packit ae235b
  g_object_unref (data->proxy);
Packit ae235b
  g_free (data->prop_name);
Packit ae235b
  g_slice_free (InvalidatedPropGetData, data);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
on_properties_changed (GDBusConnection *connection,
Packit ae235b
                       const gchar     *sender_name,
Packit ae235b
                       const gchar     *object_path,
Packit ae235b
                       const gchar     *interface_name,
Packit ae235b
                       const gchar     *signal_name,
Packit ae235b
                       GVariant        *parameters,
Packit ae235b
                       gpointer         user_data)
Packit ae235b
{
Packit ae235b
  SignalSubscriptionData *data = user_data;
Packit ae235b
  gboolean emit_g_signal = FALSE;
Packit ae235b
  GDBusProxy *proxy;
Packit ae235b
  const gchar *interface_name_for_signal;
Packit ae235b
  GVariant *changed_properties;
Packit ae235b
  gchar **invalidated_properties;
Packit ae235b
  GVariantIter iter;
Packit ae235b
  gchar *key;
Packit ae235b
  GVariant *value;
Packit ae235b
  guint n;
Packit ae235b
Packit ae235b
  changed_properties = NULL;
Packit ae235b
  invalidated_properties = NULL;
Packit ae235b
Packit ae235b
  G_LOCK (signal_subscription_lock);
Packit ae235b
  proxy = data->proxy;
Packit ae235b
  if (proxy == NULL)
Packit ae235b
    {
Packit ae235b
      G_UNLOCK (signal_subscription_lock);
Packit ae235b
      goto out;
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      g_object_ref (proxy);
Packit ae235b
      G_UNLOCK (signal_subscription_lock);
Packit ae235b
    }
Packit ae235b
Packit ae235b
  if (!proxy->priv->initialized)
Packit ae235b
    goto out;
Packit ae235b
Packit ae235b
  G_LOCK (properties_lock);
Packit ae235b
Packit ae235b
  if (proxy->priv->name_owner != NULL && g_strcmp0 (sender_name, proxy->priv->name_owner) != 0)
Packit ae235b
    {
Packit ae235b
      G_UNLOCK (properties_lock);
Packit ae235b
      goto out;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(sa{sv}as)")))
Packit ae235b
    {
Packit ae235b
      g_warning ("Value for PropertiesChanged signal with type '%s' does not match '(sa{sv}as)'",
Packit ae235b
                 g_variant_get_type_string (parameters));
Packit ae235b
      G_UNLOCK (properties_lock);
Packit ae235b
      goto out;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  g_variant_get (parameters,
Packit ae235b
                 "(&s@a{sv}^a&s)",
Packit ae235b
                 &interface_name_for_signal,
Packit ae235b
                 &changed_properties,
Packit ae235b
                 &invalidated_properties);
Packit ae235b
Packit ae235b
  if (g_strcmp0 (interface_name_for_signal, proxy->priv->interface_name) != 0)
Packit ae235b
    {
Packit ae235b
      G_UNLOCK (properties_lock);
Packit ae235b
      goto out;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  g_variant_iter_init (&iter, changed_properties);
Packit ae235b
  while (g_variant_iter_next (&iter, "{sv}", &key, &value))
Packit ae235b
    {
Packit ae235b
      insert_property_checked (proxy,
Packit ae235b
			       key, /* adopts string */
Packit ae235b
			       value); /* adopts value */
Packit ae235b
      emit_g_signal = TRUE;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  if (proxy->priv->flags & G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES)
Packit ae235b
    {
Packit ae235b
      if (proxy->priv->name_owner != NULL)
Packit ae235b
        {
Packit ae235b
          for (n = 0; invalidated_properties[n] != NULL; n++)
Packit ae235b
            {
Packit ae235b
              InvalidatedPropGetData *data;
Packit ae235b
              data = g_slice_new0 (InvalidatedPropGetData);
Packit ae235b
              data->proxy = g_object_ref (proxy);
Packit ae235b
              data->prop_name = g_strdup (invalidated_properties[n]);
Packit ae235b
              g_dbus_connection_call (proxy->priv->connection,
Packit ae235b
                                      proxy->priv->name_owner,
Packit ae235b
                                      proxy->priv->object_path,
Packit ae235b
                                      "org.freedesktop.DBus.Properties",
Packit ae235b
                                      "Get",
Packit ae235b
                                      g_variant_new ("(ss)", proxy->priv->interface_name, data->prop_name),
Packit ae235b
                                      G_VARIANT_TYPE ("(v)"),
Packit ae235b
                                      G_DBUS_CALL_FLAGS_NONE,
Packit ae235b
                                      -1,           /* timeout */
Packit ae235b
                                      NULL,         /* GCancellable */
Packit ae235b
                                      (GAsyncReadyCallback) invalidated_property_get_cb,
Packit ae235b
                                      data);
Packit ae235b
            }
Packit ae235b
        }
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      emit_g_signal = TRUE;
Packit ae235b
      for (n = 0; invalidated_properties[n] != NULL; n++)
Packit ae235b
        {
Packit ae235b
          g_hash_table_remove (proxy->priv->properties, invalidated_properties[n]);
Packit ae235b
        }
Packit ae235b
    }
Packit ae235b
Packit ae235b
  G_UNLOCK (properties_lock);
Packit ae235b
Packit ae235b
  if (emit_g_signal)
Packit ae235b
    {
Packit ae235b
      g_signal_emit (proxy, signals[PROPERTIES_CHANGED_SIGNAL],
Packit ae235b
                     0,
Packit ae235b
                     changed_properties,
Packit ae235b
                     invalidated_properties);
Packit ae235b
    }
Packit ae235b
Packit ae235b
 out:
Packit ae235b
  if (changed_properties != NULL)
Packit ae235b
    g_variant_unref (changed_properties);
Packit ae235b
  g_free (invalidated_properties);
Packit ae235b
  if (proxy != NULL)
Packit ae235b
    g_object_unref (proxy);
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
static void
Packit ae235b
process_get_all_reply (GDBusProxy *proxy,
Packit ae235b
                       GVariant   *result)
Packit ae235b
{
Packit ae235b
  GVariantIter *iter;
Packit ae235b
  gchar *key;
Packit ae235b
  GVariant *value;
Packit ae235b
  guint num_properties;
Packit ae235b
Packit ae235b
  if (!g_variant_is_of_type (result, G_VARIANT_TYPE ("(a{sv})")))
Packit ae235b
    {
Packit ae235b
      g_warning ("Value for GetAll reply with type '%s' does not match '(a{sv})'",
Packit ae235b
                 g_variant_get_type_string (result));
Packit ae235b
      goto out;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  G_LOCK (properties_lock);
Packit ae235b
Packit ae235b
  g_variant_get (result, "(a{sv})", &iter);
Packit ae235b
  while (g_variant_iter_next (iter, "{sv}", &key, &value))
Packit ae235b
    {
Packit ae235b
      insert_property_checked (proxy,
Packit ae235b
			       key, /* adopts string */
Packit ae235b
			       value); /* adopts value */
Packit ae235b
    }
Packit ae235b
  g_variant_iter_free (iter);
Packit ae235b
Packit ae235b
  num_properties = g_hash_table_size (proxy->priv->properties);
Packit ae235b
  G_UNLOCK (properties_lock);
Packit ae235b
Packit ae235b
  /* Synthesize ::g-properties-changed changed */
Packit ae235b
  if (num_properties > 0)
Packit ae235b
    {
Packit ae235b
      GVariant *changed_properties;
Packit ae235b
      const gchar *invalidated_properties[1] = {NULL};
Packit ae235b
Packit ae235b
      g_variant_get (result,
Packit ae235b
                     "(@a{sv})",
Packit ae235b
                     &changed_properties);
Packit ae235b
      g_signal_emit (proxy, signals[PROPERTIES_CHANGED_SIGNAL],
Packit ae235b
                     0,
Packit ae235b
                     changed_properties,
Packit ae235b
                     invalidated_properties);
Packit ae235b
      g_variant_unref (changed_properties);
Packit ae235b
    }
Packit ae235b
Packit ae235b
 out:
Packit ae235b
  ;
Packit ae235b
}
Packit ae235b
Packit ae235b
typedef struct
Packit ae235b
{
Packit ae235b
  GDBusProxy *proxy;
Packit ae235b
  GCancellable *cancellable;
Packit ae235b
  gchar *name_owner;
Packit ae235b
} LoadPropertiesOnNameOwnerChangedData;
Packit ae235b
Packit ae235b
static void
Packit ae235b
on_name_owner_changed_get_all_cb (GDBusConnection *connection,
Packit ae235b
                                  GAsyncResult    *res,
Packit ae235b
                                  gpointer         user_data)
Packit ae235b
{
Packit ae235b
  LoadPropertiesOnNameOwnerChangedData *data = user_data;
Packit ae235b
  GVariant *result;
Packit ae235b
  GError *error;
Packit ae235b
  gboolean cancelled;
Packit ae235b
Packit ae235b
  cancelled = FALSE;
Packit ae235b
Packit ae235b
  error = NULL;
Packit ae235b
  result = g_dbus_connection_call_finish (connection,
Packit ae235b
                                          res,
Packit ae235b
                                          &error);
Packit ae235b
  if (result == NULL)
Packit ae235b
    {
Packit ae235b
      if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_CANCELLED)
Packit ae235b
        cancelled = TRUE;
Packit ae235b
      /* We just ignore if GetAll() is failing. Because this might happen
Packit ae235b
       * if the object has no properties at all. Or if the caller is
Packit ae235b
       * not authorized to see the properties.
Packit ae235b
       *
Packit ae235b
       * Either way, apps can know about this by using
Packit ae235b
       * get_cached_property_names() or get_cached_property().
Packit ae235b
       *
Packit ae235b
       * TODO: handle G_DBUS_DEBUG flag 'proxy' and, if enabled, log the
Packit ae235b
       * fact that GetAll() failed
Packit ae235b
       */
Packit ae235b
      //g_debug ("error: %d %d %s", error->domain, error->code, error->message);
Packit ae235b
      g_error_free (error);
Packit ae235b
    }
Packit ae235b
Packit ae235b
  /* and finally we can notify */
Packit ae235b
  if (!cancelled)
Packit ae235b
    {
Packit ae235b
      G_LOCK (properties_lock);
Packit ae235b
      g_free (data->proxy->priv->name_owner);
Packit ae235b
      data->proxy->priv->name_owner = data->name_owner;
Packit ae235b
      data->name_owner = NULL; /* to avoid an extra copy, we steal the string */
Packit ae235b
      g_hash_table_remove_all (data->proxy->priv->properties);
Packit ae235b
      G_UNLOCK (properties_lock);
Packit ae235b
      if (result != NULL)
Packit ae235b
        {
Packit ae235b
          process_get_all_reply (data->proxy, result);
Packit ae235b
          g_variant_unref (result);
Packit ae235b
        }
Packit ae235b
Packit ae235b
      g_object_notify (G_OBJECT (data->proxy), "g-name-owner");
Packit ae235b
    }
Packit ae235b
Packit ae235b
  if (data->cancellable == data->proxy->priv->get_all_cancellable)
Packit ae235b
    data->proxy->priv->get_all_cancellable = NULL;
Packit ae235b
Packit ae235b
  g_object_unref (data->proxy);
Packit ae235b
  g_object_unref (data->cancellable);
Packit ae235b
  g_free (data->name_owner);
Packit ae235b
  g_free (data);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
on_name_owner_changed (GDBusConnection *connection,
Packit ae235b
                       const gchar      *sender_name,
Packit ae235b
                       const gchar      *object_path,
Packit ae235b
                       const gchar      *interface_name,
Packit ae235b
                       const gchar      *signal_name,
Packit ae235b
                       GVariant         *parameters,
Packit ae235b
                       gpointer          user_data)
Packit ae235b
{
Packit ae235b
  SignalSubscriptionData *data = user_data;
Packit ae235b
  GDBusProxy *proxy;
Packit ae235b
  const gchar *old_owner;
Packit ae235b
  const gchar *new_owner;
Packit ae235b
Packit ae235b
  G_LOCK (signal_subscription_lock);
Packit ae235b
  proxy = data->proxy;
Packit ae235b
  if (proxy == NULL)
Packit ae235b
    {
Packit ae235b
      G_UNLOCK (signal_subscription_lock);
Packit ae235b
      goto out;
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      g_object_ref (proxy);
Packit ae235b
      G_UNLOCK (signal_subscription_lock);
Packit ae235b
    }
Packit ae235b
Packit ae235b
  /* if we are already trying to load properties, cancel that */
Packit ae235b
  if (proxy->priv->get_all_cancellable != NULL)
Packit ae235b
    {
Packit ae235b
      g_cancellable_cancel (proxy->priv->get_all_cancellable);
Packit ae235b
      proxy->priv->get_all_cancellable = NULL;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  g_variant_get (parameters,
Packit ae235b
                 "(&s&s&s)",
Packit ae235b
                 NULL,
Packit ae235b
                 &old_owner,
Packit ae235b
                 &new_owner);
Packit ae235b
Packit ae235b
  if (strlen (new_owner) == 0)
Packit ae235b
    {
Packit ae235b
      G_LOCK (properties_lock);
Packit ae235b
      g_free (proxy->priv->name_owner);
Packit ae235b
      proxy->priv->name_owner = NULL;
Packit ae235b
Packit ae235b
      /* Synthesize ::g-properties-changed changed */
Packit ae235b
      if (!(proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES) &&
Packit ae235b
          g_hash_table_size (proxy->priv->properties) > 0)
Packit ae235b
        {
Packit ae235b
          GVariantBuilder builder;
Packit ae235b
          GPtrArray *invalidated_properties;
Packit ae235b
          GHashTableIter iter;
Packit ae235b
          const gchar *key;
Packit ae235b
Packit ae235b
          /* Build changed_properties (always empty) and invalidated_properties ... */
Packit ae235b
          g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
Packit ae235b
Packit ae235b
          invalidated_properties = g_ptr_array_new_with_free_func (g_free);
Packit ae235b
          g_hash_table_iter_init (&iter, proxy->priv->properties);
Packit ae235b
          while (g_hash_table_iter_next (&iter, (gpointer) &key, NULL))
Packit ae235b
            g_ptr_array_add (invalidated_properties, g_strdup (key));
Packit ae235b
          g_ptr_array_add (invalidated_properties, NULL);
Packit ae235b
Packit ae235b
          /* ... throw out the properties ... */
Packit ae235b
          g_hash_table_remove_all (proxy->priv->properties);
Packit ae235b
Packit ae235b
          G_UNLOCK (properties_lock);
Packit ae235b
Packit ae235b
          /* ... and finally emit the ::g-properties-changed signal */
Packit ae235b
          g_signal_emit (proxy, signals[PROPERTIES_CHANGED_SIGNAL],
Packit ae235b
                         0,
Packit ae235b
                         g_variant_builder_end (&builder) /* consumed */,
Packit ae235b
                         (const gchar* const *) invalidated_properties->pdata);
Packit ae235b
          g_ptr_array_unref (invalidated_properties);
Packit ae235b
        }
Packit ae235b
      else
Packit ae235b
        {
Packit ae235b
          G_UNLOCK (properties_lock);
Packit ae235b
        }
Packit ae235b
      g_object_notify (G_OBJECT (proxy), "g-name-owner");
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      G_LOCK (properties_lock);
Packit ae235b
Packit ae235b
      /* ignore duplicates - this can happen when activating the service */
Packit ae235b
      if (g_strcmp0 (new_owner, proxy->priv->name_owner) == 0)
Packit ae235b
        {
Packit ae235b
          G_UNLOCK (properties_lock);
Packit ae235b
          goto out;
Packit ae235b
        }
Packit ae235b
Packit ae235b
      if (proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES)
Packit ae235b
        {
Packit ae235b
          g_free (proxy->priv->name_owner);
Packit ae235b
          proxy->priv->name_owner = g_strdup (new_owner);
Packit ae235b
Packit ae235b
          g_hash_table_remove_all (proxy->priv->properties);
Packit ae235b
          G_UNLOCK (properties_lock);
Packit ae235b
          g_object_notify (G_OBJECT (proxy), "g-name-owner");
Packit ae235b
        }
Packit ae235b
      else
Packit ae235b
        {
Packit ae235b
          LoadPropertiesOnNameOwnerChangedData *data;
Packit ae235b
Packit ae235b
          G_UNLOCK (properties_lock);
Packit ae235b
Packit ae235b
          /* start loading properties.. only then emit notify::g-name-owner .. we
Packit ae235b
           * need to be able to cancel this in the event another NameOwnerChanged
Packit ae235b
           * signal suddenly happens
Packit ae235b
           */
Packit ae235b
Packit ae235b
          g_assert (proxy->priv->get_all_cancellable == NULL);
Packit ae235b
          proxy->priv->get_all_cancellable = g_cancellable_new ();
Packit ae235b
          data = g_new0 (LoadPropertiesOnNameOwnerChangedData, 1);
Packit ae235b
          data->proxy = g_object_ref (proxy);
Packit ae235b
          data->cancellable = proxy->priv->get_all_cancellable;
Packit ae235b
          data->name_owner = g_strdup (new_owner);
Packit ae235b
          g_dbus_connection_call (proxy->priv->connection,
Packit ae235b
                                  data->name_owner,
Packit ae235b
                                  proxy->priv->object_path,
Packit ae235b
                                  "org.freedesktop.DBus.Properties",
Packit ae235b
                                  "GetAll",
Packit ae235b
                                  g_variant_new ("(s)", proxy->priv->interface_name),
Packit ae235b
                                  G_VARIANT_TYPE ("(a{sv})"),
Packit ae235b
                                  G_DBUS_CALL_FLAGS_NONE,
Packit ae235b
                                  -1,           /* timeout */
Packit ae235b
                                  proxy->priv->get_all_cancellable,
Packit ae235b
                                  (GAsyncReadyCallback) on_name_owner_changed_get_all_cb,
Packit ae235b
                                  data);
Packit ae235b
        }
Packit ae235b
    }
Packit ae235b
Packit ae235b
 out:
Packit ae235b
  if (proxy != NULL)
Packit ae235b
    g_object_unref (proxy);
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
static void
Packit ae235b
async_init_get_all_cb (GDBusConnection *connection,
Packit ae235b
                       GAsyncResult    *res,
Packit ae235b
                       gpointer         user_data)
Packit ae235b
{
Packit ae235b
  GTask *task = user_data;
Packit ae235b
  GVariant *result;
Packit ae235b
  GError *error;
Packit ae235b
Packit ae235b
  error = NULL;
Packit ae235b
  result = g_dbus_connection_call_finish (connection,
Packit ae235b
                                          res,
Packit ae235b
                                          &error);
Packit ae235b
  if (result == NULL)
Packit ae235b
    {
Packit ae235b
      /* We just ignore if GetAll() is failing. Because this might happen
Packit ae235b
       * if the object has no properties at all. Or if the caller is
Packit ae235b
       * not authorized to see the properties.
Packit ae235b
       *
Packit ae235b
       * Either way, apps can know about this by using
Packit ae235b
       * get_cached_property_names() or get_cached_property().
Packit ae235b
       *
Packit ae235b
       * TODO: handle G_DBUS_DEBUG flag 'proxy' and, if enabled, log the
Packit ae235b
       * fact that GetAll() failed
Packit ae235b
       */
Packit ae235b
      //g_debug ("error: %d %d %s", error->domain, error->code, error->message);
Packit ae235b
      g_error_free (error);
Packit ae235b
    }
Packit ae235b
Packit ae235b
  g_task_return_pointer (task, result,
Packit ae235b
                         (GDestroyNotify) g_variant_unref);
Packit ae235b
  g_object_unref (task);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
async_init_data_set_name_owner (GTask       *task,
Packit ae235b
                                const gchar *name_owner)
Packit ae235b
{
Packit ae235b
  GDBusProxy *proxy = g_task_get_source_object (task);
Packit ae235b
  gboolean get_all;
Packit ae235b
Packit ae235b
  if (name_owner != NULL)
Packit ae235b
    {
Packit ae235b
      G_LOCK (properties_lock);
Packit ae235b
      /* Must free first, since on_name_owner_changed() could run before us */
Packit ae235b
      g_free (proxy->priv->name_owner);
Packit ae235b
      proxy->priv->name_owner = g_strdup (name_owner);
Packit ae235b
      G_UNLOCK (properties_lock);
Packit ae235b
    }
Packit ae235b
Packit ae235b
  get_all = TRUE;
Packit ae235b
Packit ae235b
  if (proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES)
Packit ae235b
    {
Packit ae235b
      /* Don't load properties if the API user doesn't want them */
Packit ae235b
      get_all = FALSE;
Packit ae235b
    }
Packit ae235b
  else if (name_owner == NULL && proxy->priv->name != NULL)
Packit ae235b
    {
Packit ae235b
      /* Don't attempt to load properties if the name_owner is NULL (which
Packit ae235b
       * usually means the name isn't owned), unless name is also NULL (which
Packit ae235b
       * means we actually wanted to talk to the directly-connected process -
Packit ae235b
       * either dbus-daemon or a peer - instead of going via dbus-daemon)
Packit ae235b
       */
Packit ae235b
        get_all = FALSE;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  if (get_all)
Packit ae235b
    {
Packit ae235b
      /* load all properties asynchronously */
Packit ae235b
      g_dbus_connection_call (proxy->priv->connection,
Packit ae235b
                              name_owner,
Packit ae235b
                              proxy->priv->object_path,
Packit ae235b
                              "org.freedesktop.DBus.Properties",
Packit ae235b
                              "GetAll",
Packit ae235b
                              g_variant_new ("(s)", proxy->priv->interface_name),
Packit ae235b
                              G_VARIANT_TYPE ("(a{sv})"),
Packit ae235b
                              G_DBUS_CALL_FLAGS_NONE,
Packit ae235b
                              -1,           /* timeout */
Packit ae235b
                              g_task_get_cancellable (task),
Packit ae235b
                              (GAsyncReadyCallback) async_init_get_all_cb,
Packit ae235b
                              task);
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      g_task_return_pointer (task, NULL, NULL);
Packit ae235b
      g_object_unref (task);
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
async_init_get_name_owner_cb (GDBusConnection *connection,
Packit ae235b
                              GAsyncResult    *res,
Packit ae235b
                              gpointer         user_data)
Packit ae235b
{
Packit ae235b
  GTask *task = user_data;
Packit ae235b
  GError *error;
Packit ae235b
  GVariant *result;
Packit ae235b
Packit ae235b
  error = NULL;
Packit ae235b
  result = g_dbus_connection_call_finish (connection,
Packit ae235b
                                          res,
Packit ae235b
                                          &error);
Packit ae235b
  if (result == NULL)
Packit ae235b
    {
Packit ae235b
      if (error->domain == G_DBUS_ERROR &&
Packit ae235b
          error->code == G_DBUS_ERROR_NAME_HAS_NO_OWNER)
Packit ae235b
        {
Packit ae235b
          g_error_free (error);
Packit ae235b
          async_init_data_set_name_owner (task, NULL);
Packit ae235b
        }
Packit ae235b
      else
Packit ae235b
        {
Packit ae235b
          g_task_return_error (task, error);
Packit ae235b
          g_object_unref (task);
Packit ae235b
        }
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      /* borrowed from result to avoid an extra copy */
Packit ae235b
      const gchar *name_owner;
Packit ae235b
Packit ae235b
      g_variant_get (result, "(&s)", &name_owner);
Packit ae235b
      async_init_data_set_name_owner (task, name_owner);
Packit ae235b
      g_variant_unref (result);
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
async_init_call_get_name_owner (GTask *task)
Packit ae235b
{
Packit ae235b
  GDBusProxy *proxy = g_task_get_source_object (task);
Packit ae235b
Packit ae235b
  g_dbus_connection_call (proxy->priv->connection,
Packit ae235b
                          "org.freedesktop.DBus",  /* name */
Packit ae235b
                          "/org/freedesktop/DBus", /* object path */
Packit ae235b
                          "org.freedesktop.DBus",  /* interface */
Packit ae235b
                          "GetNameOwner",
Packit ae235b
                          g_variant_new ("(s)",
Packit ae235b
                                         proxy->priv->name),
Packit ae235b
                          G_VARIANT_TYPE ("(s)"),
Packit ae235b
                          G_DBUS_CALL_FLAGS_NONE,
Packit ae235b
                          -1,           /* timeout */
Packit ae235b
                          g_task_get_cancellable (task),
Packit ae235b
                          (GAsyncReadyCallback) async_init_get_name_owner_cb,
Packit ae235b
                          task);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
async_init_start_service_by_name_cb (GDBusConnection *connection,
Packit ae235b
                                     GAsyncResult    *res,
Packit ae235b
                                     gpointer         user_data)
Packit ae235b
{
Packit ae235b
  GTask *task = user_data;
Packit ae235b
  GDBusProxy *proxy = g_task_get_source_object (task);
Packit ae235b
  GError *error;
Packit ae235b
  GVariant *result;
Packit ae235b
Packit ae235b
  error = NULL;
Packit ae235b
  result = g_dbus_connection_call_finish (connection,
Packit ae235b
                                          res,
Packit ae235b
                                          &error);
Packit ae235b
  if (result == NULL)
Packit ae235b
    {
Packit ae235b
      /* Errors are not unexpected; the bus will reply e.g.
Packit ae235b
       *
Packit ae235b
       *   org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.Epiphany2
Packit ae235b
       *   was not provided by any .service files
Packit ae235b
       *
Packit ae235b
       * or (see #677718)
Packit ae235b
       *
Packit ae235b
       *   org.freedesktop.systemd1.Masked: Unit polkit.service is masked.
Packit ae235b
       *
Packit ae235b
       * This doesn't mean that the name doesn't have an owner, just
Packit ae235b
       * that it's not provided by a .service file or can't currently
Packit ae235b
       * be started.
Packit ae235b
       *
Packit ae235b
       * In particular, in both cases, it could be that a service
Packit ae235b
       * owner will actually appear later. So instead of erroring out,
Packit ae235b
       * we just proceed to invoke GetNameOwner() if dealing with the
Packit ae235b
       * kind of errors above.
Packit ae235b
       */
Packit ae235b
      if (error->domain == G_DBUS_ERROR && error->code == G_DBUS_ERROR_SERVICE_UNKNOWN)
Packit ae235b
        {
Packit ae235b
          g_error_free (error);
Packit ae235b
        }
Packit ae235b
      else
Packit ae235b
        {
Packit ae235b
          gchar *remote_error = g_dbus_error_get_remote_error (error);
Packit ae235b
          if (g_strcmp0 (remote_error, "org.freedesktop.systemd1.Masked") == 0)
Packit ae235b
            {
Packit ae235b
              g_error_free (error);
Packit ae235b
              g_free (remote_error);
Packit ae235b
            }
Packit ae235b
          else
Packit ae235b
            {
Packit ae235b
              g_prefix_error (&error,
Packit ae235b
                              _("Error calling StartServiceByName for %s: "),
Packit ae235b
                              proxy->priv->name);
Packit ae235b
              g_free (remote_error);
Packit ae235b
              goto failed;
Packit ae235b
            }
Packit ae235b
        }
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      guint32 start_service_result;
Packit ae235b
      g_variant_get (result,
Packit ae235b
                     "(u)",
Packit ae235b
                     &start_service_result);
Packit ae235b
      g_variant_unref (result);
Packit ae235b
      if (start_service_result == 1 ||  /* DBUS_START_REPLY_SUCCESS */
Packit ae235b
          start_service_result == 2)    /* DBUS_START_REPLY_ALREADY_RUNNING */
Packit ae235b
        {
Packit ae235b
          /* continue to invoke GetNameOwner() */
Packit ae235b
        }
Packit ae235b
      else
Packit ae235b
        {
Packit ae235b
          error = g_error_new (G_IO_ERROR,
Packit ae235b
                               G_IO_ERROR_FAILED,
Packit ae235b
                               _("Unexpected reply %d from StartServiceByName(\"%s\") method"),
Packit ae235b
                               start_service_result,
Packit ae235b
                               proxy->priv->name);
Packit ae235b
          goto failed;
Packit ae235b
        }
Packit ae235b
    }
Packit ae235b
Packit ae235b
  async_init_call_get_name_owner (task);
Packit ae235b
  return;
Packit ae235b
Packit ae235b
 failed:
Packit ae235b
  g_warn_if_fail (error != NULL);
Packit ae235b
  g_task_return_error (task, error);
Packit ae235b
  g_object_unref (task);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
async_init_call_start_service_by_name (GTask *task)
Packit ae235b
{
Packit ae235b
  GDBusProxy *proxy = g_task_get_source_object (task);
Packit ae235b
Packit ae235b
  g_dbus_connection_call (proxy->priv->connection,
Packit ae235b
                          "org.freedesktop.DBus",  /* name */
Packit ae235b
                          "/org/freedesktop/DBus", /* object path */
Packit ae235b
                          "org.freedesktop.DBus",  /* interface */
Packit ae235b
                          "StartServiceByName",
Packit ae235b
                          g_variant_new ("(su)",
Packit ae235b
                                         proxy->priv->name,
Packit ae235b
                                         0),
Packit ae235b
                          G_VARIANT_TYPE ("(u)"),
Packit ae235b
                          G_DBUS_CALL_FLAGS_NONE,
Packit ae235b
                          -1,           /* timeout */
Packit ae235b
                          g_task_get_cancellable (task),
Packit ae235b
                          (GAsyncReadyCallback) async_init_start_service_by_name_cb,
Packit ae235b
                          task);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
async_initable_init_second_async (GAsyncInitable      *initable,
Packit ae235b
                                  gint                 io_priority,
Packit ae235b
                                  GCancellable        *cancellable,
Packit ae235b
                                  GAsyncReadyCallback  callback,
Packit ae235b
                                  gpointer             user_data)
Packit ae235b
{
Packit ae235b
  GDBusProxy *proxy = G_DBUS_PROXY (initable);
Packit ae235b
  GTask *task;
Packit ae235b
Packit ae235b
  task = g_task_new (proxy, cancellable, callback, user_data);
Packit ae235b
  g_task_set_source_tag (task, async_initable_init_second_async);
Packit ae235b
  g_task_set_priority (task, io_priority);
Packit ae235b
Packit ae235b
  /* Check name ownership asynchronously - possibly also start the service */
Packit ae235b
  if (proxy->priv->name == NULL)
Packit ae235b
    {
Packit ae235b
      /* Do nothing */
Packit ae235b
      async_init_data_set_name_owner (task, NULL);
Packit ae235b
    }
Packit ae235b
  else if (g_dbus_is_unique_name (proxy->priv->name))
Packit ae235b
    {
Packit ae235b
      async_init_data_set_name_owner (task, proxy->priv->name);
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      if ((proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START) ||
Packit ae235b
          (proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION))
Packit ae235b
        {
Packit ae235b
          async_init_call_get_name_owner (task);
Packit ae235b
        }
Packit ae235b
      else
Packit ae235b
        {
Packit ae235b
          async_init_call_start_service_by_name (task);
Packit ae235b
        }
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
static gboolean
Packit ae235b
async_initable_init_second_finish (GAsyncInitable  *initable,
Packit ae235b
                                   GAsyncResult    *res,
Packit ae235b
                                   GError         **error)
Packit ae235b
{
Packit ae235b
  GDBusProxy *proxy = G_DBUS_PROXY (initable);
Packit ae235b
  GTask *task = G_TASK (res);
Packit ae235b
  GVariant *result;
Packit ae235b
  gboolean ret;
Packit ae235b
Packit ae235b
  ret = !g_task_had_error (task);
Packit ae235b
Packit ae235b
  result = g_task_propagate_pointer (task, error);
Packit ae235b
  if (result != NULL)
Packit ae235b
    {
Packit ae235b
      process_get_all_reply (proxy, result);
Packit ae235b
      g_variant_unref (result);
Packit ae235b
    }
Packit ae235b
Packit ae235b
  proxy->priv->initialized = TRUE;
Packit ae235b
  return ret;
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
static void
Packit ae235b
async_initable_init_first (GAsyncInitable *initable)
Packit ae235b
{
Packit ae235b
  GDBusProxy *proxy = G_DBUS_PROXY (initable);
Packit ae235b
Packit ae235b
  if (!(proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES))
Packit ae235b
    {
Packit ae235b
      /* subscribe to PropertiesChanged() */
Packit ae235b
      proxy->priv->properties_changed_subscription_id =
Packit ae235b
        g_dbus_connection_signal_subscribe (proxy->priv->connection,
Packit ae235b
                                            proxy->priv->name,
Packit ae235b
                                            "org.freedesktop.DBus.Properties",
Packit ae235b
                                            "PropertiesChanged",
Packit ae235b
                                            proxy->priv->object_path,
Packit ae235b
                                            proxy->priv->interface_name,
Packit ae235b
                                            G_DBUS_SIGNAL_FLAGS_NONE,
Packit ae235b
                                            on_properties_changed,
Packit ae235b
                                            signal_subscription_ref (proxy->priv->signal_subscription_data),
Packit ae235b
                                            (GDestroyNotify) signal_subscription_unref);
Packit ae235b
    }
Packit ae235b
Packit ae235b
  if (!(proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS))
Packit ae235b
    {
Packit ae235b
      /* subscribe to all signals for the object */
Packit ae235b
      proxy->priv->signals_subscription_id =
Packit ae235b
        g_dbus_connection_signal_subscribe (proxy->priv->connection,
Packit ae235b
                                            proxy->priv->name,
Packit ae235b
                                            proxy->priv->interface_name,
Packit ae235b
                                            NULL,                        /* member */
Packit ae235b
                                            proxy->priv->object_path,
Packit ae235b
                                            NULL,                        /* arg0 */
Packit ae235b
                                            G_DBUS_SIGNAL_FLAGS_NONE,
Packit ae235b
                                            on_signal_received,
Packit ae235b
                                            signal_subscription_ref (proxy->priv->signal_subscription_data),
Packit ae235b
                                            (GDestroyNotify) signal_subscription_unref);
Packit ae235b
    }
Packit ae235b
Packit ae235b
  if (proxy->priv->name != NULL && !g_dbus_is_unique_name (proxy->priv->name))
Packit ae235b
    {
Packit ae235b
      proxy->priv->name_owner_changed_subscription_id =
Packit ae235b
        g_dbus_connection_signal_subscribe (proxy->priv->connection,
Packit ae235b
                                            "org.freedesktop.DBus",  /* name */
Packit ae235b
                                            "org.freedesktop.DBus",  /* interface */
Packit ae235b
                                            "NameOwnerChanged",      /* signal name */
Packit ae235b
                                            "/org/freedesktop/DBus", /* path */
Packit ae235b
                                            proxy->priv->name,       /* arg0 */
Packit ae235b
                                            G_DBUS_SIGNAL_FLAGS_NONE,
Packit ae235b
                                            on_name_owner_changed,
Packit ae235b
                                            signal_subscription_ref (proxy->priv->signal_subscription_data),
Packit ae235b
                                            (GDestroyNotify) signal_subscription_unref);
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
/* initialization is split into two parts - the first is the
Packit ae235b
 * non-blocking part that requires the callers GMainContext - the
Packit ae235b
 * second is a blocking part async part that doesn't require the
Packit ae235b
 * callers GMainContext.. we do this split so the code can be reused
Packit ae235b
 * in the GInitable implementation below.
Packit ae235b
 *
Packit ae235b
 * Note that obtaining a GDBusConnection is not shared between the two
Packit ae235b
 * paths.
Packit ae235b
 */
Packit ae235b
Packit ae235b
static void
Packit ae235b
init_second_async_cb (GObject       *source_object,
Packit ae235b
		      GAsyncResult  *res,
Packit ae235b
		      gpointer       user_data)
Packit ae235b
{
Packit ae235b
  GTask *task = user_data;
Packit ae235b
  GError *error = NULL;
Packit ae235b
Packit ae235b
  if (async_initable_init_second_finish (G_ASYNC_INITABLE (source_object), res, &error))
Packit ae235b
    g_task_return_boolean (task, TRUE);
Packit ae235b
  else
Packit ae235b
    g_task_return_error (task, error);
Packit ae235b
  g_object_unref (task);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
get_connection_cb (GObject       *source_object,
Packit ae235b
                   GAsyncResult  *res,
Packit ae235b
                   gpointer       user_data)
Packit ae235b
{
Packit ae235b
  GTask *task = user_data;
Packit ae235b
  GDBusProxy *proxy = g_task_get_source_object (task);
Packit ae235b
  GError *error;
Packit ae235b
Packit ae235b
  error = NULL;
Packit ae235b
  proxy->priv->connection = g_bus_get_finish (res, &error);
Packit ae235b
  if (proxy->priv->connection == NULL)
Packit ae235b
    {
Packit ae235b
      g_task_return_error (task, error);
Packit ae235b
      g_object_unref (task);
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      async_initable_init_first (G_ASYNC_INITABLE (proxy));
Packit ae235b
      async_initable_init_second_async (G_ASYNC_INITABLE (proxy),
Packit ae235b
                                        g_task_get_priority (task),
Packit ae235b
                                        g_task_get_cancellable (task),
Packit ae235b
                                        init_second_async_cb,
Packit ae235b
                                        task);
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
async_initable_init_async (GAsyncInitable      *initable,
Packit ae235b
                           gint                 io_priority,
Packit ae235b
                           GCancellable        *cancellable,
Packit ae235b
                           GAsyncReadyCallback  callback,
Packit ae235b
                           gpointer             user_data)
Packit ae235b
{
Packit ae235b
  GDBusProxy *proxy = G_DBUS_PROXY (initable);
Packit ae235b
  GTask *task;
Packit ae235b
Packit ae235b
  task = g_task_new (proxy, cancellable, callback, user_data);
Packit ae235b
  g_task_set_source_tag (task, async_initable_init_async);
Packit ae235b
  g_task_set_priority (task, io_priority);
Packit ae235b
Packit ae235b
  if (proxy->priv->bus_type != G_BUS_TYPE_NONE)
Packit ae235b
    {
Packit ae235b
      g_assert (proxy->priv->connection == NULL);
Packit ae235b
Packit ae235b
      g_bus_get (proxy->priv->bus_type,
Packit ae235b
                 cancellable,
Packit ae235b
                 get_connection_cb,
Packit ae235b
                 task);
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      async_initable_init_first (initable);
Packit ae235b
      async_initable_init_second_async (initable, io_priority, cancellable,
Packit ae235b
                                        init_second_async_cb, task);
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
static gboolean
Packit ae235b
async_initable_init_finish (GAsyncInitable  *initable,
Packit ae235b
                            GAsyncResult    *res,
Packit ae235b
                            GError         **error)
Packit ae235b
{
Packit ae235b
  return g_task_propagate_boolean (G_TASK (res), error);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
async_initable_iface_init (GAsyncInitableIface *async_initable_iface)
Packit ae235b
{
Packit ae235b
  async_initable_iface->init_async = async_initable_init_async;
Packit ae235b
  async_initable_iface->init_finish = async_initable_init_finish;
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
typedef struct
Packit ae235b
{
Packit ae235b
  GMainContext *context;
Packit ae235b
  GMainLoop *loop;
Packit ae235b
  GAsyncResult *res;
Packit ae235b
} InitableAsyncInitableData;
Packit ae235b
Packit ae235b
static void
Packit ae235b
async_initable_init_async_cb (GObject      *source_object,
Packit ae235b
                              GAsyncResult *res,
Packit ae235b
                              gpointer      user_data)
Packit ae235b
{
Packit ae235b
  InitableAsyncInitableData *data = user_data;
Packit ae235b
  data->res = g_object_ref (res);
Packit ae235b
  g_main_loop_quit (data->loop);
Packit ae235b
}
Packit ae235b
Packit ae235b
/* Simply reuse the GAsyncInitable implementation but run the first
Packit ae235b
 * part (that is non-blocking and requires the callers GMainContext)
Packit ae235b
 * with the callers GMainContext.. and the second with a private
Packit ae235b
 * GMainContext (bug 621310 is slightly related).
Packit ae235b
 *
Packit ae235b
 * Note that obtaining a GDBusConnection is not shared between the two
Packit ae235b
 * paths.
Packit ae235b
 */
Packit ae235b
static gboolean
Packit ae235b
initable_init (GInitable     *initable,
Packit ae235b
               GCancellable  *cancellable,
Packit ae235b
               GError       **error)
Packit ae235b
{
Packit ae235b
  GDBusProxy *proxy = G_DBUS_PROXY (initable);
Packit ae235b
  InitableAsyncInitableData *data;
Packit ae235b
  gboolean ret;
Packit ae235b
Packit ae235b
  ret = FALSE;
Packit ae235b
Packit ae235b
  if (proxy->priv->bus_type != G_BUS_TYPE_NONE)
Packit ae235b
    {
Packit ae235b
      g_assert (proxy->priv->connection == NULL);
Packit ae235b
      proxy->priv->connection = g_bus_get_sync (proxy->priv->bus_type,
Packit ae235b
                                                cancellable,
Packit ae235b
                                                error);
Packit ae235b
      if (proxy->priv->connection == NULL)
Packit ae235b
        goto out;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  async_initable_init_first (G_ASYNC_INITABLE (initable));
Packit ae235b
Packit ae235b
  data = g_new0 (InitableAsyncInitableData, 1);
Packit ae235b
  data->context = g_main_context_new ();
Packit ae235b
  data->loop = g_main_loop_new (data->context, FALSE);
Packit ae235b
Packit ae235b
  g_main_context_push_thread_default (data->context);
Packit ae235b
Packit ae235b
  async_initable_init_second_async (G_ASYNC_INITABLE (initable),
Packit ae235b
                                    G_PRIORITY_DEFAULT,
Packit ae235b
                                    cancellable,
Packit ae235b
                                    async_initable_init_async_cb,
Packit ae235b
                                    data);
Packit ae235b
Packit ae235b
  g_main_loop_run (data->loop);
Packit ae235b
Packit ae235b
  ret = async_initable_init_second_finish (G_ASYNC_INITABLE (initable),
Packit ae235b
                                           data->res,
Packit ae235b
                                           error);
Packit ae235b
Packit ae235b
  g_main_context_pop_thread_default (data->context);
Packit ae235b
Packit ae235b
  g_main_context_unref (data->context);
Packit ae235b
  g_main_loop_unref (data->loop);
Packit ae235b
  g_object_unref (data->res);
Packit ae235b
  g_free (data);
Packit ae235b
Packit ae235b
 out:
Packit ae235b
Packit ae235b
  return ret;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
initable_iface_init (GInitableIface *initable_iface)
Packit ae235b
{
Packit ae235b
  initable_iface->init = initable_init;
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_proxy_new:
Packit ae235b
 * @connection: A #GDBusConnection.
Packit ae235b
 * @flags: Flags used when constructing the proxy.
Packit ae235b
 * @info: (nullable): A #GDBusInterfaceInfo specifying the minimal interface that @proxy conforms to or %NULL.
Packit ae235b
 * @name: (nullable): A bus name (well-known or unique) or %NULL if @connection is not a message bus connection.
Packit ae235b
 * @object_path: An object path.
Packit ae235b
 * @interface_name: A D-Bus interface name.
Packit ae235b
 * @cancellable: (nullable): A #GCancellable or %NULL.
Packit ae235b
 * @callback: Callback function to invoke when the proxy is ready.
Packit ae235b
 * @user_data: User data to pass to @callback.
Packit ae235b
 *
Packit ae235b
 * Creates a proxy for accessing @interface_name on the remote object
Packit ae235b
 * at @object_path owned by @name at @connection and asynchronously
Packit ae235b
 * loads D-Bus properties unless the
Packit ae235b
 * %G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES flag is used. Connect to
Packit ae235b
 * the #GDBusProxy::g-properties-changed signal to get notified about
Packit ae235b
 * property changes.
Packit ae235b
 *
Packit ae235b
 * If the %G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS flag is not set, also sets up
Packit ae235b
 * match rules for signals. Connect to the #GDBusProxy::g-signal signal
Packit ae235b
 * to handle signals from the remote object.
Packit ae235b
 *
Packit ae235b
 * If @name is a well-known name and the
Packit ae235b
 * %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START and %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION
Packit ae235b
 * flags aren't set and no name owner currently exists, the message bus
Packit ae235b
 * will be requested to launch a name owner for the name.
Packit ae235b
 *
Packit ae235b
 * This is a failable asynchronous constructor - when the proxy is
Packit ae235b
 * ready, @callback will be invoked and you can use
Packit ae235b
 * g_dbus_proxy_new_finish() to get the result.
Packit ae235b
 *
Packit ae235b
 * See g_dbus_proxy_new_sync() and for a synchronous version of this constructor.
Packit ae235b
 *
Packit ae235b
 * #GDBusProxy is used in this [example][gdbus-wellknown-proxy].
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dbus_proxy_new (GDBusConnection     *connection,
Packit ae235b
                  GDBusProxyFlags      flags,
Packit ae235b
                  GDBusInterfaceInfo  *info,
Packit ae235b
                  const gchar         *name,
Packit ae235b
                  const gchar         *object_path,
Packit ae235b
                  const gchar         *interface_name,
Packit ae235b
                  GCancellable        *cancellable,
Packit ae235b
                  GAsyncReadyCallback  callback,
Packit ae235b
                  gpointer             user_data)
Packit ae235b
{
Packit ae235b
  _g_dbus_initialize ();
Packit ae235b
Packit ae235b
  g_return_if_fail (G_IS_DBUS_CONNECTION (connection));
Packit ae235b
  g_return_if_fail ((name == NULL && g_dbus_connection_get_unique_name (connection) == NULL) || g_dbus_is_name (name));
Packit ae235b
  g_return_if_fail (g_variant_is_object_path (object_path));
Packit ae235b
  g_return_if_fail (g_dbus_is_interface_name (interface_name));
Packit ae235b
Packit ae235b
  g_async_initable_new_async (G_TYPE_DBUS_PROXY,
Packit ae235b
                              G_PRIORITY_DEFAULT,
Packit ae235b
                              cancellable,
Packit ae235b
                              callback,
Packit ae235b
                              user_data,
Packit ae235b
                              "g-flags", flags,
Packit ae235b
                              "g-interface-info", info,
Packit ae235b
                              "g-name", name,
Packit ae235b
                              "g-connection", connection,
Packit ae235b
                              "g-object-path", object_path,
Packit ae235b
                              "g-interface-name", interface_name,
Packit ae235b
                              NULL);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_proxy_new_finish:
Packit ae235b
 * @res: A #GAsyncResult obtained from the #GAsyncReadyCallback function passed to g_dbus_proxy_new().
Packit ae235b
 * @error: Return location for error or %NULL.
Packit ae235b
 *
Packit ae235b
 * Finishes creating a #GDBusProxy.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer full): A #GDBusProxy or %NULL if @error is set.
Packit ae235b
 *    Free with g_object_unref().
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
GDBusProxy *
Packit ae235b
g_dbus_proxy_new_finish (GAsyncResult  *res,
Packit ae235b
                         GError       **error)
Packit ae235b
{
Packit ae235b
  GObject *object;
Packit ae235b
  GObject *source_object;
Packit ae235b
Packit ae235b
  source_object = g_async_result_get_source_object (res);
Packit ae235b
  g_assert (source_object != NULL);
Packit ae235b
Packit ae235b
  object = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object),
Packit ae235b
                                        res,
Packit ae235b
                                        error);
Packit ae235b
  g_object_unref (source_object);
Packit ae235b
Packit ae235b
  if (object != NULL)
Packit ae235b
    return G_DBUS_PROXY (object);
Packit ae235b
  else
Packit ae235b
    return NULL;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_proxy_new_sync:
Packit ae235b
 * @connection: A #GDBusConnection.
Packit ae235b
 * @flags: Flags used when constructing the proxy.
Packit ae235b
 * @info: (nullable): A #GDBusInterfaceInfo specifying the minimal interface that @proxy conforms to or %NULL.
Packit ae235b
 * @name: (nullable): A bus name (well-known or unique) or %NULL if @connection is not a message bus connection.
Packit ae235b
 * @object_path: An object path.
Packit ae235b
 * @interface_name: A D-Bus interface name.
Packit ae235b
 * @cancellable: (nullable): A #GCancellable or %NULL.
Packit ae235b
 * @error: (nullable): Return location for error or %NULL.
Packit ae235b
 *
Packit ae235b
 * Creates a proxy for accessing @interface_name on the remote object
Packit ae235b
 * at @object_path owned by @name at @connection and synchronously
Packit ae235b
 * loads D-Bus properties unless the
Packit ae235b
 * %G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES flag is used.
Packit ae235b
 *
Packit ae235b
 * If the %G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS flag is not set, also sets up
Packit ae235b
 * match rules for signals. Connect to the #GDBusProxy::g-signal signal
Packit ae235b
 * to handle signals from the remote object.
Packit ae235b
 *
Packit ae235b
 * If @name is a well-known name and the
Packit ae235b
 * %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START and %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION
Packit ae235b
 * flags aren't set and no name owner currently exists, the message bus
Packit ae235b
 * will be requested to launch a name owner for the name.
Packit ae235b
 *
Packit ae235b
 * This is a synchronous failable constructor. See g_dbus_proxy_new()
Packit ae235b
 * and g_dbus_proxy_new_finish() for the asynchronous version.
Packit ae235b
 *
Packit ae235b
 * #GDBusProxy is used in this [example][gdbus-wellknown-proxy].
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer full): A #GDBusProxy or %NULL if error is set.
Packit ae235b
 *    Free with g_object_unref().
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
GDBusProxy *
Packit ae235b
g_dbus_proxy_new_sync (GDBusConnection     *connection,
Packit ae235b
                       GDBusProxyFlags      flags,
Packit ae235b
                       GDBusInterfaceInfo  *info,
Packit ae235b
                       const gchar         *name,
Packit ae235b
                       const gchar         *object_path,
Packit ae235b
                       const gchar         *interface_name,
Packit ae235b
                       GCancellable        *cancellable,
Packit ae235b
                       GError             **error)
Packit ae235b
{
Packit ae235b
  GInitable *initable;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
Packit ae235b
  g_return_val_if_fail ((name == NULL && g_dbus_connection_get_unique_name (connection) == NULL) ||
Packit ae235b
                        g_dbus_is_name (name), NULL);
Packit ae235b
  g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);
Packit ae235b
  g_return_val_if_fail (g_dbus_is_interface_name (interface_name), NULL);
Packit ae235b
Packit ae235b
  initable = g_initable_new (G_TYPE_DBUS_PROXY,
Packit ae235b
                             cancellable,
Packit ae235b
                             error,
Packit ae235b
                             "g-flags", flags,
Packit ae235b
                             "g-interface-info", info,
Packit ae235b
                             "g-name", name,
Packit ae235b
                             "g-connection", connection,
Packit ae235b
                             "g-object-path", object_path,
Packit ae235b
                             "g-interface-name", interface_name,
Packit ae235b
                             NULL);
Packit ae235b
  if (initable != NULL)
Packit ae235b
    return G_DBUS_PROXY (initable);
Packit ae235b
  else
Packit ae235b
    return NULL;
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_proxy_new_for_bus:
Packit ae235b
 * @bus_type: A #GBusType.
Packit ae235b
 * @flags: Flags used when constructing the proxy.
Packit ae235b
 * @info: (nullable): A #GDBusInterfaceInfo specifying the minimal interface that @proxy conforms to or %NULL.
Packit ae235b
 * @name: A bus name (well-known or unique).
Packit ae235b
 * @object_path: An object path.
Packit ae235b
 * @interface_name: A D-Bus interface name.
Packit ae235b
 * @cancellable: (nullable): A #GCancellable or %NULL.
Packit ae235b
 * @callback: Callback function to invoke when the proxy is ready.
Packit ae235b
 * @user_data: User data to pass to @callback.
Packit ae235b
 *
Packit ae235b
 * Like g_dbus_proxy_new() but takes a #GBusType instead of a #GDBusConnection.
Packit ae235b
 *
Packit ae235b
 * #GDBusProxy is used in this [example][gdbus-wellknown-proxy].
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dbus_proxy_new_for_bus (GBusType             bus_type,
Packit ae235b
                          GDBusProxyFlags      flags,
Packit ae235b
                          GDBusInterfaceInfo  *info,
Packit ae235b
                          const gchar         *name,
Packit ae235b
                          const gchar         *object_path,
Packit ae235b
                          const gchar         *interface_name,
Packit ae235b
                          GCancellable        *cancellable,
Packit ae235b
                          GAsyncReadyCallback  callback,
Packit ae235b
                          gpointer             user_data)
Packit ae235b
{
Packit ae235b
  _g_dbus_initialize ();
Packit ae235b
Packit ae235b
  g_return_if_fail (g_dbus_is_name (name));
Packit ae235b
  g_return_if_fail (g_variant_is_object_path (object_path));
Packit ae235b
  g_return_if_fail (g_dbus_is_interface_name (interface_name));
Packit ae235b
Packit ae235b
  g_async_initable_new_async (G_TYPE_DBUS_PROXY,
Packit ae235b
                              G_PRIORITY_DEFAULT,
Packit ae235b
                              cancellable,
Packit ae235b
                              callback,
Packit ae235b
                              user_data,
Packit ae235b
                              "g-flags", flags,
Packit ae235b
                              "g-interface-info", info,
Packit ae235b
                              "g-name", name,
Packit ae235b
                              "g-bus-type", bus_type,
Packit ae235b
                              "g-object-path", object_path,
Packit ae235b
                              "g-interface-name", interface_name,
Packit ae235b
                              NULL);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_proxy_new_for_bus_finish:
Packit ae235b
 * @res: A #GAsyncResult obtained from the #GAsyncReadyCallback function passed to g_dbus_proxy_new_for_bus().
Packit ae235b
 * @error: Return location for error or %NULL.
Packit ae235b
 *
Packit ae235b
 * Finishes creating a #GDBusProxy.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer full): A #GDBusProxy or %NULL if @error is set.
Packit ae235b
 *    Free with g_object_unref().
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
GDBusProxy *
Packit ae235b
g_dbus_proxy_new_for_bus_finish (GAsyncResult  *res,
Packit ae235b
                                 GError       **error)
Packit ae235b
{
Packit ae235b
  return g_dbus_proxy_new_finish (res, error);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_proxy_new_for_bus_sync:
Packit ae235b
 * @bus_type: A #GBusType.
Packit ae235b
 * @flags: Flags used when constructing the proxy.
Packit ae235b
 * @info: (nullable): A #GDBusInterfaceInfo specifying the minimal interface
Packit ae235b
 *        that @proxy conforms to or %NULL.
Packit ae235b
 * @name: A bus name (well-known or unique).
Packit ae235b
 * @object_path: An object path.
Packit ae235b
 * @interface_name: A D-Bus interface name.
Packit ae235b
 * @cancellable: (nullable): A #GCancellable or %NULL.
Packit ae235b
 * @error: Return location for error or %NULL.
Packit ae235b
 *
Packit ae235b
 * Like g_dbus_proxy_new_sync() but takes a #GBusType instead of a #GDBusConnection.
Packit ae235b
 *
Packit ae235b
 * #GDBusProxy is used in this [example][gdbus-wellknown-proxy].
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer full): A #GDBusProxy or %NULL if error is set.
Packit ae235b
 *    Free with g_object_unref().
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
GDBusProxy *
Packit ae235b
g_dbus_proxy_new_for_bus_sync (GBusType             bus_type,
Packit ae235b
                               GDBusProxyFlags      flags,
Packit ae235b
                               GDBusInterfaceInfo  *info,
Packit ae235b
                               const gchar         *name,
Packit ae235b
                               const gchar         *object_path,
Packit ae235b
                               const gchar         *interface_name,
Packit ae235b
                               GCancellable        *cancellable,
Packit ae235b
                               GError             **error)
Packit ae235b
{
Packit ae235b
  GInitable *initable;
Packit ae235b
Packit ae235b
  _g_dbus_initialize ();
Packit ae235b
Packit ae235b
  g_return_val_if_fail (g_dbus_is_name (name), NULL);
Packit ae235b
  g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);
Packit ae235b
  g_return_val_if_fail (g_dbus_is_interface_name (interface_name), NULL);
Packit ae235b
Packit ae235b
  initable = g_initable_new (G_TYPE_DBUS_PROXY,
Packit ae235b
                             cancellable,
Packit ae235b
                             error,
Packit ae235b
                             "g-flags", flags,
Packit ae235b
                             "g-interface-info", info,
Packit ae235b
                             "g-name", name,
Packit ae235b
                             "g-bus-type", bus_type,
Packit ae235b
                             "g-object-path", object_path,
Packit ae235b
                             "g-interface-name", interface_name,
Packit ae235b
                             NULL);
Packit ae235b
  if (initable != NULL)
Packit ae235b
    return G_DBUS_PROXY (initable);
Packit ae235b
  else
Packit ae235b
    return NULL;
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_proxy_get_connection:
Packit ae235b
 * @proxy: A #GDBusProxy.
Packit ae235b
 *
Packit ae235b
 * Gets the connection @proxy is for.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer none): A #GDBusConnection owned by @proxy. Do not free.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
GDBusConnection *
Packit ae235b
g_dbus_proxy_get_connection (GDBusProxy *proxy)
Packit ae235b
{
Packit ae235b
  g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
Packit ae235b
  return proxy->priv->connection;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_proxy_get_flags:
Packit ae235b
 * @proxy: A #GDBusProxy.
Packit ae235b
 *
Packit ae235b
 * Gets the flags that @proxy was constructed with.
Packit ae235b
 *
Packit ae235b
 * Returns: Flags from the #GDBusProxyFlags enumeration.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
GDBusProxyFlags
Packit ae235b
g_dbus_proxy_get_flags (GDBusProxy *proxy)
Packit ae235b
{
Packit ae235b
  g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), 0);
Packit ae235b
  return proxy->priv->flags;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_proxy_get_name:
Packit ae235b
 * @proxy: A #GDBusProxy.
Packit ae235b
 *
Packit ae235b
 * Gets the name that @proxy was constructed for.
Packit ae235b
 *
Packit ae235b
 * Returns: A string owned by @proxy. Do not free.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
const gchar *
Packit ae235b
g_dbus_proxy_get_name (GDBusProxy *proxy)
Packit ae235b
{
Packit ae235b
  g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
Packit ae235b
  return proxy->priv->name;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_proxy_get_name_owner:
Packit ae235b
 * @proxy: A #GDBusProxy.
Packit ae235b
 *
Packit ae235b
 * The unique name that owns the name that @proxy is for or %NULL if
Packit ae235b
 * no-one currently owns that name. You may connect to the
Packit ae235b
 * #GObject::notify signal to track changes to the
Packit ae235b
 * #GDBusProxy:g-name-owner property.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer full) (nullable): The name owner or %NULL if no name
Packit ae235b
 *    owner exists. Free with g_free().
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
gchar *
Packit ae235b
g_dbus_proxy_get_name_owner (GDBusProxy *proxy)
Packit ae235b
{
Packit ae235b
  gchar *ret;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
Packit ae235b
Packit ae235b
  G_LOCK (properties_lock);
Packit ae235b
  ret = g_strdup (proxy->priv->name_owner);
Packit ae235b
  G_UNLOCK (properties_lock);
Packit ae235b
  return ret;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_proxy_get_object_path:
Packit ae235b
 * @proxy: A #GDBusProxy.
Packit ae235b
 *
Packit ae235b
 * Gets the object path @proxy is for.
Packit ae235b
 *
Packit ae235b
 * Returns: A string owned by @proxy. Do not free.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
const gchar *
Packit ae235b
g_dbus_proxy_get_object_path (GDBusProxy *proxy)
Packit ae235b
{
Packit ae235b
  g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
Packit ae235b
  return proxy->priv->object_path;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_proxy_get_interface_name:
Packit ae235b
 * @proxy: A #GDBusProxy.
Packit ae235b
 *
Packit ae235b
 * Gets the D-Bus interface name @proxy is for.
Packit ae235b
 *
Packit ae235b
 * Returns: A string owned by @proxy. Do not free.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
const gchar *
Packit ae235b
g_dbus_proxy_get_interface_name (GDBusProxy *proxy)
Packit ae235b
{
Packit ae235b
  g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
Packit ae235b
  return proxy->priv->interface_name;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_proxy_get_default_timeout:
Packit ae235b
 * @proxy: A #GDBusProxy.
Packit ae235b
 *
Packit ae235b
 * Gets the timeout to use if -1 (specifying default timeout) is
Packit ae235b
 * passed as @timeout_msec in the g_dbus_proxy_call() and
Packit ae235b
 * g_dbus_proxy_call_sync() functions.
Packit ae235b
 *
Packit ae235b
 * See the #GDBusProxy:g-default-timeout property for more details.
Packit ae235b
 *
Packit ae235b
 * Returns: Timeout to use for @proxy.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
gint
Packit ae235b
g_dbus_proxy_get_default_timeout (GDBusProxy *proxy)
Packit ae235b
{
Packit ae235b
  gint ret;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), -1);
Packit ae235b
Packit ae235b
  G_LOCK (properties_lock);
Packit ae235b
  ret = proxy->priv->timeout_msec;
Packit ae235b
  G_UNLOCK (properties_lock);
Packit ae235b
  return ret;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_proxy_set_default_timeout:
Packit ae235b
 * @proxy: A #GDBusProxy.
Packit ae235b
 * @timeout_msec: Timeout in milliseconds.
Packit ae235b
 *
Packit ae235b
 * Sets the timeout to use if -1 (specifying default timeout) is
Packit ae235b
 * passed as @timeout_msec in the g_dbus_proxy_call() and
Packit ae235b
 * g_dbus_proxy_call_sync() functions.
Packit ae235b
 *
Packit ae235b
 * See the #GDBusProxy:g-default-timeout property for more details.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dbus_proxy_set_default_timeout (GDBusProxy *proxy,
Packit ae235b
                                  gint        timeout_msec)
Packit ae235b
{
Packit ae235b
  g_return_if_fail (G_IS_DBUS_PROXY (proxy));
Packit ae235b
  g_return_if_fail (timeout_msec == -1 || timeout_msec >= 0);
Packit ae235b
Packit ae235b
  G_LOCK (properties_lock);
Packit ae235b
Packit ae235b
  if (proxy->priv->timeout_msec != timeout_msec)
Packit ae235b
    {
Packit ae235b
      proxy->priv->timeout_msec = timeout_msec;
Packit ae235b
      G_UNLOCK (properties_lock);
Packit ae235b
Packit ae235b
      g_object_notify (G_OBJECT (proxy), "g-default-timeout");
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      G_UNLOCK (properties_lock);
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_proxy_get_interface_info:
Packit ae235b
 * @proxy: A #GDBusProxy
Packit ae235b
 *
Packit ae235b
 * Returns the #GDBusInterfaceInfo, if any, specifying the interface
Packit ae235b
 * that @proxy conforms to. See the #GDBusProxy:g-interface-info
Packit ae235b
 * property for more details.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer none) (nullable): A #GDBusInterfaceInfo or %NULL.
Packit ae235b
 *    Do not unref the returned object, it is owned by @proxy.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
GDBusInterfaceInfo *
Packit ae235b
g_dbus_proxy_get_interface_info (GDBusProxy *proxy)
Packit ae235b
{
Packit ae235b
  GDBusInterfaceInfo *ret;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
Packit ae235b
Packit ae235b
  G_LOCK (properties_lock);
Packit ae235b
  ret = proxy->priv->expected_interface;
Packit ae235b
  G_UNLOCK (properties_lock);
Packit ae235b
  /* FIXME: returning a borrowed ref with no guarantee that nobody will
Packit ae235b
   * call g_dbus_proxy_set_interface_info() and make it invalid...
Packit ae235b
   */
Packit ae235b
  return ret;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_proxy_set_interface_info:
Packit ae235b
 * @proxy: A #GDBusProxy
Packit ae235b
 * @info: (transfer none) (nullable): Minimum interface this proxy conforms to
Packit ae235b
 *    or %NULL to unset.
Packit ae235b
 *
Packit ae235b
 * Ensure that interactions with @proxy conform to the given
Packit ae235b
 * interface. See the #GDBusProxy:g-interface-info property for more
Packit ae235b
 * details.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dbus_proxy_set_interface_info (GDBusProxy         *proxy,
Packit ae235b
                                 GDBusInterfaceInfo *info)
Packit ae235b
{
Packit ae235b
  g_return_if_fail (G_IS_DBUS_PROXY (proxy));
Packit ae235b
  G_LOCK (properties_lock);
Packit ae235b
Packit ae235b
  if (proxy->priv->expected_interface != NULL)
Packit ae235b
    {
Packit ae235b
      g_dbus_interface_info_cache_release (proxy->priv->expected_interface);
Packit ae235b
      g_dbus_interface_info_unref (proxy->priv->expected_interface);
Packit ae235b
    }
Packit ae235b
  proxy->priv->expected_interface = info != NULL ? g_dbus_interface_info_ref (info) : NULL;
Packit ae235b
  if (proxy->priv->expected_interface != NULL)
Packit ae235b
    g_dbus_interface_info_cache_build (proxy->priv->expected_interface);
Packit ae235b
Packit ae235b
  G_UNLOCK (properties_lock);
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
static gboolean
Packit ae235b
maybe_split_method_name (const gchar  *method_name,
Packit ae235b
                         gchar       **out_interface_name,
Packit ae235b
                         const gchar **out_method_name)
Packit ae235b
{
Packit ae235b
  gboolean was_split;
Packit ae235b
Packit ae235b
  was_split = FALSE;
Packit ae235b
  g_assert (out_interface_name != NULL);
Packit ae235b
  g_assert (out_method_name != NULL);
Packit ae235b
  *out_interface_name = NULL;
Packit ae235b
  *out_method_name = NULL;
Packit ae235b
Packit ae235b
  if (strchr (method_name, '.') != NULL)
Packit ae235b
    {
Packit ae235b
      gchar *p;
Packit ae235b
      gchar *last_dot;
Packit ae235b
Packit ae235b
      p = g_strdup (method_name);
Packit ae235b
      last_dot = strrchr (p, '.');
Packit ae235b
      *last_dot = '\0';
Packit ae235b
Packit ae235b
      *out_interface_name = p;
Packit ae235b
      *out_method_name = last_dot + 1;
Packit ae235b
Packit ae235b
      was_split = TRUE;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  return was_split;
Packit ae235b
}
Packit ae235b
Packit ae235b
typedef struct
Packit ae235b
{
Packit ae235b
  GVariant *value;
Packit ae235b
#ifdef G_OS_UNIX
Packit ae235b
  GUnixFDList *fd_list;
Packit ae235b
#endif
Packit ae235b
} ReplyData;
Packit ae235b
Packit ae235b
static void
Packit ae235b
reply_data_free (ReplyData *data)
Packit ae235b
{
Packit ae235b
  g_variant_unref (data->value);
Packit ae235b
#ifdef G_OS_UNIX
Packit ae235b
  if (data->fd_list != NULL)
Packit ae235b
    g_object_unref (data->fd_list);
Packit ae235b
#endif
Packit ae235b
  g_slice_free (ReplyData, data);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
reply_cb (GDBusConnection *connection,
Packit ae235b
          GAsyncResult    *res,
Packit ae235b
          gpointer         user_data)
Packit ae235b
{
Packit ae235b
  GTask *task = user_data;
Packit ae235b
  GVariant *value;
Packit ae235b
  GError *error;
Packit ae235b
#ifdef G_OS_UNIX
Packit ae235b
  GUnixFDList *fd_list;
Packit ae235b
#endif
Packit ae235b
Packit ae235b
  error = NULL;
Packit ae235b
#ifdef G_OS_UNIX
Packit ae235b
  value = g_dbus_connection_call_with_unix_fd_list_finish (connection,
Packit ae235b
                                                           &fd_list,
Packit ae235b
                                                           res,
Packit ae235b
                                                           &error);
Packit ae235b
#else
Packit ae235b
  value = g_dbus_connection_call_finish (connection,
Packit ae235b
                                         res,
Packit ae235b
                                         &error);
Packit ae235b
#endif
Packit ae235b
  if (error != NULL)
Packit ae235b
    {
Packit ae235b
      g_task_return_error (task, error);
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      ReplyData *data;
Packit ae235b
      data = g_slice_new0 (ReplyData);
Packit ae235b
      data->value = value;
Packit ae235b
#ifdef G_OS_UNIX
Packit ae235b
      data->fd_list = fd_list;
Packit ae235b
#endif
Packit ae235b
      g_task_return_pointer (task, data, (GDestroyNotify) reply_data_free);
Packit ae235b
    }
Packit ae235b
Packit ae235b
  g_object_unref (task);
Packit ae235b
}
Packit ae235b
Packit ae235b
/* properties_lock must be held for as long as you will keep the
Packit ae235b
 * returned value
Packit ae235b
 */
Packit ae235b
static const GDBusMethodInfo *
Packit ae235b
lookup_method_info (GDBusProxy  *proxy,
Packit ae235b
                    const gchar *method_name)
Packit ae235b
{
Packit ae235b
  const GDBusMethodInfo *info = NULL;
Packit ae235b
Packit ae235b
  if (proxy->priv->expected_interface == NULL)
Packit ae235b
    goto out;
Packit ae235b
Packit ae235b
  info = g_dbus_interface_info_lookup_method (proxy->priv->expected_interface, method_name);
Packit ae235b
Packit ae235b
out:
Packit ae235b
  return info;
Packit ae235b
}
Packit ae235b
Packit ae235b
/* properties_lock must be held for as long as you will keep the
Packit ae235b
 * returned value
Packit ae235b
 */
Packit ae235b
static const gchar *
Packit ae235b
get_destination_for_call (GDBusProxy *proxy)
Packit ae235b
{
Packit ae235b
  const gchar *ret;
Packit ae235b
Packit ae235b
  ret = NULL;
Packit ae235b
Packit ae235b
  /* If proxy->priv->name is a unique name, then proxy->priv->name_owner
Packit ae235b
   * is never NULL and always the same as proxy->priv->name. We use this
Packit ae235b
   * knowledge to avoid checking if proxy->priv->name is a unique or
Packit ae235b
   * well-known name.
Packit ae235b
   */
Packit ae235b
  ret = proxy->priv->name_owner;
Packit ae235b
  if (ret != NULL)
Packit ae235b
    goto out;
Packit ae235b
Packit ae235b
  if (proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START)
Packit ae235b
    goto out;
Packit ae235b
Packit ae235b
  ret = proxy->priv->name;
Packit ae235b
Packit ae235b
 out:
Packit ae235b
  return ret;
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_dbus_proxy_call_internal (GDBusProxy          *proxy,
Packit ae235b
                            const gchar         *method_name,
Packit ae235b
                            GVariant            *parameters,
Packit ae235b
                            GDBusCallFlags       flags,
Packit ae235b
                            gint                 timeout_msec,
Packit ae235b
                            GUnixFDList         *fd_list,
Packit ae235b
                            GCancellable        *cancellable,
Packit ae235b
                            GAsyncReadyCallback  callback,
Packit ae235b
                            gpointer             user_data)
Packit ae235b
{
Packit ae235b
  GTask *task;
Packit ae235b
  gboolean was_split;
Packit ae235b
  gchar *split_interface_name;
Packit ae235b
  const gchar *split_method_name;
Packit ae235b
  const gchar *target_method_name;
Packit ae235b
  const gchar *target_interface_name;
Packit ae235b
  gchar *destination;
Packit ae235b
  GVariantType *reply_type;
Packit ae235b
  GAsyncReadyCallback my_callback;
Packit ae235b
Packit ae235b
  g_return_if_fail (G_IS_DBUS_PROXY (proxy));
Packit ae235b
  g_return_if_fail (g_dbus_is_member_name (method_name) || g_dbus_is_interface_name (method_name));
Packit ae235b
  g_return_if_fail (parameters == NULL || g_variant_is_of_type (parameters, G_VARIANT_TYPE_TUPLE));
Packit ae235b
  g_return_if_fail (timeout_msec == -1 || timeout_msec >= 0);
Packit ae235b
#ifdef G_OS_UNIX
Packit ae235b
  g_return_if_fail (fd_list == NULL || G_IS_UNIX_FD_LIST (fd_list));
Packit ae235b
#else
Packit ae235b
  g_return_if_fail (fd_list == NULL);
Packit ae235b
#endif
Packit ae235b
Packit ae235b
  reply_type = NULL;
Packit ae235b
  split_interface_name = NULL;
Packit ae235b
Packit ae235b
  /* g_dbus_connection_call() is optimised for the case of a NULL
Packit ae235b
   * callback.  If we get a NULL callback from our user then make sure
Packit ae235b
   * we pass along a NULL callback for ourselves as well.
Packit ae235b
   */
Packit ae235b
  if (callback != NULL)
Packit ae235b
    {
Packit ae235b
      my_callback = (GAsyncReadyCallback) reply_cb;
Packit ae235b
      task = g_task_new (proxy, cancellable, callback, user_data);
Packit ae235b
      g_task_set_source_tag (task, g_dbus_proxy_call_internal);
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      my_callback = NULL;
Packit ae235b
      task = NULL;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  G_LOCK (properties_lock);
Packit ae235b
Packit ae235b
  was_split = maybe_split_method_name (method_name, &split_interface_name, &split_method_name);
Packit ae235b
  target_method_name = was_split ? split_method_name : method_name;
Packit ae235b
  target_interface_name = was_split ? split_interface_name : proxy->priv->interface_name;
Packit ae235b
Packit ae235b
  /* Warn if method is unexpected (cf. :g-interface-info) */
Packit ae235b
  if (!was_split)
Packit ae235b
    {
Packit ae235b
      const GDBusMethodInfo *expected_method_info;
Packit ae235b
      expected_method_info = lookup_method_info (proxy, target_method_name);
Packit ae235b
      if (expected_method_info != NULL)
Packit ae235b
        reply_type = _g_dbus_compute_complete_signature (expected_method_info->out_args);
Packit ae235b
    }
Packit ae235b
Packit ae235b
  destination = NULL;
Packit ae235b
  if (proxy->priv->name != NULL)
Packit ae235b
    {
Packit ae235b
      destination = g_strdup (get_destination_for_call (proxy));
Packit ae235b
      if (destination == NULL)
Packit ae235b
        {
Packit ae235b
          if (task != NULL)
Packit ae235b
            {
Packit ae235b
              g_task_return_new_error (task,
Packit ae235b
                                       G_IO_ERROR,
Packit ae235b
                                       G_IO_ERROR_FAILED,
Packit ae235b
                                       _("Cannot invoke method; proxy is for a well-known name without an owner and proxy was constructed with the G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START flag"));
Packit ae235b
              g_object_unref (task);
Packit ae235b
            }
Packit ae235b
          G_UNLOCK (properties_lock);
Packit ae235b
          goto out;
Packit ae235b
        }
Packit ae235b
    }
Packit ae235b
Packit ae235b
  G_UNLOCK (properties_lock);
Packit ae235b
Packit ae235b
#ifdef G_OS_UNIX
Packit ae235b
  g_dbus_connection_call_with_unix_fd_list (proxy->priv->connection,
Packit ae235b
                                            destination,
Packit ae235b
                                            proxy->priv->object_path,
Packit ae235b
                                            target_interface_name,
Packit ae235b
                                            target_method_name,
Packit ae235b
                                            parameters,
Packit ae235b
                                            reply_type,
Packit ae235b
                                            flags,
Packit ae235b
                                            timeout_msec == -1 ? proxy->priv->timeout_msec : timeout_msec,
Packit ae235b
                                            fd_list,
Packit ae235b
                                            cancellable,
Packit ae235b
                                            my_callback,
Packit ae235b
                                            task);
Packit ae235b
#else
Packit ae235b
  g_dbus_connection_call (proxy->priv->connection,
Packit ae235b
                          destination,
Packit ae235b
                          proxy->priv->object_path,
Packit ae235b
                          target_interface_name,
Packit ae235b
                          target_method_name,
Packit ae235b
                          parameters,
Packit ae235b
                          reply_type,
Packit ae235b
                          flags,
Packit ae235b
                          timeout_msec == -1 ? proxy->priv->timeout_msec : timeout_msec,
Packit ae235b
                          cancellable,
Packit ae235b
                          my_callback,
Packit ae235b
                          task);
Packit ae235b
#endif
Packit ae235b
Packit ae235b
 out:
Packit ae235b
  if (reply_type != NULL)
Packit ae235b
    g_variant_type_free (reply_type);
Packit ae235b
Packit ae235b
  g_free (destination);
Packit ae235b
  g_free (split_interface_name);
Packit ae235b
}
Packit ae235b
Packit ae235b
static GVariant *
Packit ae235b
g_dbus_proxy_call_finish_internal (GDBusProxy    *proxy,
Packit ae235b
                                   GUnixFDList  **out_fd_list,
Packit ae235b
                                   GAsyncResult  *res,
Packit ae235b
                                   GError       **error)
Packit ae235b
{
Packit ae235b
  GVariant *value;
Packit ae235b
  ReplyData *data;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
Packit ae235b
  g_return_val_if_fail (g_task_is_valid (res, proxy), NULL);
Packit ae235b
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
Packit ae235b
Packit ae235b
  value = NULL;
Packit ae235b
Packit ae235b
  data = g_task_propagate_pointer (G_TASK (res), error);
Packit ae235b
  if (!data)
Packit ae235b
    goto out;
Packit ae235b
Packit ae235b
  value = g_variant_ref (data->value);
Packit ae235b
#ifdef G_OS_UNIX
Packit ae235b
  if (out_fd_list != NULL)
Packit ae235b
    *out_fd_list = data->fd_list != NULL ? g_object_ref (data->fd_list) : NULL;
Packit ae235b
#endif
Packit ae235b
  reply_data_free (data);
Packit ae235b
Packit ae235b
 out:
Packit ae235b
  return value;
Packit ae235b
}
Packit ae235b
Packit ae235b
static GVariant *
Packit ae235b
g_dbus_proxy_call_sync_internal (GDBusProxy      *proxy,
Packit ae235b
                                 const gchar     *method_name,
Packit ae235b
                                 GVariant        *parameters,
Packit ae235b
                                 GDBusCallFlags   flags,
Packit ae235b
                                 gint             timeout_msec,
Packit ae235b
                                 GUnixFDList     *fd_list,
Packit ae235b
                                 GUnixFDList    **out_fd_list,
Packit ae235b
                                 GCancellable    *cancellable,
Packit ae235b
                                 GError         **error)
Packit ae235b
{
Packit ae235b
  GVariant *ret;
Packit ae235b
  gboolean was_split;
Packit ae235b
  gchar *split_interface_name;
Packit ae235b
  const gchar *split_method_name;
Packit ae235b
  const gchar *target_method_name;
Packit ae235b
  const gchar *target_interface_name;
Packit ae235b
  gchar *destination;
Packit ae235b
  GVariantType *reply_type;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
Packit ae235b
  g_return_val_if_fail (g_dbus_is_member_name (method_name) || g_dbus_is_interface_name (method_name), NULL);
Packit ae235b
  g_return_val_if_fail (parameters == NULL || g_variant_is_of_type (parameters, G_VARIANT_TYPE_TUPLE), NULL);
Packit ae235b
  g_return_val_if_fail (timeout_msec == -1 || timeout_msec >= 0, NULL);
Packit ae235b
#ifdef G_OS_UNIX
Packit ae235b
  g_return_val_if_fail (fd_list == NULL || G_IS_UNIX_FD_LIST (fd_list), NULL);
Packit ae235b
#else
Packit ae235b
  g_return_val_if_fail (fd_list == NULL, NULL);
Packit ae235b
#endif
Packit ae235b
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
Packit ae235b
Packit ae235b
  reply_type = NULL;
Packit ae235b
Packit ae235b
  G_LOCK (properties_lock);
Packit ae235b
Packit ae235b
  was_split = maybe_split_method_name (method_name, &split_interface_name, &split_method_name);
Packit ae235b
  target_method_name = was_split ? split_method_name : method_name;
Packit ae235b
  target_interface_name = was_split ? split_interface_name : proxy->priv->interface_name;
Packit ae235b
Packit ae235b
  /* Warn if method is unexpected (cf. :g-interface-info) */
Packit ae235b
  if (!was_split)
Packit ae235b
    {
Packit ae235b
      const GDBusMethodInfo *expected_method_info;
Packit ae235b
      expected_method_info = lookup_method_info (proxy, target_method_name);
Packit ae235b
      if (expected_method_info != NULL)
Packit ae235b
        reply_type = _g_dbus_compute_complete_signature (expected_method_info->out_args);
Packit ae235b
    }
Packit ae235b
Packit ae235b
  destination = NULL;
Packit ae235b
  if (proxy->priv->name != NULL)
Packit ae235b
    {
Packit ae235b
      destination = g_strdup (get_destination_for_call (proxy));
Packit ae235b
      if (destination == NULL)
Packit ae235b
        {
Packit ae235b
          g_set_error_literal (error,
Packit ae235b
                               G_IO_ERROR,
Packit ae235b
                               G_IO_ERROR_FAILED,
Packit ae235b
                               _("Cannot invoke method; proxy is for a well-known name without an owner and proxy was constructed with the G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START flag"));
Packit ae235b
          ret = NULL;
Packit ae235b
          G_UNLOCK (properties_lock);
Packit ae235b
          goto out;
Packit ae235b
        }
Packit ae235b
    }
Packit ae235b
Packit ae235b
  G_UNLOCK (properties_lock);
Packit ae235b
Packit ae235b
#ifdef G_OS_UNIX
Packit ae235b
  ret = g_dbus_connection_call_with_unix_fd_list_sync (proxy->priv->connection,
Packit ae235b
                                                       destination,
Packit ae235b
                                                       proxy->priv->object_path,
Packit ae235b
                                                       target_interface_name,
Packit ae235b
                                                       target_method_name,
Packit ae235b
                                                       parameters,
Packit ae235b
                                                       reply_type,
Packit ae235b
                                                       flags,
Packit ae235b
                                                       timeout_msec == -1 ? proxy->priv->timeout_msec : timeout_msec,
Packit ae235b
                                                       fd_list,
Packit ae235b
                                                       out_fd_list,
Packit ae235b
                                                       cancellable,
Packit ae235b
                                                       error);
Packit ae235b
#else
Packit ae235b
  ret = g_dbus_connection_call_sync (proxy->priv->connection,
Packit ae235b
                                     destination,
Packit ae235b
                                     proxy->priv->object_path,
Packit ae235b
                                     target_interface_name,
Packit ae235b
                                     target_method_name,
Packit ae235b
                                     parameters,
Packit ae235b
                                     reply_type,
Packit ae235b
                                     flags,
Packit ae235b
                                     timeout_msec == -1 ? proxy->priv->timeout_msec : timeout_msec,
Packit ae235b
                                     cancellable,
Packit ae235b
                                     error);
Packit ae235b
#endif
Packit ae235b
Packit ae235b
 out:
Packit ae235b
  if (reply_type != NULL)
Packit ae235b
    g_variant_type_free (reply_type);
Packit ae235b
Packit ae235b
  g_free (destination);
Packit ae235b
  g_free (split_interface_name);
Packit ae235b
Packit ae235b
  return ret;
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_proxy_call:
Packit ae235b
 * @proxy: A #GDBusProxy.
Packit ae235b
 * @method_name: Name of method to invoke.
Packit ae235b
 * @parameters: (nullable): A #GVariant tuple with parameters for the signal or %NULL if not passing parameters.
Packit ae235b
 * @flags: Flags from the #GDBusCallFlags enumeration.
Packit ae235b
 * @timeout_msec: The timeout in milliseconds (with %G_MAXINT meaning
Packit ae235b
 *                "infinite") or -1 to use the proxy default timeout.
Packit ae235b
 * @cancellable: (nullable): A #GCancellable or %NULL.
Packit ae235b
 * @callback: (nullable): A #GAsyncReadyCallback to call when the request is satisfied or %NULL if you don't
Packit ae235b
 * care about the result of the method invocation.
Packit ae235b
 * @user_data: The data to pass to @callback.
Packit ae235b
 *
Packit ae235b
 * Asynchronously invokes the @method_name method on @proxy.
Packit ae235b
 *
Packit ae235b
 * If @method_name contains any dots, then @name is split into interface and
Packit ae235b
 * method name parts. This allows using @proxy for invoking methods on
Packit ae235b
 * other interfaces.
Packit ae235b
 *
Packit ae235b
 * If the #GDBusConnection associated with @proxy is closed then
Packit ae235b
 * the operation will fail with %G_IO_ERROR_CLOSED. If
Packit ae235b
 * @cancellable is canceled, the operation will fail with
Packit ae235b
 * %G_IO_ERROR_CANCELLED. If @parameters contains a value not
Packit ae235b
 * compatible with the D-Bus protocol, the operation fails with
Packit ae235b
 * %G_IO_ERROR_INVALID_ARGUMENT.
Packit ae235b
 *
Packit ae235b
 * If the @parameters #GVariant is floating, it is consumed. This allows
Packit ae235b
 * convenient 'inline' use of g_variant_new(), e.g.:
Packit ae235b
 * |[
Packit ae235b
 *  g_dbus_proxy_call (proxy,
Packit ae235b
 *                     "TwoStrings",
Packit ae235b
 *                     g_variant_new ("(ss)",
Packit ae235b
 *                                    "Thing One",
Packit ae235b
 *                                    "Thing Two"),
Packit ae235b
 *                     G_DBUS_CALL_FLAGS_NONE,
Packit ae235b
 *                     -1,
Packit ae235b
 *                     NULL,
Packit ae235b
 *                     (GAsyncReadyCallback) two_strings_done,
Packit ae235b
 *                     &data);
Packit ae235b
 * ]|
Packit ae235b
 *
Packit ae235b
 * If @proxy has an expected interface (see
Packit ae235b
 * #GDBusProxy:g-interface-info) and @method_name is referenced by it,
Packit ae235b
 * then the return value is checked against the return type.
Packit ae235b
 *
Packit ae235b
 * This is an asynchronous method. When the operation is finished,
Packit ae235b
 * @callback will be invoked in the
Packit ae235b
 * [thread-default main context][g-main-context-push-thread-default]
Packit ae235b
 * of the thread you are calling this method from.
Packit ae235b
 * You can then call g_dbus_proxy_call_finish() to get the result of
Packit ae235b
 * the operation. See g_dbus_proxy_call_sync() for the synchronous
Packit ae235b
 * version of this method.
Packit ae235b
 *
Packit ae235b
 * If @callback is %NULL then the D-Bus method call message will be sent with
Packit ae235b
 * the %G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED flag set.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dbus_proxy_call (GDBusProxy          *proxy,
Packit ae235b
                   const gchar         *method_name,
Packit ae235b
                   GVariant            *parameters,
Packit ae235b
                   GDBusCallFlags       flags,
Packit ae235b
                   gint                 timeout_msec,
Packit ae235b
                   GCancellable        *cancellable,
Packit ae235b
                   GAsyncReadyCallback  callback,
Packit ae235b
                   gpointer             user_data)
Packit ae235b
{
Packit ae235b
  g_dbus_proxy_call_internal (proxy, method_name, parameters, flags, timeout_msec, NULL, cancellable, callback, user_data);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_proxy_call_finish:
Packit ae235b
 * @proxy: A #GDBusProxy.
Packit ae235b
 * @res: A #GAsyncResult obtained from the #GAsyncReadyCallback passed to g_dbus_proxy_call().
Packit ae235b
 * @error: Return location for error or %NULL.
Packit ae235b
 *
Packit ae235b
 * Finishes an operation started with g_dbus_proxy_call().
Packit ae235b
 *
Packit ae235b
 * Returns: %NULL if @error is set. Otherwise a #GVariant tuple with
Packit ae235b
 * return values. Free with g_variant_unref().
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
GVariant *
Packit ae235b
g_dbus_proxy_call_finish (GDBusProxy    *proxy,
Packit ae235b
                          GAsyncResult  *res,
Packit ae235b
                          GError       **error)
Packit ae235b
{
Packit ae235b
  return g_dbus_proxy_call_finish_internal (proxy, NULL, res, error);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_proxy_call_sync:
Packit ae235b
 * @proxy: A #GDBusProxy.
Packit ae235b
 * @method_name: Name of method to invoke.
Packit ae235b
 * @parameters: (nullable): A #GVariant tuple with parameters for the signal
Packit ae235b
 *              or %NULL if not passing parameters.
Packit ae235b
 * @flags: Flags from the #GDBusCallFlags enumeration.
Packit ae235b
 * @timeout_msec: The timeout in milliseconds (with %G_MAXINT meaning
Packit ae235b
 *                "infinite") or -1 to use the proxy default timeout.
Packit ae235b
 * @cancellable: (nullable): A #GCancellable or %NULL.
Packit ae235b
 * @error: Return location for error or %NULL.
Packit ae235b
 *
Packit ae235b
 * Synchronously invokes the @method_name method on @proxy.
Packit ae235b
 *
Packit ae235b
 * If @method_name contains any dots, then @name is split into interface and
Packit ae235b
 * method name parts. This allows using @proxy for invoking methods on
Packit ae235b
 * other interfaces.
Packit ae235b
 *
Packit ae235b
 * If the #GDBusConnection associated with @proxy is disconnected then
Packit ae235b
 * the operation will fail with %G_IO_ERROR_CLOSED. If
Packit ae235b
 * @cancellable is canceled, the operation will fail with
Packit ae235b
 * %G_IO_ERROR_CANCELLED. If @parameters contains a value not
Packit ae235b
 * compatible with the D-Bus protocol, the operation fails with
Packit ae235b
 * %G_IO_ERROR_INVALID_ARGUMENT.
Packit ae235b
 *
Packit ae235b
 * If the @parameters #GVariant is floating, it is consumed. This allows
Packit ae235b
 * convenient 'inline' use of g_variant_new(), e.g.:
Packit ae235b
 * |[
Packit ae235b
 *  g_dbus_proxy_call_sync (proxy,
Packit ae235b
 *                          "TwoStrings",
Packit ae235b
 *                          g_variant_new ("(ss)",
Packit ae235b
 *                                         "Thing One",
Packit ae235b
 *                                         "Thing Two"),
Packit ae235b
 *                          G_DBUS_CALL_FLAGS_NONE,
Packit ae235b
 *                          -1,
Packit ae235b
 *                          NULL,
Packit ae235b
 *                          &error);
Packit ae235b
 * ]|
Packit ae235b
 *
Packit ae235b
 * The calling thread is blocked until a reply is received. See
Packit ae235b
 * g_dbus_proxy_call() for the asynchronous version of this
Packit ae235b
 * method.
Packit ae235b
 *
Packit ae235b
 * If @proxy has an expected interface (see
Packit ae235b
 * #GDBusProxy:g-interface-info) and @method_name is referenced by it,
Packit ae235b
 * then the return value is checked against the return type.
Packit ae235b
 *
Packit ae235b
 * Returns: %NULL if @error is set. Otherwise a #GVariant tuple with
Packit ae235b
 * return values. Free with g_variant_unref().
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
GVariant *
Packit ae235b
g_dbus_proxy_call_sync (GDBusProxy      *proxy,
Packit ae235b
                        const gchar     *method_name,
Packit ae235b
                        GVariant        *parameters,
Packit ae235b
                        GDBusCallFlags   flags,
Packit ae235b
                        gint             timeout_msec,
Packit ae235b
                        GCancellable    *cancellable,
Packit ae235b
                        GError         **error)
Packit ae235b
{
Packit ae235b
  return g_dbus_proxy_call_sync_internal (proxy, method_name, parameters, flags, timeout_msec, NULL, NULL, cancellable, error);
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
#ifdef G_OS_UNIX
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_proxy_call_with_unix_fd_list:
Packit ae235b
 * @proxy: A #GDBusProxy.
Packit ae235b
 * @method_name: Name of method to invoke.
Packit ae235b
 * @parameters: (nullable): A #GVariant tuple with parameters for the signal or %NULL if not passing parameters.
Packit ae235b
 * @flags: Flags from the #GDBusCallFlags enumeration.
Packit ae235b
 * @timeout_msec: The timeout in milliseconds (with %G_MAXINT meaning
Packit ae235b
 *                "infinite") or -1 to use the proxy default timeout.
Packit ae235b
 * @fd_list: (nullable): A #GUnixFDList or %NULL.
Packit ae235b
 * @cancellable: (nullable): A #GCancellable or %NULL.
Packit ae235b
 * @callback: (nullable): A #GAsyncReadyCallback to call when the request is satisfied or %NULL if you don't
Packit ae235b
 * care about the result of the method invocation.
Packit ae235b
 * @user_data: The data to pass to @callback.
Packit ae235b
 *
Packit ae235b
 * Like g_dbus_proxy_call() but also takes a #GUnixFDList object.
Packit ae235b
 *
Packit ae235b
 * This method is only available on UNIX.
Packit ae235b
 *
Packit ae235b
 * Since: 2.30
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dbus_proxy_call_with_unix_fd_list (GDBusProxy          *proxy,
Packit ae235b
                                     const gchar         *method_name,
Packit ae235b
                                     GVariant            *parameters,
Packit ae235b
                                     GDBusCallFlags       flags,
Packit ae235b
                                     gint                 timeout_msec,
Packit ae235b
                                     GUnixFDList         *fd_list,
Packit ae235b
                                     GCancellable        *cancellable,
Packit ae235b
                                     GAsyncReadyCallback  callback,
Packit ae235b
                                     gpointer             user_data)
Packit ae235b
{
Packit ae235b
  g_dbus_proxy_call_internal (proxy, method_name, parameters, flags, timeout_msec, fd_list, cancellable, callback, user_data);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_proxy_call_with_unix_fd_list_finish:
Packit ae235b
 * @proxy: A #GDBusProxy.
Packit ae235b
 * @out_fd_list: (out) (optional): Return location for a #GUnixFDList or %NULL.
Packit ae235b
 * @res: A #GAsyncResult obtained from the #GAsyncReadyCallback passed to g_dbus_proxy_call_with_unix_fd_list().
Packit ae235b
 * @error: Return location for error or %NULL.
Packit ae235b
 *
Packit ae235b
 * Finishes an operation started with g_dbus_proxy_call_with_unix_fd_list().
Packit ae235b
 *
Packit ae235b
 * Returns: %NULL if @error is set. Otherwise a #GVariant tuple with
Packit ae235b
 * return values. Free with g_variant_unref().
Packit ae235b
 *
Packit ae235b
 * Since: 2.30
Packit ae235b
 */
Packit ae235b
GVariant *
Packit ae235b
g_dbus_proxy_call_with_unix_fd_list_finish (GDBusProxy    *proxy,
Packit ae235b
                                            GUnixFDList  **out_fd_list,
Packit ae235b
                                            GAsyncResult  *res,
Packit ae235b
                                            GError       **error)
Packit ae235b
{
Packit ae235b
  return g_dbus_proxy_call_finish_internal (proxy, out_fd_list, res, error);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_proxy_call_with_unix_fd_list_sync:
Packit ae235b
 * @proxy: A #GDBusProxy.
Packit ae235b
 * @method_name: Name of method to invoke.
Packit ae235b
 * @parameters: (nullable): A #GVariant tuple with parameters for the signal
Packit ae235b
 *              or %NULL if not passing parameters.
Packit ae235b
 * @flags: Flags from the #GDBusCallFlags enumeration.
Packit ae235b
 * @timeout_msec: The timeout in milliseconds (with %G_MAXINT meaning
Packit ae235b
 *                "infinite") or -1 to use the proxy default timeout.
Packit ae235b
 * @fd_list: (nullable): A #GUnixFDList or %NULL.
Packit ae235b
 * @out_fd_list: (out) (optional): Return location for a #GUnixFDList or %NULL.
Packit ae235b
 * @cancellable: (nullable): A #GCancellable or %NULL.
Packit ae235b
 * @error: Return location for error or %NULL.
Packit ae235b
 *
Packit ae235b
 * Like g_dbus_proxy_call_sync() but also takes and returns #GUnixFDList objects.
Packit ae235b
 *
Packit ae235b
 * This method is only available on UNIX.
Packit ae235b
 *
Packit ae235b
 * Returns: %NULL if @error is set. Otherwise a #GVariant tuple with
Packit ae235b
 * return values. Free with g_variant_unref().
Packit ae235b
 *
Packit ae235b
 * Since: 2.30
Packit ae235b
 */
Packit ae235b
GVariant *
Packit ae235b
g_dbus_proxy_call_with_unix_fd_list_sync (GDBusProxy      *proxy,
Packit ae235b
                                          const gchar     *method_name,
Packit ae235b
                                          GVariant        *parameters,
Packit ae235b
                                          GDBusCallFlags   flags,
Packit ae235b
                                          gint             timeout_msec,
Packit ae235b
                                          GUnixFDList     *fd_list,
Packit ae235b
                                          GUnixFDList    **out_fd_list,
Packit ae235b
                                          GCancellable    *cancellable,
Packit ae235b
                                          GError         **error)
Packit ae235b
{
Packit ae235b
  return g_dbus_proxy_call_sync_internal (proxy, method_name, parameters, flags, timeout_msec, fd_list, out_fd_list, cancellable, error);
Packit ae235b
}
Packit ae235b
Packit ae235b
#endif /* G_OS_UNIX */
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
static GDBusInterfaceInfo *
Packit ae235b
_g_dbus_proxy_get_info (GDBusInterface *interface)
Packit ae235b
{
Packit ae235b
  GDBusProxy *proxy = G_DBUS_PROXY (interface);
Packit ae235b
  return g_dbus_proxy_get_interface_info (proxy);
Packit ae235b
}
Packit ae235b
Packit ae235b
static GDBusObject *
Packit ae235b
_g_dbus_proxy_get_object (GDBusInterface *interface)
Packit ae235b
{
Packit ae235b
  GDBusProxy *proxy = G_DBUS_PROXY (interface);
Packit ae235b
  return proxy->priv->object;
Packit ae235b
}
Packit ae235b
Packit ae235b
static GDBusObject *
Packit ae235b
_g_dbus_proxy_dup_object (GDBusInterface *interface)
Packit ae235b
{
Packit ae235b
  GDBusProxy *proxy = G_DBUS_PROXY (interface);
Packit ae235b
  GDBusObject *ret = NULL;
Packit ae235b
Packit ae235b
  G_LOCK (properties_lock);
Packit ae235b
  if (proxy->priv->object != NULL)
Packit ae235b
    ret = g_object_ref (proxy->priv->object);
Packit ae235b
  G_UNLOCK (properties_lock);
Packit ae235b
  return ret;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
_g_dbus_proxy_set_object (GDBusInterface *interface,
Packit ae235b
                          GDBusObject    *object)
Packit ae235b
{
Packit ae235b
  GDBusProxy *proxy = G_DBUS_PROXY (interface);
Packit ae235b
  G_LOCK (properties_lock);
Packit ae235b
  if (proxy->priv->object != NULL)
Packit ae235b
    g_object_remove_weak_pointer (G_OBJECT (proxy->priv->object), (gpointer *) &proxy->priv->object);
Packit ae235b
  proxy->priv->object = object;
Packit ae235b
  if (proxy->priv->object != NULL)
Packit ae235b
    g_object_add_weak_pointer (G_OBJECT (proxy->priv->object), (gpointer *) &proxy->priv->object);
Packit ae235b
  G_UNLOCK (properties_lock);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
dbus_interface_iface_init (GDBusInterfaceIface *dbus_interface_iface)
Packit ae235b
{
Packit ae235b
  dbus_interface_iface->get_info   = _g_dbus_proxy_get_info;
Packit ae235b
  dbus_interface_iface->get_object = _g_dbus_proxy_get_object;
Packit ae235b
  dbus_interface_iface->dup_object = _g_dbus_proxy_dup_object;
Packit ae235b
  dbus_interface_iface->set_object = _g_dbus_proxy_set_object;
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */