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 "gdbusobject.h"
|
2011-04-13 22:33:51 +02:00
|
|
|
#include "gdbusobjectskeleton.h"
|
|
|
|
#include "gdbusinterfaceskeleton.h"
|
2011-04-08 21:14:47 +02:00
|
|
|
#include "gdbusprivate.h"
|
|
|
|
#include "gdbusmethodinvocation.h"
|
|
|
|
#include "gdbusintrospection.h"
|
|
|
|
#include "gdbusinterface.h"
|
|
|
|
#include "gdbusutils.h"
|
|
|
|
|
|
|
|
#include "glibintl.h"
|
|
|
|
|
|
|
|
/**
|
2011-04-13 22:33:51 +02:00
|
|
|
* SECTION:gdbusobjectskeleton
|
2011-04-08 21:14:47 +02:00
|
|
|
* @short_description: Service-side D-Bus object
|
|
|
|
* @include: gio/gio.h
|
|
|
|
*
|
2011-04-13 22:33:51 +02:00
|
|
|
* A #GDBusObjectSkeleton instance is essentially a group of D-Bus
|
2011-04-08 21:14:47 +02:00
|
|
|
* interfaces. The set of exported interfaces on the object may be
|
|
|
|
* dynamic and change at runtime.
|
|
|
|
*
|
|
|
|
* This type is intended to be used with #GDBusObjectManager.
|
|
|
|
*/
|
|
|
|
|
2011-04-13 22:33:51 +02:00
|
|
|
struct _GDBusObjectSkeletonPrivate
|
2011-04-08 21:14:47 +02:00
|
|
|
{
|
2011-10-04 05:26:55 +02:00
|
|
|
GMutex lock;
|
2011-04-08 21:14:47 +02:00
|
|
|
gchar *object_path;
|
|
|
|
GHashTable *map_name_to_iface;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2011-09-21 14:16:43 +02:00
|
|
|
PROP_G_OBJECT_PATH
|
2011-04-08 21:14:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
AUTHORIZE_METHOD_SIGNAL,
|
|
|
|
LAST_SIGNAL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL] = {0};
|
|
|
|
|
|
|
|
static void dbus_object_interface_init (GDBusObjectIface *iface);
|
|
|
|
|
2011-04-13 22:33:51 +02:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GDBusObjectSkeleton, g_dbus_object_skeleton, G_TYPE_OBJECT,
|
2013-06-11 01:29:58 +02:00
|
|
|
G_ADD_PRIVATE (GDBusObjectSkeleton)
|
|
|
|
G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT, dbus_object_interface_init))
|
2011-04-08 21:14:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
2011-04-13 22:33:51 +02:00
|
|
|
g_dbus_object_skeleton_finalize (GObject *_object)
|
2011-04-08 21:14:47 +02:00
|
|
|
{
|
2011-04-13 22:33:51 +02:00
|
|
|
GDBusObjectSkeleton *object = G_DBUS_OBJECT_SKELETON (_object);
|
2011-04-08 21:14:47 +02:00
|
|
|
|
|
|
|
g_free (object->priv->object_path);
|
|
|
|
g_hash_table_unref (object->priv->map_name_to_iface);
|
|
|
|
|
2011-10-04 05:26:55 +02:00
|
|
|
g_mutex_clear (&object->priv->lock);
|
2011-08-29 21:19:42 +02:00
|
|
|
|
2011-04-13 22:33:51 +02:00
|
|
|
if (G_OBJECT_CLASS (g_dbus_object_skeleton_parent_class)->finalize != NULL)
|
|
|
|
G_OBJECT_CLASS (g_dbus_object_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_object_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
|
|
|
GDBusObjectSkeleton *object = G_DBUS_OBJECT_SKELETON (_object);
|
2011-04-08 21:14:47 +02:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2011-09-21 14:16:43 +02:00
|
|
|
case PROP_G_OBJECT_PATH:
|
2011-10-04 05:26:55 +02:00
|
|
|
g_mutex_lock (&object->priv->lock);
|
2012-08-17 10:55:10 +02:00
|
|
|
g_value_set_string (value, object->priv->object_path);
|
2011-10-04 05:26:55 +02:00
|
|
|
g_mutex_unlock (&object->priv->lock);
|
2011-04-08 21:14:47 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2012-11-30 21:18:01 +01:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2011-04-08 21:14:47 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-04-13 22:33:51 +02:00
|
|
|
g_dbus_object_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
|
|
|
GDBusObjectSkeleton *object = G_DBUS_OBJECT_SKELETON (_object);
|
2011-04-08 21:14:47 +02:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2011-09-21 14:16:43 +02:00
|
|
|
case PROP_G_OBJECT_PATH:
|
2011-04-13 22:33:51 +02:00
|
|
|
g_dbus_object_skeleton_set_object_path (object, g_value_get_string (value));
|
2011-04-08 21:14:47 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2012-11-30 21:18:01 +01:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2011-04-08 21:14:47 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-04-13 22:33:51 +02:00
|
|
|
g_dbus_object_skeleton_authorize_method_default (GDBusObjectSkeleton *object,
|
|
|
|
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_object_skeleton_class_init (GDBusObjectSkeletonClass *klass)
|
2011-04-08 21:14:47 +02:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2011-04-13 22:33:51 +02:00
|
|
|
gobject_class->finalize = g_dbus_object_skeleton_finalize;
|
|
|
|
gobject_class->set_property = g_dbus_object_skeleton_set_property;
|
|
|
|
gobject_class->get_property = g_dbus_object_skeleton_get_property;
|
2011-04-08 21:14:47 +02:00
|
|
|
|
2011-04-13 22:33:51 +02:00
|
|
|
klass->authorize_method = g_dbus_object_skeleton_authorize_method_default;
|
2011-04-08 21:14:47 +02:00
|
|
|
|
|
|
|
/**
|
2011-09-21 14:16:43 +02:00
|
|
|
* GDBusObjectSkeleton:g-object-path:
|
2011-04-08 21:14:47 +02:00
|
|
|
*
|
|
|
|
* The object path where the object is exported.
|
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,
|
2011-09-21 14:16:43 +02:00
|
|
|
PROP_G_OBJECT_PATH,
|
|
|
|
g_param_spec_string ("g-object-path",
|
2011-04-08 21:14:47 +02:00
|
|
|
"Object Path",
|
|
|
|
"The object path where the object is exported",
|
|
|
|
NULL,
|
|
|
|
G_PARAM_READABLE |
|
|
|
|
G_PARAM_WRITABLE |
|
|
|
|
G_PARAM_CONSTRUCT |
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
/**
|
2011-04-13 22:33:51 +02:00
|
|
|
* GDBusObjectSkeleton::authorize-method:
|
|
|
|
* @object: The #GDBusObjectSkeleton emitting the signal.
|
2011-04-13 22:39:50 +02:00
|
|
|
* @interface: The #GDBusInterfaceSkeleton that @invocation is for.
|
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.
|
|
|
|
*
|
2014-02-01 17:57:13 +01:00
|
|
|
* This signal is like #GDBusInterfaceSkeleton's
|
|
|
|
* #GDBusInterfaceSkeleton::g-authorize-method signal,
|
|
|
|
* except that it is for the enclosing object.
|
2011-04-08 21:14:47 +02:00
|
|
|
*
|
|
|
|
* The default class handler just returns %TRUE.
|
|
|
|
*
|
|
|
|
* 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[AUTHORIZE_METHOD_SIGNAL] =
|
|
|
|
g_signal_new ("authorize-method",
|
2011-04-13 22:33:51 +02:00
|
|
|
G_TYPE_DBUS_OBJECT_SKELETON,
|
2011-04-08 21:14:47 +02:00
|
|
|
G_SIGNAL_RUN_LAST,
|
2011-04-13 22:33:51 +02:00
|
|
|
G_STRUCT_OFFSET (GDBusObjectSkeletonClass, 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,
|
|
|
|
2,
|
2011-04-13 22:33:51 +02:00
|
|
|
G_TYPE_DBUS_INTERFACE_SKELETON,
|
2011-04-08 21:14:47 +02:00
|
|
|
G_TYPE_DBUS_METHOD_INVOCATION);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-04-13 22:33:51 +02:00
|
|
|
g_dbus_object_skeleton_init (GDBusObjectSkeleton *object)
|
2011-04-08 21:14:47 +02:00
|
|
|
{
|
2013-06-24 16:43:04 +02:00
|
|
|
object->priv = g_dbus_object_skeleton_get_instance_private (object);
|
2011-10-04 05:26:55 +02:00
|
|
|
g_mutex_init (&object->priv->lock);
|
2011-04-08 21:14:47 +02:00
|
|
|
object->priv->map_name_to_iface = g_hash_table_new_full (g_str_hash,
|
|
|
|
g_str_equal,
|
|
|
|
g_free,
|
|
|
|
(GDestroyNotify) g_object_unref);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-04-13 22:33:51 +02:00
|
|
|
* g_dbus_object_skeleton_new:
|
2011-04-08 21:14:47 +02:00
|
|
|
* @object_path: An object path.
|
|
|
|
*
|
2011-04-13 22:33:51 +02:00
|
|
|
* Creates a new #GDBusObjectSkeleton.
|
2011-04-08 21:14:47 +02:00
|
|
|
*
|
2011-04-13 22:33:51 +02:00
|
|
|
* Returns: A #GDBusObjectSkeleton. Free with g_object_unref().
|
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
|
|
|
GDBusObjectSkeleton *
|
|
|
|
g_dbus_object_skeleton_new (const gchar *object_path)
|
2011-04-08 21:14:47 +02:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);
|
2011-04-13 22:33:51 +02:00
|
|
|
return G_DBUS_OBJECT_SKELETON (g_object_new (G_TYPE_DBUS_OBJECT_SKELETON,
|
2011-09-21 14:16:43 +02:00
|
|
|
"g-object-path", object_path,
|
2011-04-13 22:33:51 +02:00
|
|
|
NULL));
|
2011-04-08 21:14:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-04-13 22:33:51 +02:00
|
|
|
* g_dbus_object_skeleton_set_object_path:
|
|
|
|
* @object: A #GDBusObjectSkeleton.
|
2011-04-08 21:14:47 +02:00
|
|
|
* @object_path: A valid D-Bus object path.
|
|
|
|
*
|
|
|
|
* Sets the object path for @object.
|
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_object_skeleton_set_object_path (GDBusObjectSkeleton *object,
|
|
|
|
const gchar *object_path)
|
2011-04-08 21:14:47 +02:00
|
|
|
{
|
2011-04-13 22:33:51 +02:00
|
|
|
g_return_if_fail (G_IS_DBUS_OBJECT_SKELETON (object));
|
2011-04-08 21:14:47 +02:00
|
|
|
g_return_if_fail (object_path == NULL || g_variant_is_object_path (object_path));
|
2011-10-04 05:26:55 +02:00
|
|
|
g_mutex_lock (&object->priv->lock);
|
2011-04-08 21:14:47 +02:00
|
|
|
/* TODO: fail if object is currently exported */
|
|
|
|
if (g_strcmp0 (object->priv->object_path, object_path) != 0)
|
|
|
|
{
|
|
|
|
g_free (object->priv->object_path);
|
|
|
|
object->priv->object_path = g_strdup (object_path);
|
2011-10-04 05:26:55 +02:00
|
|
|
g_mutex_unlock (&object->priv->lock);
|
2011-09-21 14:16:43 +02:00
|
|
|
g_object_notify (G_OBJECT (object), "g-object-path");
|
2011-04-08 21:14:47 +02:00
|
|
|
}
|
2011-08-29 21:19:42 +02:00
|
|
|
else
|
|
|
|
{
|
2011-10-04 05:26:55 +02:00
|
|
|
g_mutex_unlock (&object->priv->lock);
|
2011-08-29 21:19:42 +02:00
|
|
|
}
|
2011-04-08 21:14:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const gchar *
|
2011-04-13 22:33:51 +02:00
|
|
|
g_dbus_object_skeleton_get_object_path (GDBusObject *_object)
|
2011-04-08 21:14:47 +02:00
|
|
|
{
|
2011-04-13 22:33:51 +02:00
|
|
|
GDBusObjectSkeleton *object = G_DBUS_OBJECT_SKELETON (_object);
|
2011-08-29 21:19:42 +02:00
|
|
|
const gchar *ret;
|
2011-10-04 05:26:55 +02:00
|
|
|
g_mutex_lock (&object->priv->lock);
|
2011-08-29 21:19:42 +02:00
|
|
|
ret = object->priv->object_path;
|
2011-10-04 05:26:55 +02:00
|
|
|
g_mutex_unlock (&object->priv->lock);
|
2011-08-29 21:19:42 +02:00
|
|
|
return ret;
|
2011-04-08 21:14:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-04-13 22:33:51 +02:00
|
|
|
* g_dbus_object_skeleton_add_interface:
|
|
|
|
* @object: A #GDBusObjectSkeleton.
|
|
|
|
* @interface_: A #GDBusInterfaceSkeleton.
|
2011-04-08 21:14:47 +02:00
|
|
|
*
|
2011-04-11 21:34:38 +02:00
|
|
|
* Adds @interface_ to @object.
|
2011-04-08 21:14:47 +02:00
|
|
|
*
|
2011-04-13 22:33:51 +02:00
|
|
|
* If @object already contains a #GDBusInterfaceSkeleton with the same
|
2011-04-11 21:34:38 +02:00
|
|
|
* interface name, it is removed before @interface_ is added.
|
2011-04-08 21:14:47 +02:00
|
|
|
*
|
2011-04-11 21:34:38 +02:00
|
|
|
* Note that @object takes its own reference on @interface_ and holds
|
2011-04-08 21:14:47 +02:00
|
|
|
* it until removed.
|
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_object_skeleton_add_interface (GDBusObjectSkeleton *object,
|
|
|
|
GDBusInterfaceSkeleton *interface_)
|
2011-04-08 21:14:47 +02:00
|
|
|
{
|
|
|
|
GDBusInterfaceInfo *info;
|
2011-08-29 21:19:42 +02:00
|
|
|
GDBusInterface *interface_to_remove;
|
2011-04-08 21:14:47 +02:00
|
|
|
|
2011-04-13 22:33:51 +02:00
|
|
|
g_return_if_fail (G_IS_DBUS_OBJECT_SKELETON (object));
|
|
|
|
g_return_if_fail (G_IS_DBUS_INTERFACE_SKELETON (interface_));
|
2011-04-08 21:14:47 +02:00
|
|
|
|
2011-10-04 05:26:55 +02:00
|
|
|
g_mutex_lock (&object->priv->lock);
|
2011-08-29 21:19:42 +02:00
|
|
|
|
2011-04-13 22:33:51 +02:00
|
|
|
info = g_dbus_interface_skeleton_get_info (interface_);
|
2011-04-11 21:34:38 +02:00
|
|
|
g_object_ref (interface_);
|
2011-08-29 21:19:42 +02:00
|
|
|
|
|
|
|
interface_to_remove = g_hash_table_lookup (object->priv->map_name_to_iface, info->name);
|
|
|
|
if (interface_to_remove != NULL)
|
|
|
|
{
|
|
|
|
g_object_ref (interface_to_remove);
|
|
|
|
g_warn_if_fail (g_hash_table_remove (object->priv->map_name_to_iface, info->name));
|
|
|
|
}
|
2011-04-08 21:14:47 +02:00
|
|
|
g_hash_table_insert (object->priv->map_name_to_iface,
|
|
|
|
g_strdup (info->name),
|
2011-08-29 21:19:42 +02:00
|
|
|
g_object_ref (interface_));
|
2011-04-11 21:34:38 +02:00
|
|
|
g_dbus_interface_set_object (G_DBUS_INTERFACE (interface_), G_DBUS_OBJECT (object));
|
2011-08-29 21:19:42 +02:00
|
|
|
|
2011-10-04 05:26:55 +02:00
|
|
|
g_mutex_unlock (&object->priv->lock);
|
2011-08-29 21:19:42 +02:00
|
|
|
|
|
|
|
if (interface_to_remove != NULL)
|
|
|
|
{
|
|
|
|
g_dbus_interface_set_object (interface_to_remove, NULL);
|
|
|
|
g_signal_emit_by_name (object,
|
|
|
|
"interface-removed",
|
|
|
|
interface_to_remove);
|
|
|
|
g_object_unref (interface_to_remove);
|
|
|
|
}
|
|
|
|
|
2011-04-08 21:14:47 +02:00
|
|
|
g_signal_emit_by_name (object,
|
|
|
|
"interface-added",
|
2011-04-11 21:34:38 +02:00
|
|
|
interface_);
|
2011-08-29 21:19:42 +02:00
|
|
|
g_object_unref (interface_);
|
2011-04-08 21:14:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-04-13 22:33:51 +02:00
|
|
|
* g_dbus_object_skeleton_remove_interface:
|
|
|
|
* @object: A #GDBusObjectSkeleton.
|
|
|
|
* @interface_: A #GDBusInterfaceSkeleton.
|
2011-04-08 21:14:47 +02:00
|
|
|
*
|
2011-04-11 21:34:38 +02:00
|
|
|
* Removes @interface_ from @object.
|
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_object_skeleton_remove_interface (GDBusObjectSkeleton *object,
|
|
|
|
GDBusInterfaceSkeleton *interface_)
|
2011-04-08 21:14:47 +02:00
|
|
|
{
|
2011-04-13 22:33:51 +02:00
|
|
|
GDBusInterfaceSkeleton *other_interface;
|
2011-04-08 21:14:47 +02:00
|
|
|
GDBusInterfaceInfo *info;
|
|
|
|
|
2011-04-13 22:33:51 +02:00
|
|
|
g_return_if_fail (G_IS_DBUS_OBJECT_SKELETON (object));
|
2011-04-11 21:34:38 +02:00
|
|
|
g_return_if_fail (G_IS_DBUS_INTERFACE (interface_));
|
2011-04-08 21:14:47 +02:00
|
|
|
|
2011-10-04 05:26:55 +02:00
|
|
|
g_mutex_lock (&object->priv->lock);
|
2011-08-29 21:19:42 +02:00
|
|
|
|
2011-04-13 22:33:51 +02:00
|
|
|
info = g_dbus_interface_skeleton_get_info (interface_);
|
2011-04-08 21:14:47 +02:00
|
|
|
|
|
|
|
other_interface = g_hash_table_lookup (object->priv->map_name_to_iface, info->name);
|
|
|
|
if (other_interface == NULL)
|
|
|
|
{
|
2011-10-04 05:26:55 +02:00
|
|
|
g_mutex_unlock (&object->priv->lock);
|
2011-04-08 21:14:47 +02:00
|
|
|
g_warning ("Tried to remove interface with name %s from object "
|
|
|
|
"at path %s but no such interface exists",
|
|
|
|
info->name,
|
|
|
|
object->priv->object_path);
|
|
|
|
}
|
2011-04-11 21:34:38 +02:00
|
|
|
else if (other_interface != interface_)
|
2011-04-08 21:14:47 +02:00
|
|
|
{
|
2011-10-04 05:26:55 +02:00
|
|
|
g_mutex_unlock (&object->priv->lock);
|
2011-04-08 21:14:47 +02:00
|
|
|
g_warning ("Tried to remove interface %p with name %s from object "
|
|
|
|
"at path %s but the object has the interface %p",
|
2011-04-11 21:34:38 +02:00
|
|
|
interface_,
|
2011-04-08 21:14:47 +02:00
|
|
|
info->name,
|
|
|
|
object->priv->object_path,
|
|
|
|
other_interface);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-04-11 21:34:38 +02:00
|
|
|
g_object_ref (interface_);
|
2011-04-08 21:14:47 +02:00
|
|
|
g_warn_if_fail (g_hash_table_remove (object->priv->map_name_to_iface, info->name));
|
2011-10-04 05:26:55 +02:00
|
|
|
g_mutex_unlock (&object->priv->lock);
|
2011-04-11 21:34:38 +02:00
|
|
|
g_dbus_interface_set_object (G_DBUS_INTERFACE (interface_), NULL);
|
2011-04-08 21:14:47 +02:00
|
|
|
g_signal_emit_by_name (object,
|
|
|
|
"interface-removed",
|
2011-04-11 21:34:38 +02:00
|
|
|
interface_);
|
|
|
|
g_object_unref (interface_);
|
2011-04-08 21:14:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2011-04-13 22:33:51 +02:00
|
|
|
* g_dbus_object_skeleton_remove_interface_by_name:
|
|
|
|
* @object: A #GDBusObjectSkeleton.
|
2011-04-08 21:14:47 +02:00
|
|
|
* @interface_name: A D-Bus interface name.
|
|
|
|
*
|
|
|
|
* Removes the #GDBusInterface with @interface_name from @object.
|
|
|
|
*
|
|
|
|
* If no D-Bus interface of the given interface exists, this function
|
|
|
|
* does nothing.
|
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_object_skeleton_remove_interface_by_name (GDBusObjectSkeleton *object,
|
|
|
|
const gchar *interface_name)
|
2011-04-08 21:14:47 +02:00
|
|
|
{
|
|
|
|
GDBusInterface *interface;
|
|
|
|
|
2011-04-13 22:33:51 +02:00
|
|
|
g_return_if_fail (G_IS_DBUS_OBJECT_SKELETON (object));
|
2011-04-08 21:14:47 +02:00
|
|
|
g_return_if_fail (g_dbus_is_interface_name (interface_name));
|
|
|
|
|
2011-10-04 05:26:55 +02:00
|
|
|
g_mutex_lock (&object->priv->lock);
|
2011-04-08 21:14:47 +02:00
|
|
|
interface = g_hash_table_lookup (object->priv->map_name_to_iface, interface_name);
|
|
|
|
if (interface != NULL)
|
|
|
|
{
|
|
|
|
g_object_ref (interface);
|
|
|
|
g_warn_if_fail (g_hash_table_remove (object->priv->map_name_to_iface, interface_name));
|
2011-10-04 05:26:55 +02:00
|
|
|
g_mutex_unlock (&object->priv->lock);
|
2011-04-08 21:14:47 +02:00
|
|
|
g_dbus_interface_set_object (interface, NULL);
|
|
|
|
g_signal_emit_by_name (object,
|
|
|
|
"interface-removed",
|
|
|
|
interface);
|
|
|
|
g_object_unref (interface);
|
|
|
|
}
|
2011-08-29 21:19:42 +02:00
|
|
|
else
|
|
|
|
{
|
2011-10-04 05:26:55 +02:00
|
|
|
g_mutex_unlock (&object->priv->lock);
|
2011-08-29 21:19:42 +02:00
|
|
|
}
|
2011-04-08 21:14:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static GDBusInterface *
|
2011-04-13 22:33:51 +02:00
|
|
|
g_dbus_object_skeleton_get_interface (GDBusObject *_object,
|
|
|
|
const gchar *interface_name)
|
2011-04-08 21:14:47 +02:00
|
|
|
{
|
2011-04-13 22:33:51 +02:00
|
|
|
GDBusObjectSkeleton *object = G_DBUS_OBJECT_SKELETON (_object);
|
2011-04-08 21:14:47 +02:00
|
|
|
GDBusInterface *ret;
|
|
|
|
|
2011-04-13 22:33:51 +02:00
|
|
|
g_return_val_if_fail (G_IS_DBUS_OBJECT_SKELETON (object), NULL);
|
2011-04-08 21:14:47 +02:00
|
|
|
g_return_val_if_fail (g_dbus_is_interface_name (interface_name), NULL);
|
|
|
|
|
2011-10-04 05:26:55 +02:00
|
|
|
g_mutex_lock (&object->priv->lock);
|
2011-04-08 21:14:47 +02:00
|
|
|
ret = g_hash_table_lookup (object->priv->map_name_to_iface, interface_name);
|
|
|
|
if (ret != NULL)
|
|
|
|
g_object_ref (ret);
|
2011-10-04 05:26:55 +02:00
|
|
|
g_mutex_unlock (&object->priv->lock);
|
2011-04-08 21:14:47 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GList *
|
2011-04-13 22:33:51 +02:00
|
|
|
g_dbus_object_skeleton_get_interfaces (GDBusObject *_object)
|
2011-04-08 21:14:47 +02:00
|
|
|
{
|
2011-04-13 22:33:51 +02:00
|
|
|
GDBusObjectSkeleton *object = G_DBUS_OBJECT_SKELETON (_object);
|
2011-04-08 21:14:47 +02:00
|
|
|
GList *ret;
|
|
|
|
|
2011-04-13 22:33:51 +02:00
|
|
|
g_return_val_if_fail (G_IS_DBUS_OBJECT_SKELETON (object), NULL);
|
2011-04-08 21:14:47 +02:00
|
|
|
|
|
|
|
ret = NULL;
|
|
|
|
|
2011-10-04 05:26:55 +02:00
|
|
|
g_mutex_lock (&object->priv->lock);
|
2011-08-29 21:19:42 +02:00
|
|
|
ret = g_hash_table_get_values (object->priv->map_name_to_iface);
|
|
|
|
g_list_foreach (ret, (GFunc) g_object_ref, NULL);
|
2011-10-04 05:26:55 +02:00
|
|
|
g_mutex_unlock (&object->priv->lock);
|
2011-04-08 21:14:47 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-04-13 22:33:51 +02:00
|
|
|
* g_dbus_object_skeleton_flush:
|
|
|
|
* @object: A #GDBusObjectSkeleton.
|
2011-04-08 21:14:47 +02:00
|
|
|
*
|
2011-04-13 22:33:51 +02:00
|
|
|
* This method simply calls g_dbus_interface_skeleton_flush() on all
|
|
|
|
* interfaces belonging to @object. See that method for when flushing
|
|
|
|
* is useful.
|
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_object_skeleton_flush (GDBusObjectSkeleton *object)
|
2011-04-08 21:14:47 +02:00
|
|
|
{
|
2011-08-29 21:19:42 +02:00
|
|
|
GList *to_flush, *l;
|
2011-04-08 21:14:47 +02:00
|
|
|
|
2011-10-04 05:26:55 +02:00
|
|
|
g_mutex_lock (&object->priv->lock);
|
2011-08-29 21:19:42 +02:00
|
|
|
to_flush = g_hash_table_get_values (object->priv->map_name_to_iface);
|
|
|
|
g_list_foreach (to_flush, (GFunc) g_object_ref, NULL);
|
2011-10-04 05:26:55 +02:00
|
|
|
g_mutex_unlock (&object->priv->lock);
|
2011-08-29 21:19:42 +02:00
|
|
|
|
|
|
|
for (l = to_flush; l != NULL; l = l->next)
|
|
|
|
g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (l->data));
|
|
|
|
|
2012-01-02 16:30:11 +01:00
|
|
|
g_list_free_full (to_flush, g_object_unref);
|
2011-04-08 21:14:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dbus_object_interface_init (GDBusObjectIface *iface)
|
|
|
|
{
|
2011-04-13 22:33:51 +02:00
|
|
|
iface->get_object_path = g_dbus_object_skeleton_get_object_path;
|
|
|
|
iface->get_interfaces = g_dbus_object_skeleton_get_interfaces;
|
|
|
|
iface->get_interface = g_dbus_object_skeleton_get_interface;
|
2011-04-08 21:14:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2011-04-13 22:33:51 +02:00
|
|
|
_g_dbus_object_skeleton_has_authorize_method_handlers (GDBusObjectSkeleton *object)
|
2011-04-08 21:14:47 +02:00
|
|
|
{
|
|
|
|
gboolean has_handlers;
|
|
|
|
gboolean has_default_class_handler;
|
|
|
|
|
2011-04-13 22:33:51 +02:00
|
|
|
has_handlers = g_signal_has_handler_pending (object,
|
2011-04-08 21:14:47 +02:00
|
|
|
signals[AUTHORIZE_METHOD_SIGNAL],
|
|
|
|
0,
|
|
|
|
TRUE);
|
2011-04-13 22:33:51 +02:00
|
|
|
has_default_class_handler = (G_DBUS_OBJECT_SKELETON_GET_CLASS (object)->authorize_method ==
|
|
|
|
g_dbus_object_skeleton_authorize_method_default);
|
2011-04-08 21:14:47 +02:00
|
|
|
|
|
|
|
return has_handlers || !has_default_class_handler;
|
|
|
|
}
|