Blame gio/gdbusinterfaceskeleton.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 "gdbusinterface.h"
Packit ae235b
#include "gdbusinterfaceskeleton.h"
Packit ae235b
#include "gdbusobjectskeleton.h"
Packit ae235b
#include "gioenumtypes.h"
Packit ae235b
#include "gdbusprivate.h"
Packit ae235b
#include "gdbusmethodinvocation.h"
Packit ae235b
#include "gdbusconnection.h"
Packit ae235b
#include "gtask.h"
Packit ae235b
#include "gioerror.h"
Packit ae235b
Packit ae235b
#include "glibintl.h"
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * SECTION:gdbusinterfaceskeleton
Packit ae235b
 * @short_description: Service-side D-Bus interface
Packit ae235b
 * @include: gio/gio.h
Packit ae235b
 *
Packit ae235b
 * Abstract base class for D-Bus interfaces on the service side.
Packit ae235b
 */
Packit ae235b
Packit ae235b
struct _GDBusInterfaceSkeletonPrivate
Packit ae235b
{
Packit ae235b
  GMutex                      lock;
Packit ae235b
Packit ae235b
  GDBusObject                *object;
Packit ae235b
  GDBusInterfaceSkeletonFlags flags;
Packit ae235b
Packit ae235b
  GSList                     *connections;   /* List of ConnectionData */
Packit ae235b
  gchar                      *object_path;   /* The object path for this skeleton */
Packit ae235b
  GDBusInterfaceVTable       *hooked_vtable;
Packit ae235b
};
Packit ae235b
Packit ae235b
typedef struct
Packit ae235b
{
Packit ae235b
  GDBusConnection *connection;
Packit ae235b
  guint            registration_id;
Packit ae235b
} ConnectionData;
Packit ae235b
Packit ae235b
enum
Packit ae235b
{
Packit ae235b
  G_AUTHORIZE_METHOD_SIGNAL,
Packit ae235b
  LAST_SIGNAL
Packit ae235b
};
Packit ae235b
Packit ae235b
enum
Packit ae235b
{
Packit ae235b
  PROP_0,
Packit ae235b
  PROP_G_FLAGS
Packit ae235b
};
Packit ae235b
Packit ae235b
static guint signals[LAST_SIGNAL] = {0};
Packit ae235b
Packit ae235b
static void     dbus_interface_interface_init                      (GDBusInterfaceIface    *iface);
Packit ae235b
Packit ae235b
static void     set_object_path_locked                             (GDBusInterfaceSkeleton *interface_,
Packit ae235b
                                                                    const gchar            *object_path);
Packit ae235b
static void     remove_connection_locked                           (GDBusInterfaceSkeleton *interface_,
Packit ae235b
                                                                    GDBusConnection        *connection);
Packit ae235b
static void     skeleton_intercept_handle_method_call              (GDBusConnection        *connection,
Packit ae235b
                                                                    const gchar            *sender,
Packit ae235b
                                                                    const gchar            *object_path,
Packit ae235b
                                                                    const gchar            *interface_name,
Packit ae235b
                                                                    const gchar            *method_name,
Packit ae235b
                                                                    GVariant               *parameters,
Packit ae235b
                                                                    GDBusMethodInvocation  *invocation,
Packit ae235b
                                                                    gpointer                user_data);
Packit ae235b
Packit ae235b
Packit ae235b
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GDBusInterfaceSkeleton, g_dbus_interface_skeleton, G_TYPE_OBJECT,
Packit ae235b
                                  G_ADD_PRIVATE (GDBusInterfaceSkeleton)
