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