X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gio%2Fgdbusobjectskeleton.c;h=e0d01669a561bc689320cf0930bcc6fcef173700;hb=2138deb07ebb7d7e541c0cd35b966e107d1bf800;hp=33628460ad54cd24d5d870fa7ece97ab22d787e5;hpb=6ccca55752c41001f3af3430d3d93f587fd42383;p=platform%2Fupstream%2Fglib.git diff --git a/gio/gdbusobjectskeleton.c b/gio/gdbusobjectskeleton.c index 3362846..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 */ @@ -25,7 +23,6 @@ #include "gdbusobject.h" #include "gdbusobjectskeleton.h" #include "gdbusinterfaceskeleton.h" -#include "gio-marshal.h" #include "gdbusprivate.h" #include "gdbusmethodinvocation.h" #include "gdbusintrospection.h" @@ -48,6 +45,7 @@ struct _GDBusObjectSkeletonPrivate { + GMutex lock; gchar *object_path; GHashTable *map_name_to_iface; }; @@ -55,7 +53,7 @@ struct _GDBusObjectSkeletonPrivate enum { PROP_0, - PROP_OBJECT_PATH + PROP_G_OBJECT_PATH }; enum @@ -69,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 @@ -80,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); } @@ -94,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; } } @@ -114,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; } } @@ -144,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, @@ -164,15 +167,15 @@ g_dbus_object_skeleton_class_init (GDBusObjectSkeletonClass *klass) /** * GDBusObjectSkeleton::authorize-method: * @object: The #GDBusObjectSkeleton emitting the signal. - * @interface: The #GDBusInterfaceSkeleton that @invocation is on. + * @interface: The #GDBusInterfaceSkeleton that @invocation is for. * @invocation: A #GDBusMethodInvocation. * * 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. * @@ -187,19 +190,18 @@ g_dbus_object_skeleton_class_init (GDBusObjectSkeletonClass *klass) G_STRUCT_OFFSET (GDBusObjectSkeletonClass, authorize_method), _g_signal_accumulator_false_handled, NULL, - _gio_marshal_BOOLEAN__OBJECT_OBJECT, + NULL, G_TYPE_BOOLEAN, 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, @@ -221,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)); } @@ -240,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); } } @@ -253,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; } /** @@ -276,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_); } /** @@ -311,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, @@ -323,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_, @@ -334,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", @@ -364,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 * @@ -387,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; } @@ -398,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; } @@ -425,43 +471,17 @@ g_dbus_object_skeleton_get_interfaces (GDBusObject *_object) void g_dbus_object_skeleton_flush (GDBusObjectSkeleton *object) { - GHashTableIter iter; - GDBusInterfaceSkeleton *interface_skeleton; - - 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); - } -} + GList *to_flush, *l; -static gpointer -g_dbus_object_skeleton_lookup_with_typecheck (GDBusObject *object, - const gchar *interface_name, - GType type) -{ - GDBusObjectSkeleton *skeleton = G_DBUS_OBJECT_SKELETON (object); - GDBusProxy *ret; + 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); - ret = g_hash_table_lookup (skeleton->priv->map_name_to_iface, interface_name); - if (ret != NULL) - { - g_warn_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (ret, type)); - g_object_ref (ret); - } - return ret; -} + for (l = to_flush; l != NULL; l = l->next) + g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (l->data)); -static gpointer -g_dbus_object_skeleton_peek_with_typecheck (GDBusObject *object, - const gchar *interface_name, - GType type) -{ - GDBusInterfaceSkeleton *ret; - ret = g_dbus_object_skeleton_lookup_with_typecheck (object, interface_name, type); - if (ret != NULL) - g_object_unref (ret); - return ret; + g_list_free_full (to_flush, g_object_unref); } static void @@ -470,8 +490,6 @@ dbus_object_interface_init (GDBusObjectIface *iface) 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; - iface->lookup_with_typecheck = g_dbus_object_skeleton_lookup_with_typecheck; - iface->peek_with_typecheck = g_dbus_object_skeleton_peek_with_typecheck; } gboolean