X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gio%2Fgdbusobjectskeleton.c;h=e0d01669a561bc689320cf0930bcc6fcef173700;hb=7fd6f07d498063470903a886b4805a13bd333908;hp=869007e4d069b0e69965136e353040440d50ae2a;hpb=ec98953e42a20061427b20681d1e31501907e2fa;p=platform%2Fupstream%2Fglib.git
diff --git a/gio/gdbusobjectskeleton.c b/gio/gdbusobjectskeleton.c
index 869007e..e0d0166 100644
--- a/gio/gdbusobjectskeleton.c
+++ b/gio/gdbusobjectskeleton.c
@@ -13,9 +13,7 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Public License along with this library; if not, see .
*
* Author: David Zeuthen
*/
@@ -47,6 +45,7 @@
struct _GDBusObjectSkeletonPrivate
{
+ GMutex lock;
gchar *object_path;
GHashTable *map_name_to_iface;
};
@@ -54,7 +53,7 @@ struct _GDBusObjectSkeletonPrivate
enum
{
PROP_0,
- PROP_OBJECT_PATH
+ PROP_G_OBJECT_PATH
};
enum
@@ -68,7 +67,8 @@ static guint signals[LAST_SIGNAL] = {0};
static void dbus_object_interface_init (GDBusObjectIface *iface);
G_DEFINE_TYPE_WITH_CODE (GDBusObjectSkeleton, g_dbus_object_skeleton, G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT, dbus_object_interface_init));
+ G_ADD_PRIVATE (GDBusObjectSkeleton)
+ G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT, dbus_object_interface_init))
static void
@@ -79,6 +79,8 @@ g_dbus_object_skeleton_finalize (GObject *_object)
g_free (object->priv->object_path);
g_hash_table_unref (object->priv->map_name_to_iface);
+ g_mutex_clear (&object->priv->lock);
+
if (G_OBJECT_CLASS (g_dbus_object_skeleton_parent_class)->finalize != NULL)
G_OBJECT_CLASS (g_dbus_object_skeleton_parent_class)->finalize (_object);
}
@@ -93,12 +95,14 @@ g_dbus_object_skeleton_get_property (GObject *_object,
switch (prop_id)
{
- case PROP_OBJECT_PATH:
- g_value_take_string (value, object->priv->object_path);
+ case PROP_G_OBJECT_PATH:
+ g_mutex_lock (&object->priv->lock);
+ g_value_set_string (value, object->priv->object_path);
+ g_mutex_unlock (&object->priv->lock);
break;
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (_object, prop_id, pspec);
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
@@ -113,12 +117,12 @@ g_dbus_object_skeleton_set_property (GObject *_object,
switch (prop_id)
{
- case PROP_OBJECT_PATH:
+ case PROP_G_OBJECT_PATH:
g_dbus_object_skeleton_set_object_path (object, g_value_get_string (value));
break;
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (_object, prop_id, pspec);
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
@@ -143,15 +147,15 @@ g_dbus_object_skeleton_class_init (GDBusObjectSkeletonClass *klass)
klass->authorize_method = g_dbus_object_skeleton_authorize_method_default;
/**
- * GDBusObjectSkeleton:object-path:
+ * GDBusObjectSkeleton:g-object-path:
*
* The object path where the object is exported.
*
* Since: 2.30
*/
g_object_class_install_property (gobject_class,
- PROP_OBJECT_PATH,
- g_param_spec_string ("object-path",
+ PROP_G_OBJECT_PATH,
+ g_param_spec_string ("g-object-path",
"Object Path",
"The object path where the object is exported",
NULL,
@@ -169,9 +173,9 @@ g_dbus_object_skeleton_class_init (GDBusObjectSkeletonClass *klass)
* Emitted when a method is invoked by a remote caller and used to
* determine if the method call is authorized.
*
- * This signal is like #GDBusInterfaceSkeleton's
- * #GDBusInterfaceSkeleton::g-authorize-method signal, except that it is
- * for the enclosing object.
+ * This signal is like #GDBusInterfaceSkeleton's
+ * #GDBusInterfaceSkeleton::g-authorize-method signal,
+ * except that it is for the enclosing object.
*
* The default class handler just returns %TRUE.
*
@@ -191,14 +195,13 @@ g_dbus_object_skeleton_class_init (GDBusObjectSkeletonClass *klass)
2,
G_TYPE_DBUS_INTERFACE_SKELETON,
G_TYPE_DBUS_METHOD_INVOCATION);
-
- g_type_class_add_private (klass, sizeof (GDBusObjectSkeletonPrivate));
}
static void
g_dbus_object_skeleton_init (GDBusObjectSkeleton *object)
{
- object->priv = G_TYPE_INSTANCE_GET_PRIVATE (object, G_TYPE_DBUS_OBJECT_SKELETON, GDBusObjectSkeletonPrivate);
+ object->priv = g_dbus_object_skeleton_get_instance_private (object);
+ g_mutex_init (&object->priv->lock);
object->priv->map_name_to_iface = g_hash_table_new_full (g_str_hash,
g_str_equal,
g_free,
@@ -220,7 +223,7 @@ g_dbus_object_skeleton_new (const gchar *object_path)
{
g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);
return G_DBUS_OBJECT_SKELETON (g_object_new (G_TYPE_DBUS_OBJECT_SKELETON,
- "object-path", object_path,
+ "g-object-path", object_path,
NULL));
}
@@ -239,12 +242,18 @@ g_dbus_object_skeleton_set_object_path (GDBusObjectSkeleton *object,
{
g_return_if_fail (G_IS_DBUS_OBJECT_SKELETON (object));
g_return_if_fail (object_path == NULL || g_variant_is_object_path (object_path));
+ g_mutex_lock (&object->priv->lock);
/* 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);
- g_object_notify (G_OBJECT (object), "object-path");
+ g_mutex_unlock (&object->priv->lock);
+ g_object_notify (G_OBJECT (object), "g-object-path");
+ }
+ else
+ {
+ g_mutex_unlock (&object->priv->lock);
}
}
@@ -252,7 +261,11 @@ static const gchar *
g_dbus_object_skeleton_get_object_path (GDBusObject *_object)
{
GDBusObjectSkeleton *object = G_DBUS_OBJECT_SKELETON (_object);
- return object->priv->object_path;
+ const gchar *ret;
+ g_mutex_lock (&object->priv->lock);
+ ret = object->priv->object_path;
+ g_mutex_unlock (&object->priv->lock);
+ return ret;
}
/**
@@ -275,20 +288,42 @@ g_dbus_object_skeleton_add_interface (GDBusObjectSkeleton *object,
GDBusInterfaceSkeleton *interface_)
{
GDBusInterfaceInfo *info;
+ GDBusInterface *interface_to_remove;
g_return_if_fail (G_IS_DBUS_OBJECT_SKELETON (object));
g_return_if_fail (G_IS_DBUS_INTERFACE_SKELETON (interface_));
+ g_mutex_lock (&object->priv->lock);
+
info = g_dbus_interface_skeleton_get_info (interface_);
g_object_ref (interface_);
- g_dbus_object_skeleton_remove_interface_by_name (object, info->name);
+
+ 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));
+ }
g_hash_table_insert (object->priv->map_name_to_iface,
g_strdup (info->name),
- interface_);
+ g_object_ref (interface_));
g_dbus_interface_set_object (G_DBUS_INTERFACE (interface_), G_DBUS_OBJECT (object));
+
+ g_mutex_unlock (&object->priv->lock);
+
+ 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);
+ }
+
g_signal_emit_by_name (object,
"interface-added",
interface_);
+ g_object_unref (interface_);
}
/**
@@ -310,11 +345,14 @@ g_dbus_object_skeleton_remove_interface (GDBusObjectSkeleton *object,
g_return_if_fail (G_IS_DBUS_OBJECT_SKELETON (object));
g_return_if_fail (G_IS_DBUS_INTERFACE (interface_));
+ g_mutex_lock (&object->priv->lock);
+
info = g_dbus_interface_skeleton_get_info (interface_);
other_interface = g_hash_table_lookup (object->priv->map_name_to_iface, info->name);
if (other_interface == NULL)
{
+ g_mutex_unlock (&object->priv->lock);
g_warning ("Tried to remove interface with name %s from object "
"at path %s but no such interface exists",
info->name,
@@ -322,6 +360,7 @@ g_dbus_object_skeleton_remove_interface (GDBusObjectSkeleton *object,
}
else if (other_interface != interface_)
{
+ g_mutex_unlock (&object->priv->lock);
g_warning ("Tried to remove interface %p with name %s from object "
"at path %s but the object has the interface %p",
interface_,
@@ -333,6 +372,7 @@ g_dbus_object_skeleton_remove_interface (GDBusObjectSkeleton *object,
{
g_object_ref (interface_);
g_warn_if_fail (g_hash_table_remove (object->priv->map_name_to_iface, info->name));
+ g_mutex_unlock (&object->priv->lock);
g_dbus_interface_set_object (G_DBUS_INTERFACE (interface_), NULL);
g_signal_emit_by_name (object,
"interface-removed",
@@ -363,17 +403,23 @@ g_dbus_object_skeleton_remove_interface_by_name (GDBusObjectSkeleton *object,
g_return_if_fail (G_IS_DBUS_OBJECT_SKELETON (object));
g_return_if_fail (g_dbus_is_interface_name (interface_name));
+ g_mutex_lock (&object->priv->lock);
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));
+ g_mutex_unlock (&object->priv->lock);
g_dbus_interface_set_object (interface, NULL);
g_signal_emit_by_name (object,
"interface-removed",
interface);
g_object_unref (interface);
}
+ else
+ {
+ g_mutex_unlock (&object->priv->lock);
+ }
}
static GDBusInterface *
@@ -386,9 +432,11 @@ g_dbus_object_skeleton_get_interface (GDBusObject *_object,
g_return_val_if_fail (G_IS_DBUS_OBJECT_SKELETON (object), NULL);
g_return_val_if_fail (g_dbus_is_interface_name (interface_name), NULL);
+ g_mutex_lock (&object->priv->lock);
ret = g_hash_table_lookup (object->priv->map_name_to_iface, interface_name);
if (ret != NULL)
g_object_ref (ret);
+ g_mutex_unlock (&object->priv->lock);
return ret;
}
@@ -397,16 +445,15 @@ g_dbus_object_skeleton_get_interfaces (GDBusObject *_object)
{
GDBusObjectSkeleton *object = G_DBUS_OBJECT_SKELETON (_object);
GList *ret;
- GHashTableIter iter;
- GDBusInterface *interface;
g_return_val_if_fail (G_IS_DBUS_OBJECT_SKELETON (object), NULL);
ret = NULL;
- g_hash_table_iter_init (&iter, object->priv->map_name_to_iface);
- while (g_hash_table_iter_next (&iter, NULL, (gpointer) &interface))
- ret = g_list_prepend (ret, g_object_ref (interface));
+ g_mutex_lock (&object->priv->lock);
+ ret = g_hash_table_get_values (object->priv->map_name_to_iface);
+ g_list_foreach (ret, (GFunc) g_object_ref, NULL);
+ g_mutex_unlock (&object->priv->lock);
return ret;
}
@@ -424,14 +471,17 @@ g_dbus_object_skeleton_get_interfaces (GDBusObject *_object)
void
g_dbus_object_skeleton_flush (GDBusObjectSkeleton *object)
{
- GHashTableIter iter;
- GDBusInterfaceSkeleton *interface_skeleton;
+ GList *to_flush, *l;
- g_hash_table_iter_init (&iter, object->priv->map_name_to_iface);
- while (g_hash_table_iter_next (&iter, NULL, (gpointer) &interface_skeleton))
- {
- g_dbus_interface_skeleton_flush (interface_skeleton);
- }
+ g_mutex_lock (&object->priv->lock);
+ to_flush = g_hash_table_get_values (object->priv->map_name_to_iface);
+ g_list_foreach (to_flush, (GFunc) g_object_ref, NULL);
+ g_mutex_unlock (&object->priv->lock);
+
+ for (l = to_flush; l != NULL; l = l->next)
+ g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (l->data));
+
+ g_list_free_full (to_flush, g_object_unref);
}
static void