Packit ae235b
                                  G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_INTERFACE, dbus_interface_interface_init))
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_dbus_interface_skeleton_finalize (GObject *object)
Packit ae235b
{
Packit ae235b
  GDBusInterfaceSkeleton *interface = G_DBUS_INTERFACE_SKELETON (object);
Packit ae235b
Packit ae235b
  /* Hold the lock just in case any code we call verifies that the lock is held */
Packit ae235b
  g_mutex_lock (&interface->priv->lock);
Packit ae235b
Packit ae235b
  /* unexport from all connections if we're exported anywhere */
Packit ae235b
  while (interface->priv->connections != NULL)
Packit ae235b
    {
Packit ae235b
      ConnectionData *data = interface->priv->connections->data;
Packit ae235b
      remove_connection_locked (interface, data->connection);
Packit ae235b
    }
Packit ae235b
Packit ae235b
  set_object_path_locked (interface, NULL);
Packit ae235b
Packit ae235b
  g_mutex_unlock (&interface->priv->lock);
Packit ae235b
Packit ae235b
  g_free (interface->priv->hooked_vtable);
Packit ae235b
Packit ae235b
  if (interface->priv->object != NULL)
Packit ae235b
    g_object_remove_weak_pointer (G_OBJECT (interface->priv->object), (gpointer *) &interface->priv->object);
Packit ae235b
Packit ae235b
  g_mutex_clear (&interface->priv->lock);
Packit ae235b
Packit ae235b
  G_OBJECT_CLASS (g_dbus_interface_skeleton_parent_class)->finalize (object);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_dbus_interface_skeleton_get_property (GObject      *object,
Packit ae235b
                                        guint         prop_id,
Packit ae235b
                                        GValue       *value,
Packit ae235b
                                        GParamSpec   *pspec)
Packit ae235b
{
Packit ae235b
  GDBusInterfaceSkeleton *interface = G_DBUS_INTERFACE_SKELETON (object);
Packit ae235b
Packit ae235b
  switch (prop_id)
Packit ae235b
    {
Packit ae235b
    case PROP_G_FLAGS:
Packit ae235b
      g_value_set_flags (value, g_dbus_interface_skeleton_get_flags (interface));
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_interface_skeleton_set_property (GObject      *object,
Packit ae235b
                                        guint         prop_id,
Packit ae235b
                                        const GValue *value,
Packit ae235b
                                        GParamSpec   *pspec)
Packit ae235b
{
Packit ae235b
  GDBusInterfaceSkeleton *interface = G_DBUS_INTERFACE_SKELETON (object);
Packit ae235b
Packit ae235b
  switch (prop_id)
Packit ae235b
    {
Packit ae235b
    case PROP_G_FLAGS:
Packit ae235b
      g_dbus_interface_skeleton_set_flags (interface, g_value_get_flags (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 gboolean
Packit ae235b
g_dbus_interface_skeleton_g_authorize_method_default (GDBusInterfaceSkeleton    *interface,
Packit ae235b
                                                      GDBusMethodInvocation *invocation)
Packit ae235b
{
Packit ae235b
  return TRUE;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_dbus_interface_skeleton_class_init (GDBusInterfaceSkeletonClass *klass)
Packit ae235b
{
Packit ae235b
  GObjectClass *gobject_class;
Packit ae235b
Packit ae235b
  gobject_class = G_OBJECT_CLASS (klass);
Packit ae235b
  gobject_class->finalize     = g_dbus_interface_skeleton_finalize;
Packit ae235b
  gobject_class->set_property = g_dbus_interface_skeleton_set_property;
Packit ae235b
  gobject_class->get_property = g_dbus_interface_skeleton_get_property;
Packit ae235b
Packit ae235b
  klass->g_authorize_method = g_dbus_interface_skeleton_g_authorize_method_default;
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GDBusInterfaceSkeleton:g-flags:
Packit ae235b
   *
Packit ae235b
   * Flags from the #GDBusInterfaceSkeletonFlags enumeration.
Packit ae235b
   *
Packit ae235b
   * Since: 2.30
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
                                                       "g-flags",
Packit ae235b
                                                       "Flags for the interface skeleton",
Packit ae235b
                                                       G_TYPE_DBUS_INTERFACE_SKELETON_FLAGS,
Packit ae235b
                                                       G_DBUS_INTERFACE_SKELETON_FLAGS_NONE,
Packit ae235b
                                                       G_PARAM_READABLE |
Packit ae235b
                                                       G_PARAM_WRITABLE |
Packit ae235b
                                                       G_PARAM_STATIC_STRINGS));
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GDBusInterfaceSkeleton::g-authorize-method:
Packit ae235b
   * @interface: The #GDBusInterfaceSkeleton emitting the signal.
Packit ae235b
   * @invocation: A #GDBusMethodInvocation.
Packit ae235b
   *
Packit ae235b
   * Emitted when a method is invoked by a remote caller and used to
Packit ae235b
   * determine if the method call is authorized.
Packit ae235b
   *
Packit ae235b
   * Note that this signal is emitted in a thread dedicated to
Packit ae235b
   * handling the method call so handlers are allowed to perform
Packit ae235b
   * blocking IO. This means that it is appropriate to call e.g.
Packit ae235b
   * [polkit_authority_check_authorization_sync()](http://hal.freedesktop.org/docs/polkit/PolkitAuthority.html#polkit-authority-check-authorization-sync)
Packit ae235b
   * with the
Packit ae235b
   * [POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION](http://hal.freedesktop.org/docs/polkit/PolkitAuthority.html#POLKIT-CHECK-AUTHORIZATION-FLAGS-ALLOW-USER-INTERACTION:CAPS)
Packit ae235b
   * flag set.
Packit ae235b
   *
Packit ae235b
   * If %FALSE is returned then no further handlers are run and the
Packit ae235b
   * signal handler must take a reference to @invocation and finish
Packit ae235b
   * handling the call (e.g. return an error via
Packit ae235b
   * g_dbus_method_invocation_return_error()).
Packit ae235b
   *
Packit ae235b
   * Otherwise, if %TRUE is returned, signal emission continues. If no
Packit ae235b
   * handlers return %FALSE, then the method is dispatched. If
Packit ae235b
   * @interface has an enclosing #GDBusObjectSkeleton, then the
Packit ae235b
   * #GDBusObjectSkeleton::authorize-method signal handlers run before
Packit ae235b
   * the handlers for this signal.
Packit ae235b
   *
Packit ae235b
   * The default class handler just returns %TRUE.
Packit ae235b
   *
Packit ae235b
   * Please note that the common case is optimized: if no signals
Packit ae235b
   * handlers are connected and the default class handler isn't
Packit ae235b
   * overridden (for both @interface and the enclosing
Packit ae235b
   * #GDBusObjectSkeleton, if any) and #GDBusInterfaceSkeleton:g-flags does
Packit ae235b
   * not have the
Packit ae235b
   * %G_DBUS_INTERFACE_SKELETON_FLAGS_HANDLE_METHOD_INVOCATIONS_IN_THREAD
Packit ae235b
   * flags set, no dedicated thread is ever used and the call will be
Packit ae235b
   * handled in the same thread as the object that @interface belongs
Packit ae235b
   * to was exported in.
Packit ae235b
   *
Packit ae235b
   * Returns: %TRUE if the call is authorized, %FALSE otherwise.
Packit ae235b
   *
Packit ae235b
   * Since: 2.30
Packit ae235b
   */
Packit ae235b
  signals[G_AUTHORIZE_METHOD_SIGNAL] =
Packit ae235b
    g_signal_new (I_("g-authorize-method"),
Packit ae235b
                  G_TYPE_DBUS_INTERFACE_SKELETON,
Packit ae235b
                  G_SIGNAL_RUN_LAST,
Packit ae235b
                  G_STRUCT_OFFSET (GDBusInterfaceSkeletonClass, g_authorize_method),
Packit ae235b
                  _g_signal_accumulator_false_handled,
Packit ae235b
                  NULL,
Packit ae235b
                  NULL,
Packit ae235b
                  G_TYPE_BOOLEAN,
Packit ae235b
                  1,
Packit ae235b
                  G_TYPE_DBUS_METHOD_INVOCATION);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_dbus_interface_skeleton_init (GDBusInterfaceSkeleton *interface)
Packit ae235b
{
Packit ae235b
  interface->priv = g_dbus_interface_skeleton_get_instance_private (interface);
Packit ae235b
  g_mutex_init (&interface->priv->lock);
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_interface_skeleton_get_flags:
Packit ae235b
 * @interface_: A #GDBusInterfaceSkeleton.
Packit ae235b
 *
Packit ae235b
 * Gets the #GDBusInterfaceSkeletonFlags that describes what the behavior
Packit ae235b
 * of @interface_
Packit ae235b
 *
Packit ae235b
 * Returns: One or more flags from the #GDBusInterfaceSkeletonFlags enumeration.
Packit ae235b
 *
Packit ae235b
 * Since: 2.30
Packit ae235b
 */
Packit ae235b
GDBusInterfaceSkeletonFlags
Packit ae235b
g_dbus_interface_skeleton_get_flags (GDBusInterfaceSkeleton  *interface_)
Packit ae235b
{
Packit ae235b
  g_return_val_if_fail (G_IS_DBUS_INTERFACE_SKELETON (interface_), G_DBUS_INTERFACE_SKELETON_FLAGS_NONE);
Packit ae235b
  return interface_->priv->flags;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_interface_skeleton_set_flags:
Packit ae235b
 * @interface_: A #GDBusInterfaceSkeleton.
Packit ae235b
 * @flags: Flags from the #GDBusInterfaceSkeletonFlags enumeration.
Packit ae235b
 *
Packit ae235b
 * Sets flags describing what the behavior of @skeleton should be.
Packit ae235b
 *
Packit ae235b
 * Since: 2.30
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dbus_interface_skeleton_set_flags (GDBusInterfaceSkeleton      *interface_,
Packit ae235b
                                     GDBusInterfaceSkeletonFlags  flags)
Packit ae235b
{
Packit ae235b
  g_return_if_fail (G_IS_DBUS_INTERFACE_SKELETON (interface_));
Packit ae235b
  g_mutex_lock (&interface_->priv->lock);
Packit ae235b
  if (interface_->priv->flags != flags)
Packit ae235b
    {
Packit ae235b
      interface_->priv->flags = flags;
Packit ae235b
      g_mutex_unlock (&interface_->priv->lock);
Packit ae235b
      g_object_notify (G_OBJECT (interface_), "g-flags");
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      g_mutex_unlock (&interface_->priv->lock);
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_interface_skeleton_get_info:
Packit ae235b
 * @interface_: A #GDBusInterfaceSkeleton.
Packit ae235b
 *
Packit ae235b
 * Gets D-Bus introspection information for the D-Bus interface
Packit ae235b
 * implemented by @interface_.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer none): A #GDBusInterfaceInfo (never %NULL). Do not free.
Packit ae235b
 *
Packit ae235b
 * Since: 2.30
Packit ae235b
 */
Packit ae235b
GDBusInterfaceInfo *
Packit ae235b
g_dbus_interface_skeleton_get_info (GDBusInterfaceSkeleton *interface_)
Packit ae235b
{
Packit ae235b
  GDBusInterfaceInfo *ret;
Packit ae235b
  g_return_val_if_fail (G_IS_DBUS_INTERFACE_SKELETON (interface_), NULL);
Packit ae235b
  ret = G_DBUS_INTERFACE_SKELETON_GET_CLASS (interface_)->get_info (interface_);
Packit ae235b
  g_warn_if_fail (ret != NULL);
Packit ae235b
  return ret;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_interface_skeleton_get_vtable: (skip)
Packit ae235b
 * @interface_: A #GDBusInterfaceSkeleton.
Packit ae235b
 *
Packit ae235b
 * Gets the interface vtable for the D-Bus interface implemented by
Packit ae235b
 * @interface_. The returned function pointers should expect @interface_
Packit ae235b
 * itself to be passed as @user_data.
Packit ae235b
 *
Packit ae235b
 * Returns: A #GDBusInterfaceVTable (never %NULL).
Packit ae235b
 *
Packit ae235b
 * Since: 2.30
Packit ae235b
 */
Packit ae235b
GDBusInterfaceVTable *
Packit ae235b
g_dbus_interface_skeleton_get_vtable (GDBusInterfaceSkeleton *interface_)
Packit ae235b
{
Packit ae235b
  GDBusInterfaceVTable *ret;
Packit ae235b
  g_return_val_if_fail (G_IS_DBUS_INTERFACE_SKELETON (interface_), NULL);
Packit ae235b
  ret = G_DBUS_INTERFACE_SKELETON_GET_CLASS (interface_)->get_vtable (interface_);
Packit ae235b
  g_warn_if_fail (ret != NULL);
Packit ae235b
  return ret;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_interface_skeleton_get_properties:
Packit ae235b
 * @interface_: A #GDBusInterfaceSkeleton.
Packit ae235b
 *
Packit ae235b
 * Gets all D-Bus properties for @interface_.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer full): A #GVariant of type
Packit ae235b
 * ['a{sv}'][G-VARIANT-TYPE-VARDICT:CAPS].
Packit ae235b
 * Free with g_variant_unref().
Packit ae235b
 *
Packit ae235b
 * Since: 2.30
Packit ae235b
 */
Packit ae235b
GVariant *
Packit ae235b
g_dbus_interface_skeleton_get_properties (GDBusInterfaceSkeleton *interface_)
Packit ae235b
{
Packit ae235b
  GVariant *ret;
Packit ae235b
  g_return_val_if_fail (G_IS_DBUS_INTERFACE_SKELETON (interface_), NULL);
Packit ae235b
  ret = G_DBUS_INTERFACE_SKELETON_GET_CLASS (interface_)->get_properties (interface_);
Packit ae235b
  return g_variant_take_ref (ret);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_interface_skeleton_flush:
Packit ae235b
 * @interface_: A #GDBusInterfaceSkeleton.
Packit ae235b
 *
Packit ae235b
 * If @interface_ has outstanding changes, request for these changes to be
Packit ae235b
 * emitted immediately.
Packit ae235b
 *
Packit ae235b
 * For example, an exported D-Bus interface may queue up property
Packit ae235b
 * changes and emit the
Packit ae235b
 * `org.freedesktop.DBus.Properties.PropertiesChanged`
Packit ae235b
 * signal later (e.g. in an idle handler). This technique is useful
Packit ae235b
 * for collapsing multiple property changes into one.
Packit ae235b
 *
Packit ae235b
 * Since: 2.30
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dbus_interface_skeleton_flush (GDBusInterfaceSkeleton *interface_)
Packit ae235b
{
Packit ae235b
  g_return_if_fail (G_IS_DBUS_INTERFACE_SKELETON (interface_));
Packit ae235b
  G_DBUS_INTERFACE_SKELETON_GET_CLASS (interface_)->flush (interface_);
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
static GDBusInterfaceInfo *
Packit ae235b
_g_dbus_interface_skeleton_get_info (GDBusInterface *interface_)
Packit ae235b
{
Packit ae235b
  GDBusInterfaceSkeleton *interface = G_DBUS_INTERFACE_SKELETON (interface_);
Packit ae235b
  return g_dbus_interface_skeleton_get_info (interface);
Packit ae235b
}
Packit ae235b
Packit ae235b
static GDBusObject *
Packit ae235b
g_dbus_interface_skeleton_get_object (GDBusInterface *interface_)
Packit ae235b
{
Packit ae235b
  GDBusInterfaceSkeleton *interface = G_DBUS_INTERFACE_SKELETON (interface_);
Packit ae235b
  GDBusObject *ret;
Packit ae235b
  g_mutex_lock (&interface->priv->lock);
Packit ae235b
  ret = interface->priv->object;
Packit ae235b
  g_mutex_unlock (&interface->priv->lock);
Packit ae235b
  return ret;
Packit ae235b
}
Packit ae235b
Packit ae235b
static GDBusObject *
Packit ae235b
g_dbus_interface_skeleton_dup_object (GDBusInterface *interface_)
Packit ae235b
{
Packit ae235b
  GDBusInterfaceSkeleton *interface = G_DBUS_INTERFACE_SKELETON (interface_);
Packit ae235b
  GDBusObject *ret;
Packit ae235b
  g_mutex_lock (&interface->priv->lock);
Packit ae235b
  ret = interface->priv->object;
Packit ae235b
  if (ret != NULL)
Packit ae235b
    g_object_ref (ret);
Packit ae235b
  g_mutex_unlock (&interface->priv->lock);
Packit ae235b
  return ret;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_dbus_interface_skeleton_set_object (GDBusInterface *interface_,
Packit ae235b
                                      GDBusObject    *object)
Packit ae235b
{
Packit ae235b
  GDBusInterfaceSkeleton *interface = G_DBUS_INTERFACE_SKELETON (interface_);
Packit ae235b
  g_mutex_lock (&interface->priv->lock);
Packit ae235b
  if (interface->priv->object != NULL)
Packit ae235b
    g_object_remove_weak_pointer (G_OBJECT (interface->priv->object), (gpointer *) &interface->priv->object);
Packit ae235b
  interface->priv->object = object;
Packit ae235b
  if (object != NULL)
Packit ae235b
    g_object_add_weak_pointer (G_OBJECT (interface->priv->object), (gpointer *) &interface->priv->object);
Packit ae235b
  g_mutex_unlock (&interface->priv->lock);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
dbus_interface_interface_init (GDBusInterfaceIface *iface)
Packit ae235b
{
Packit ae235b
  iface->get_info    = _g_dbus_interface_skeleton_get_info;
Packit ae235b
  iface->get_object  = g_dbus_interface_skeleton_get_object;
Packit ae235b
  iface->dup_object  = g_dbus_interface_skeleton_dup_object;
Packit ae235b
  iface->set_object  = g_dbus_interface_skeleton_set_object;
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
typedef struct
Packit ae235b
{
Packit ae235b
  volatile gint ref_count;
Packit ae235b
  GDBusInterfaceSkeleton       *interface;
Packit ae235b
  GDBusInterfaceMethodCallFunc  method_call_func;
Packit ae235b
  GDBusMethodInvocation        *invocation;
Packit ae235b
} DispatchData;
Packit ae235b
Packit ae235b
static void
Packit ae235b
dispatch_data_unref (DispatchData *data)
Packit ae235b
{
Packit ae235b
  if (g_atomic_int_dec_and_test (&data->ref_count))
Packit ae235b
    g_slice_free (DispatchData, data);
Packit ae235b
}
Packit ae235b
Packit ae235b
static DispatchData *
Packit ae235b
dispatch_data_ref (DispatchData *data)
Packit ae235b
{
Packit ae235b
  g_atomic_int_inc (&data->ref_count);
Packit ae235b
  return data;
Packit ae235b
}
Packit ae235b
Packit ae235b
static gboolean
Packit ae235b
dispatch_invoke_in_context_func (gpointer user_data)
Packit ae235b
{
Packit ae235b
  DispatchData *data = user_data;
Packit ae235b
  data->method_call_func (g_dbus_method_invocation_get_connection (data->invocation),
Packit ae235b
                          g_dbus_method_invocation_get_sender (data->invocation),
Packit ae235b
                          g_dbus_method_invocation_get_object_path (data->invocation),
Packit ae235b
                          g_dbus_method_invocation_get_interface_name (data->invocation),
Packit ae235b
                          g_dbus_method_invocation_get_method_name (data->invocation),
Packit ae235b
                          g_dbus_method_invocation_get_parameters (data->invocation),
Packit ae235b
                          data->invocation,
Packit ae235b
                          g_dbus_method_invocation_get_user_data (data->invocation));
Packit ae235b
  return FALSE;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
dispatch_in_thread_func (GTask        *task,
Packit ae235b
                         gpointer      source_object,
Packit ae235b
                         gpointer      task_data,
Packit ae235b
                         GCancellable *cancellable)
Packit ae235b
{
Packit ae235b
  DispatchData *data = task_data;
Packit ae235b
  GDBusInterfaceSkeletonFlags flags;
Packit ae235b
  GDBusObject *object;
Packit ae235b
  gboolean authorized;
Packit ae235b
Packit ae235b
  g_mutex_lock (&data->interface->priv->lock);
Packit ae235b
  flags = data->interface->priv->flags;
Packit ae235b
  object = data->interface->priv->object;
Packit ae235b
  if (object != NULL)
Packit ae235b
    g_object_ref (object);
Packit ae235b
  g_mutex_unlock (&data->interface->priv->lock);
Packit ae235b
Packit ae235b
  /* first check on the enclosing object (if any), then the interface */
Packit ae235b
  authorized = TRUE;
Packit ae235b
  if (object != NULL)
Packit ae235b
    {
Packit ae235b
      g_signal_emit_by_name (object,
Packit ae235b
                             "authorize-method",
Packit ae235b
                             data->interface,
Packit ae235b
                             data->invocation,
Packit ae235b
                             &authorized);
Packit ae235b
    }
Packit ae235b
  if (authorized)
Packit ae235b
    {
Packit ae235b
      g_signal_emit (data->interface,
Packit ae235b
                     signals[G_AUTHORIZE_METHOD_SIGNAL],
Packit ae235b
                     0,
Packit ae235b
                     data->invocation,
Packit ae235b
                     &authorized);
Packit ae235b
    }
Packit ae235b
Packit ae235b
  if (authorized)
Packit ae235b
    {
Packit ae235b
      gboolean run_in_thread;
Packit ae235b
      run_in_thread = (flags & G_DBUS_INTERFACE_SKELETON_FLAGS_HANDLE_METHOD_INVOCATIONS_IN_THREAD);
Packit ae235b
      if (run_in_thread)
Packit ae235b
        {
Packit ae235b
          /* might as well just re-use the existing thread */
Packit ae235b
          data->method_call_func (g_dbus_method_invocation_get_connection (data->invocation),
Packit ae235b
                                  g_dbus_method_invocation_get_sender (data->invocation),
Packit ae235b
                                  g_dbus_method_invocation_get_object_path (data->invocation),
Packit ae235b
                                  g_dbus_method_invocation_get_interface_name (data->invocation),
Packit ae235b
                                  g_dbus_method_invocation_get_method_name (data->invocation),
Packit ae235b
                                  g_dbus_method_invocation_get_parameters (data->invocation),
Packit ae235b
                                  data->invocation,
Packit ae235b
                                  g_dbus_method_invocation_get_user_data (data->invocation));
Packit ae235b
        }
Packit ae235b
      else
Packit ae235b
        {
Packit ae235b
          /* bah, back to original context */
Packit ae235b
          g_main_context_invoke_full (g_task_get_context (task),
Packit ae235b
                                      g_task_get_priority (task),
Packit ae235b
                                      dispatch_invoke_in_context_func,
Packit ae235b
                                      dispatch_data_ref (data),
Packit ae235b
                                      (GDestroyNotify) dispatch_data_unref);
Packit ae235b
        }
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      /* do nothing */
Packit ae235b
    }
Packit ae235b
Packit ae235b
  if (object != NULL)
Packit ae235b
    g_object_unref (object);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_dbus_interface_method_dispatch_helper (GDBusInterfaceSkeleton       *interface,
Packit ae235b
                                         GDBusInterfaceMethodCallFunc  method_call_func,
Packit ae235b
                                         GDBusMethodInvocation        *invocation)
Packit ae235b
{
Packit ae235b
  gboolean has_handlers;
Packit ae235b
  gboolean has_default_class_handler;
Packit ae235b
  gboolean emit_authorized_signal;
Packit ae235b
  gboolean run_in_thread;
Packit ae235b
  GDBusInterfaceSkeletonFlags flags;
Packit ae235b
  GDBusObject *object;
Packit ae235b
Packit ae235b
  g_return_if_fail (G_IS_DBUS_INTERFACE_SKELETON (interface));
Packit ae235b
  g_return_if_fail (method_call_func != NULL);
Packit ae235b
  g_return_if_fail (G_IS_DBUS_METHOD_INVOCATION (invocation));
Packit ae235b
Packit ae235b
  g_mutex_lock (&interface->priv->lock);
Packit ae235b
  flags = interface->priv->flags;
Packit ae235b
  object = interface->priv->object;
Packit ae235b
  if (object != NULL)
Packit ae235b
    g_object_ref (object);
Packit ae235b
  g_mutex_unlock (&interface->priv->lock);
Packit ae235b
Packit ae235b
  /* optimization for the common case where
Packit ae235b
   *
Packit ae235b
   *  a) no handler is connected and class handler is not overridden (both interface and object); and
Packit ae235b
   *  b) method calls are not dispatched in a thread
Packit ae235b
   */
Packit ae235b
  has_handlers = g_signal_has_handler_pending (interface,
Packit ae235b
                                               signals[G_AUTHORIZE_METHOD_SIGNAL],
Packit ae235b
                                               0,
Packit ae235b
                                               TRUE);
Packit ae235b
  has_default_class_handler = (G_DBUS_INTERFACE_SKELETON_GET_CLASS (interface)->g_authorize_method ==
Packit ae235b
                               g_dbus_interface_skeleton_g_authorize_method_default);
Packit ae235b
Packit ae235b
  emit_authorized_signal = (has_handlers || !has_default_class_handler);
Packit ae235b
  if (!emit_authorized_signal)
Packit ae235b
    {
Packit ae235b
      if (object != NULL)
Packit ae235b
        emit_authorized_signal = _g_dbus_object_skeleton_has_authorize_method_handlers (G_DBUS_OBJECT_SKELETON (object));
Packit ae235b
    }
Packit ae235b
Packit ae235b
  run_in_thread = (flags & G_DBUS_INTERFACE_SKELETON_FLAGS_HANDLE_METHOD_INVOCATIONS_IN_THREAD);
Packit ae235b
  if (!emit_authorized_signal && !run_in_thread)
Packit ae235b
    {
Packit ae235b
      method_call_func (g_dbus_method_invocation_get_connection (invocation),
Packit ae235b
                        g_dbus_method_invocation_get_sender (invocation),
Packit ae235b
                        g_dbus_method_invocation_get_object_path (invocation),
Packit ae235b
                        g_dbus_method_invocation_get_interface_name (invocation),
Packit ae235b
                        g_dbus_method_invocation_get_method_name (invocation),
Packit ae235b
                        g_dbus_method_invocation_get_parameters (invocation),
Packit ae235b
                        invocation,
Packit ae235b
                        g_dbus_method_invocation_get_user_data (invocation));
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      GTask *task;
Packit ae235b
      DispatchData *data;
Packit ae235b
Packit ae235b
      data = g_slice_new0 (DispatchData);
Packit ae235b
      data->interface = interface;
Packit ae235b
      data->method_call_func = method_call_func;
Packit ae235b
      data->invocation = invocation;
Packit ae235b
      data->ref_count = 1;
Packit ae235b
Packit ae235b
      task = g_task_new (interface, NULL, NULL, NULL);
Packit ae235b
      g_task_set_source_tag (task, g_dbus_interface_method_dispatch_helper);
Packit ae235b
      g_task_set_task_data (task, data, (GDestroyNotify) dispatch_data_unref);
Packit ae235b
      g_task_run_in_thread (task, dispatch_in_thread_func);
Packit ae235b
      g_object_unref (task);
Packit ae235b
    }
Packit ae235b
Packit ae235b
  if (object != NULL)
Packit ae235b
    g_object_unref (object);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
skeleton_intercept_handle_method_call (GDBusConnection       *connection,
Packit ae235b
                                       const gchar           *sender,
Packit ae235b
                                       const gchar           *object_path,
Packit ae235b
                                       const gchar           *interface_name,
Packit ae235b
                                       const gchar           *method_name,
Packit ae235b
                                       GVariant              *parameters,
Packit ae235b
                                       GDBusMethodInvocation *invocation,
Packit ae235b
                                       gpointer               user_data)
Packit ae235b
{
Packit ae235b
  GDBusInterfaceSkeleton *interface = G_DBUS_INTERFACE_SKELETON (user_data);
Packit ae235b
  g_dbus_interface_method_dispatch_helper (interface,
Packit ae235b
                                           g_dbus_interface_skeleton_get_vtable (interface)->method_call,
Packit ae235b
                                           invocation);
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
static ConnectionData *
Packit ae235b
new_connection (GDBusConnection *connection,
Packit ae235b
                guint            registration_id)
Packit ae235b
{
Packit ae235b
  ConnectionData *data;
Packit ae235b
Packit ae235b
  data = g_slice_new0 (ConnectionData);
Packit ae235b
  data->connection      = g_object_ref (connection);
Packit ae235b
  data->registration_id = registration_id;
Packit ae235b
Packit ae235b
  return data;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
free_connection (ConnectionData *data)
Packit ae235b
{
Packit ae235b
  if (data != NULL)
Packit ae235b
    {
Packit ae235b
      g_object_unref (data->connection);
Packit ae235b
      g_slice_free (ConnectionData, data);
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
static gboolean
Packit ae235b
add_connection_locked (GDBusInterfaceSkeleton *interface_,
Packit ae235b
                       GDBusConnection        *connection,
Packit ae235b
                       GError                **error)
Packit ae235b
{
Packit ae235b
  ConnectionData *data;
Packit ae235b
  guint registration_id;
Packit ae235b
  gboolean ret = FALSE;
Packit ae235b
Packit ae235b
  if (interface_->priv->hooked_vtable == NULL)
Packit ae235b
    {
Packit ae235b
      /* Hook the vtable since we need to intercept method calls for
Packit ae235b
       * ::g-authorize-method and for dispatching in thread vs
Packit ae235b
       * context
Packit ae235b
       *
Packit ae235b
       * We need to wait until subclasses have had time to initialize
Packit ae235b
       * properly before building the hooked_vtable, so we create it
Packit ae235b
       * once at the last minute.
Packit ae235b
       */
Packit ae235b
      interface_->priv->hooked_vtable = g_memdup (g_dbus_interface_skeleton_get_vtable (interface_), sizeof (GDBusInterfaceVTable));
Packit ae235b
      interface_->priv->hooked_vtable->method_call = skeleton_intercept_handle_method_call;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  registration_id = g_dbus_connection_register_object (connection,
Packit ae235b
                                                       interface_->priv->object_path,
Packit ae235b
                                                       g_dbus_interface_skeleton_get_info (interface_),
Packit ae235b
                                                       interface_->priv->hooked_vtable,
Packit ae235b
                                                       interface_,
Packit ae235b
                                                       NULL, /* user_data_free_func */
Packit ae235b
                                                       error);
Packit ae235b
Packit ae235b
  if (registration_id > 0)
Packit ae235b
    {
Packit ae235b
      data = new_connection (connection, registration_id);
Packit ae235b
      interface_->priv->connections = g_slist_append (interface_->priv->connections, data);
Packit ae235b
      ret = TRUE;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  return ret;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
remove_connection_locked (GDBusInterfaceSkeleton *interface_,
Packit ae235b
                          GDBusConnection        *connection)
Packit ae235b
{
Packit ae235b
  ConnectionData *data;
Packit ae235b
  GSList *l;
Packit ae235b
Packit ae235b
  /* Get the connection in the list and unregister ... */
Packit ae235b
  for (l = interface_->priv->connections; l != NULL; l = l->next)
Packit ae235b
    {
Packit ae235b
      data = l->data;
Packit ae235b
      if (data->connection == connection)
Packit ae235b
        {
Packit ae235b
          g_warn_if_fail (g_dbus_connection_unregister_object (data->connection, data->registration_id));
Packit ae235b
          free_connection (data);
Packit ae235b
          interface_->priv->connections = g_slist_delete_link (interface_->priv->connections, l);
Packit ae235b
          /* we are guaranteed that the connection is only added once, so bail out early */
Packit ae235b
          goto out;
Packit ae235b
        }
Packit ae235b
    }
Packit ae235b
 out:
Packit ae235b
  ;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
set_object_path_locked (GDBusInterfaceSkeleton *interface_,
Packit ae235b
                        const gchar            *object_path)
Packit ae235b
{
Packit ae235b
  if (g_strcmp0 (interface_->priv->object_path, object_path) != 0)
Packit ae235b
    {
Packit ae235b
      g_free (interface_->priv->object_path);
Packit ae235b
      interface_->priv->object_path = g_strdup (object_path);
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_interface_skeleton_get_connection:
Packit ae235b
 * @interface_: A #GDBusInterfaceSkeleton.
Packit ae235b
 *
Packit ae235b
 * Gets the first connection that @interface_ is exported on, if any.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer none): A #GDBusConnection or %NULL if @interface_ is
Packit ae235b
 * not exported anywhere. Do not free, the object belongs to @interface_.
Packit ae235b
 *
Packit ae235b
 * Since: 2.30
Packit ae235b
 */
Packit ae235b
GDBusConnection *
Packit ae235b
g_dbus_interface_skeleton_get_connection (GDBusInterfaceSkeleton *interface_)
Packit ae235b
{
Packit ae235b
  ConnectionData  *data;
Packit ae235b
  GDBusConnection *ret;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DBUS_INTERFACE_SKELETON (interface_), NULL);
Packit ae235b
  g_mutex_lock (&interface_->priv->lock);
Packit ae235b
Packit ae235b
  ret = NULL;
Packit ae235b
  if (interface_->priv->connections != NULL)
Packit ae235b
    {
Packit ae235b
      data = interface_->priv->connections->data;
Packit ae235b
      if (data != NULL)
Packit ae235b
        ret = data->connection;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  g_mutex_unlock (&interface_->priv->lock);
Packit ae235b
Packit ae235b
  return ret;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_interface_skeleton_get_connections:
Packit ae235b
 * @interface_: A #GDBusInterfaceSkeleton.
Packit ae235b
 *
Packit ae235b
 * Gets a list of the connections that @interface_ is exported on.
Packit ae235b
 *
Packit ae235b
 * Returns: (element-type GDBusConnection) (transfer full): A list of
Packit ae235b
 *   all the connections that @interface_ is exported on. The returned
Packit ae235b
 *   list should be freed with g_list_free() after each element has
Packit ae235b
 *   been freed with g_object_unref().
Packit ae235b
 *
Packit ae235b
 * Since: 2.32
Packit ae235b
 */
Packit ae235b
GList *
Packit ae235b
g_dbus_interface_skeleton_get_connections (GDBusInterfaceSkeleton *interface_)
Packit ae235b
{
Packit ae235b
  GList           *connections;
Packit ae235b
  GSList          *l;
Packit ae235b
  ConnectionData  *data;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DBUS_INTERFACE_SKELETON (interface_), NULL);
Packit ae235b
Packit ae235b
  g_mutex_lock (&interface_->priv->lock);
Packit ae235b
  connections = NULL;
Packit ae235b
Packit ae235b
  for (l = interface_->priv->connections; l != NULL; l = l->next)
Packit ae235b
    {
Packit ae235b
      data        = l->data;
Packit ae235b
      connections = g_list_prepend (connections,
Packit ae235b
                                    /* Return a reference to each connection */
Packit ae235b
                                    g_object_ref (data->connection));
Packit ae235b
    }
Packit ae235b
Packit ae235b
  g_mutex_unlock (&interface_->priv->lock);
Packit ae235b
Packit ae235b
  return g_list_reverse (connections);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_interface_skeleton_has_connection:
Packit ae235b
 * @interface_: A #GDBusInterfaceSkeleton.
Packit ae235b
 * @connection: A #GDBusConnection.
Packit ae235b
 *
Packit ae235b
 * Checks if @interface_ is exported on @connection.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE if @interface_ is exported on @connection, %FALSE otherwise.
Packit ae235b
 *
Packit ae235b
 * Since: 2.32
Packit ae235b
 */
Packit ae235b
gboolean
Packit ae235b
g_dbus_interface_skeleton_has_connection (GDBusInterfaceSkeleton     *interface_,
Packit ae235b
                                          GDBusConnection            *connection)
Packit ae235b
{
Packit ae235b
  GSList *l;
Packit ae235b
  gboolean ret = FALSE;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DBUS_INTERFACE_SKELETON (interface_), FALSE);
Packit ae235b
  g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), FALSE);
Packit ae235b
Packit ae235b
  g_mutex_lock (&interface_->priv->lock);
Packit ae235b
Packit ae235b
  for (l = interface_->priv->connections; l != NULL; l = l->next)
Packit ae235b
    {
Packit ae235b
      ConnectionData *data = l->data;
Packit ae235b
      if (data->connection == connection)
Packit ae235b
        {
Packit ae235b
          ret = TRUE;
Packit ae235b
          goto out;
Packit ae235b
        }
Packit ae235b
    }
Packit ae235b
Packit ae235b
 out:
Packit ae235b
  g_mutex_unlock (&interface_->priv->lock);
Packit ae235b
  return ret;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_interface_skeleton_get_object_path:
Packit ae235b
 * @interface_: A #GDBusInterfaceSkeleton.
Packit ae235b
 *
Packit ae235b
 * Gets the object path that @interface_ is exported on, if any.
Packit ae235b
 *
Packit ae235b
 * Returns: A string owned by @interface_ or %NULL if @interface_ is not exported
Packit ae235b
 * anywhere. Do not free, the string belongs to @interface_.
Packit ae235b
 *
Packit ae235b
 * Since: 2.30
Packit ae235b
 */
Packit ae235b
const gchar *
Packit ae235b
g_dbus_interface_skeleton_get_object_path (GDBusInterfaceSkeleton *interface_)
Packit ae235b
{
Packit ae235b
  const gchar *ret;
Packit ae235b
  g_return_val_if_fail (G_IS_DBUS_INTERFACE_SKELETON (interface_), NULL);
Packit ae235b
  g_mutex_lock (&interface_->priv->lock);
Packit ae235b
  ret = interface_->priv->object_path;
Packit ae235b
  g_mutex_unlock (&interface_->priv->lock);
Packit ae235b
  return ret;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_interface_skeleton_export:
Packit ae235b
 * @interface_: The D-Bus interface to export.
Packit ae235b
 * @connection: A #GDBusConnection to export @interface_ on.
Packit ae235b
 * @object_path: The path to export the interface at.
Packit ae235b
 * @error: Return location for error or %NULL.
Packit ae235b
 *
Packit ae235b
 * Exports @interface_ at @object_path on @connection.
Packit ae235b
 *
Packit ae235b
 * This can be called multiple times to export the same @interface_
Packit ae235b
 * onto multiple connections however the @object_path provided must be
Packit ae235b
 * the same for all connections.
Packit ae235b
 *
Packit ae235b
 * Use g_dbus_interface_skeleton_unexport() to unexport the object.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE if the interface was exported on @connection, otherwise %FALSE with
Packit ae235b
 * @error set.
Packit ae235b
 *
Packit ae235b
 * Since: 2.30
Packit ae235b
 */
Packit ae235b
gboolean
Packit ae235b
g_dbus_interface_skeleton_export (GDBusInterfaceSkeleton  *interface_,
Packit ae235b
                                  GDBusConnection         *connection,
Packit ae235b
                                  const gchar             *object_path,
Packit ae235b
                                  GError                 **error)
Packit ae235b
{
Packit ae235b
  gboolean ret = FALSE;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DBUS_INTERFACE_SKELETON (interface_), FALSE);
Packit ae235b
  g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), FALSE);
Packit ae235b
  g_return_val_if_fail (g_variant_is_object_path (object_path), FALSE);
Packit ae235b
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
Packit ae235b
Packit ae235b
  /* Assert that the object path is the same for multiple connections here */
Packit ae235b
  g_return_val_if_fail (interface_->priv->object_path == NULL ||
Packit ae235b
                        g_strcmp0 (interface_->priv->object_path, object_path) == 0, FALSE);
Packit ae235b
Packit ae235b
  g_mutex_lock (&interface_->priv->lock);
Packit ae235b
Packit ae235b
  /* Set the object path */
Packit ae235b
  set_object_path_locked (interface_, object_path);
Packit ae235b
Packit ae235b
  /* Add the connection */
Packit ae235b
  ret = add_connection_locked (interface_, connection, error);
Packit ae235b
Packit ae235b
  g_mutex_unlock (&interface_->priv->lock);
Packit ae235b
  return ret;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_interface_skeleton_unexport:
Packit ae235b
 * @interface_: A #GDBusInterfaceSkeleton.
Packit ae235b
 *
Packit ae235b
 * Stops exporting @interface_ on all connections it is exported on.
Packit ae235b
 *
Packit ae235b
 * To unexport @interface_ from only a single connection, use
Packit ae235b
 * g_dbus_interface_skeleton_unexport_from_connection()
Packit ae235b
 *
Packit ae235b
 * Since: 2.30
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dbus_interface_skeleton_unexport (GDBusInterfaceSkeleton *interface_)
Packit ae235b
{
Packit ae235b
  g_return_if_fail (G_IS_DBUS_INTERFACE_SKELETON (interface_));
Packit ae235b
  g_return_if_fail (interface_->priv->connections != NULL);
Packit ae235b
Packit ae235b
  g_mutex_lock (&interface_->priv->lock);
Packit ae235b
Packit ae235b
  g_assert (interface_->priv->object_path != NULL);
Packit ae235b
  g_assert (interface_->priv->hooked_vtable != NULL);
Packit ae235b
Packit ae235b
  /* Remove all connections */
Packit ae235b
  while (interface_->priv->connections != NULL)
Packit ae235b
    {
Packit ae235b
      ConnectionData *data = interface_->priv->connections->data;
Packit ae235b
      remove_connection_locked (interface_, data->connection);
Packit ae235b
    }
Packit ae235b
Packit ae235b
  /* Unset the object path since there are no connections left */
Packit ae235b
  set_object_path_locked (interface_, NULL);
Packit ae235b
Packit ae235b
  g_mutex_unlock (&interface_->priv->lock);
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_interface_skeleton_unexport_from_connection:
Packit ae235b
 * @interface_: A #GDBusInterfaceSkeleton.
Packit ae235b
 * @connection: A #GDBusConnection.
Packit ae235b
 *
Packit ae235b
 * Stops exporting @interface_ on @connection.
Packit ae235b
 *
Packit ae235b
 * To stop exporting on all connections the interface is exported on,
Packit ae235b
 * use g_dbus_interface_skeleton_unexport().
Packit ae235b
 *
Packit ae235b
 * Since: 2.32
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dbus_interface_skeleton_unexport_from_connection (GDBusInterfaceSkeleton *interface_,
Packit ae235b
                                                    GDBusConnection        *connection)
Packit ae235b
{
Packit ae235b
  g_return_if_fail (G_IS_DBUS_INTERFACE_SKELETON (interface_));
Packit ae235b
  g_return_if_fail (G_IS_DBUS_CONNECTION (connection));
Packit ae235b
  g_return_if_fail (interface_->priv->connections != NULL);
Packit ae235b
Packit ae235b
  g_mutex_lock (&interface_->priv->lock);
Packit ae235b
Packit ae235b
  g_assert (interface_->priv->object_path != NULL);
Packit ae235b
  g_assert (interface_->priv->hooked_vtable != NULL);
Packit ae235b
Packit ae235b
  remove_connection_locked (interface_, connection);
Packit ae235b
Packit ae235b
  /* Reset the object path if we removed the last connection */
Packit ae235b
  if (interface_->priv->connections == NULL)
Packit ae235b
    set_object_path_locked (interface_, NULL);
Packit ae235b
Packit ae235b
  g_mutex_unlock (&interface_->priv->lock);
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */