X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fat-spi2-atk.git;a=blobdiff_plain;f=atk-adaptor%2Faccessible-cache.c;h=5065a00ebb83ccce91a6b6abc8a94e542b757d97;hp=4f87b1801acf8c98bc3a4cb927d27397a515c983;hb=548478747b2493842b736b4a1e2bc6bb3015f790;hpb=5713a8e46559b6de9fbf5fc3e073d0d482d8c7e1 diff --git a/atk-adaptor/accessible-cache.c b/atk-adaptor/accessible-cache.c index 4f87b18..5065a00 100644 --- a/atk-adaptor/accessible-cache.c +++ b/atk-adaptor/accessible-cache.c @@ -21,6 +21,7 @@ */ #include +#include #include "accessible-cache.h" #include "accessible-register.h" @@ -38,7 +39,7 @@ toplevel_added_listener (AtkObject * accessible, guint index, AtkObject * child); static void -remove_object (gpointer data, GObject * gobj); +remove_object (GObject * source, GObject * gobj, gpointer data); static void add_object (SpiCache * cache, GObject * gobj); @@ -46,14 +47,14 @@ add_object (SpiCache * cache, GObject * gobj); static void add_subtree (SpiCache *cache, AtkObject * accessible); +static gboolean +add_pending_items (gpointer data); + /*---------------------------------------------------------------------------*/ static void spi_cache_finalize (GObject * object); -static void -spi_cache_dispose (GObject * object); - /*---------------------------------------------------------------------------*/ enum @@ -75,7 +76,6 @@ static void spi_cache_class_init (SpiCacheClass * klass) spi_cache_parent_class = g_type_class_ref (G_TYPE_OBJECT); object_class->finalize = spi_cache_finalize; - object_class->dispose = spi_cache_dispose; cache_signals [OBJECT_ADDED] = \ g_signal_new ("object-added", @@ -106,6 +106,7 @@ static void spi_cache_init (SpiCache * cache) { cache->objects = g_hash_table_new (g_direct_hash, g_direct_equal); + cache->add_traversal = g_queue_new (); #ifdef SPI_ATK_DEBUG if (g_thread_supported ()) @@ -120,8 +121,8 @@ spi_cache_init (SpiCache * cache) add_subtree (cache, spi_global_app_data->root); - atk_add_global_event_listener (child_added_listener, - "Gtk:AtkObject:children-changed"); + cache->child_added_listener = atk_add_global_event_listener (child_added_listener, + "Gtk:AtkObject:children-changed"); g_signal_connect (G_OBJECT (spi_global_app_data->root), "children-changed::add", @@ -133,31 +134,43 @@ spi_cache_finalize (GObject * object) { SpiCache *cache = SPI_CACHE (object); - g_free (cache->objects); + while (!g_queue_is_empty (cache->add_traversal)) + g_object_unref (G_OBJECT (g_queue_pop_head (cache->add_traversal))); + g_queue_free (cache->add_traversal); + g_hash_table_unref (cache->objects); - G_OBJECT_CLASS (spi_cache_parent_class)->finalize (object); -} + g_signal_handlers_disconnect_by_func (spi_global_register, + (GCallback) remove_object, cache); -static void -spi_cache_dispose (GObject * object) -{ - SpiCache *cache = SPI_CACHE (object); + g_signal_handlers_disconnect_by_func (G_OBJECT (spi_global_app_data->root), + (GCallback) toplevel_added_listener, NULL); - G_OBJECT_CLASS (spi_cache_parent_class)->dispose (object); + atk_remove_global_event_listener (cache->child_added_listener); + + G_OBJECT_CLASS (spi_cache_parent_class)->finalize (object); } /*---------------------------------------------------------------------------*/ static void -remove_object (gpointer data, GObject * gobj) +remove_object (GObject * source, GObject * gobj, gpointer data) { SpiCache *cache = SPI_CACHE (data); if (spi_cache_in (cache, gobj)) { +#ifdef SPI_ATK_DEBUG + g_debug ("CACHE REM - %s - %d - %s\n", atk_object_get_name (ATK_OBJECT (gobj)), + atk_object_get_role (ATK_OBJECT (gobj)), + spi_register_object_to_path (spi_global_register, gobj)); +#endif g_signal_emit (cache, cache_signals [OBJECT_REMOVED], 0, gobj); g_hash_table_remove (cache->objects, gobj); } + else if (g_queue_remove (cache->add_traversal, gobj)) + { + g_object_unref (gobj); + } } static void @@ -167,14 +180,21 @@ add_object (SpiCache * cache, GObject * gobj) g_hash_table_insert (cache->objects, gobj, NULL); +#ifdef SPI_ATK_DEBUG + g_debug ("CACHE ADD - %s - %d - %s\n", atk_object_get_name (ATK_OBJECT (gobj)), + atk_object_get_role (ATK_OBJECT (gobj)), + spi_register_object_to_path (spi_global_register, gobj)); +#endif + g_signal_emit (cache, cache_signals [OBJECT_ADDED], 0, gobj); } /*---------------------------------------------------------------------------*/ -static GStaticRecMutex cache_mutex = G_STATIC_REC_MUTEX_INIT; -static GStaticMutex recursion_check_guard = G_STATIC_MUTEX_INIT; +static GRecMutex cache_mutex; +#ifdef SPI_ATK_DEBUG +static GStaticMutex recursion_check_guard = G_STATIC_MUTEX_INIT; static gboolean recursion_check = FALSE; static gboolean @@ -195,6 +215,7 @@ recursion_check_unset () recursion_check = FALSE; g_static_mutex_unlock (&recursion_check_guard); } +#endif /* SPI_ATK_DEBUG */ /*---------------------------------------------------------------------------*/ @@ -229,52 +250,66 @@ append_children (AtkObject * accessible, GQueue * traversal) static void add_subtree (SpiCache *cache, AtkObject * accessible) { + g_return_if_fail (ATK_IS_OBJECT (accessible)); + + g_object_ref (accessible); + g_queue_push_tail (cache->add_traversal, accessible); + add_pending_items (cache); +} + +static gboolean +add_pending_items (gpointer data) +{ + SpiCache *cache = SPI_CACHE (data); AtkObject *current; - GQueue *traversal; GQueue *to_add; - g_return_if_fail (ATK_IS_OBJECT (accessible)); - - traversal = g_queue_new (); to_add = g_queue_new (); - g_object_ref (accessible); - g_queue_push_tail (traversal, accessible); - - while (!g_queue_is_empty (traversal)) + while (!g_queue_is_empty (cache->add_traversal)) { AtkStateSet *set; - - current = g_queue_pop_head (traversal); + + /* cache->add_traversal holds a ref to current */ + current = g_queue_pop_head (cache->add_traversal); set = atk_object_ref_state_set (current); - if (!atk_state_set_contains_state (set, ATK_STATE_TRANSIENT)) + if (set && !atk_state_set_contains_state (set, ATK_STATE_TRANSIENT)) { + /* transfer the ref into to_add */ g_queue_push_tail (to_add, current); if (!spi_cache_in (cache, G_OBJECT (current)) && - !atk_state_set_contains_state (set, ATK_STATE_MANAGES_DESCENDANTS)) + !atk_state_set_contains_state (set, ATK_STATE_MANAGES_DESCENDANTS) && + !atk_state_set_contains_state (set, ATK_STATE_DEFUNCT)) { -#ifdef SPI_ATK_DEBUG - g_debug ("REG - %s - %d - %s", atk_object_get_name (current), - atk_object_get_role (current), - atk_dbus_object_to_path (current)); -#endif - append_children (current, traversal); + append_children (current, cache->add_traversal); } } + else + { + /* drop the ref for the removed object */ + g_object_unref (current); + } - g_object_unref (set); + if (set) + g_object_unref (set); } while (!g_queue_is_empty (to_add)) { current = g_queue_pop_head (to_add); + + /* Make sure object is registerd so we are notified if it goes away */ + g_free (spi_register_object_to_path (spi_global_register, + G_OBJECT (current))); + add_object (cache, G_OBJECT(current)); g_object_unref (G_OBJECT (current)); } - g_queue_free (traversal); g_queue_free (to_add); + cache->add_pending_idle = 0; + return FALSE; } /*---------------------------------------------------------------------------*/ @@ -285,13 +320,11 @@ child_added_listener (GSignalInvocationHint * signal_hint, const GValue * param_values, gpointer data) { SpiCache *cache = spi_global_cache; - AtkObject *accessible; - AtkObject *child; const gchar *detail = NULL; - g_static_rec_mutex_lock (&cache_mutex); + g_rec_mutex_lock (&cache_mutex); /* * Ensure that only accessibles already in the cache @@ -311,24 +344,28 @@ child_added_listener (GSignalInvocationHint * signal_hint, if (signal_hint->detail) detail = g_quark_to_string (signal_hint->detail); - if (!strcmp (detail, "add")) + if (detail && !strncmp (detail, "add", 3)) { gpointer child; - int index = g_value_get_uint (param_values + 1); child = g_value_get_pointer (param_values + 2); + if (!child) + { + g_rec_mutex_unlock (&cache_mutex); + return TRUE; + } + + g_object_ref (child); + g_queue_push_tail (cache->add_traversal, child); - if (!ATK_IS_OBJECT (child)) - { - child = atk_object_ref_accessible_child (accessible, index); - } - add_subtree (cache, child); + if (cache->add_pending_idle == 0) + cache->add_pending_idle = g_idle_add (add_pending_items, cache); } #ifdef SPI_ATK_DEBUG recursion_check_unset (); #endif } - g_static_rec_mutex_unlock (&cache_mutex); + g_rec_mutex_unlock (&cache_mutex); return TRUE; } @@ -341,7 +378,7 @@ toplevel_added_listener (AtkObject * accessible, { SpiCache *cache = spi_global_cache; - g_static_rec_mutex_lock (&cache_mutex); + g_rec_mutex_lock (&cache_mutex); g_return_if_fail (ATK_IS_OBJECT (accessible)); @@ -357,13 +394,19 @@ toplevel_added_listener (AtkObject * accessible, { child = atk_object_ref_accessible_child (accessible, index); } - add_subtree (cache, child); + else + g_object_ref (child); + + g_queue_push_tail (cache->add_traversal, child); + + if (cache->add_pending_idle == 0) + cache->add_pending_idle = g_idle_add (add_pending_items, cache); #ifdef SPI_ATK_DEBUG recursion_check_unset (); #endif } - g_static_rec_mutex_unlock (&cache_mutex); + g_rec_mutex_unlock (&cache_mutex); } /*---------------------------------------------------------------------------*/ @@ -377,6 +420,9 @@ spi_cache_foreach (SpiCache * cache, GHFunc func, gpointer data) gboolean spi_cache_in (SpiCache * cache, GObject * object) { + if (!cache) + return FALSE; + if (g_hash_table_lookup_extended (cache->objects, object, NULL, @@ -386,4 +432,20 @@ spi_cache_in (SpiCache * cache, GObject * object) return FALSE; } +#ifdef SPI_ATK_DEBUG +void +spi_cache_print_info (GObject * obj) +{ + char * path = spi_register_object_to_path (spi_global_register, obj); + + if (spi_cache_in (spi_global_cache, obj)) + g_printf ("%s IC\n", path); + else + g_printf ("%s NC\n", path); + + if (path) + g_free (path); +} +#endif + /*END------------------------------------------------------------------------*/