* the client side cache. This is done using the 'update' signal of the
* org.freedesktop.atspi.Tree interface. The update signal should send out
* all of the cacheable data for an Accessible object.
+ *
*/
-GHashTable *ref2ptr = NULL; /* Used for converting a D-Bus path (Reference) to the object pointer */
+/*
+ * FIXME
+ *
+ * While traversing the ATK tree we may modify it unintentionally.
+ * This is either a bug in the Gail implementation or this module.
+ * If a change is caused that recurses, via a signal into this module
+ * we should catch it.
+ *
+ * Things could also be changed that do not cause signal emission,
+ * but do cause a failure. Not sure what these would be.
+ *
+ * The other option is that there are threads that modify the GUI.
+ * This IS A BUG IN THE PROGRAM. But it may happen. If seeing very
+ * odd bugs change this to take the GDK lock. Just to make sure.
+ */
+
+static GHashTable *ref2ptr = NULL; /* Used for converting a D-Bus path (Reference) to the object pointer */
static guint counter = 1;
+static GStaticRecMutex registration_mutex = G_STATIC_REC_MUTEX_INIT;
+
+/*---------------------------------------------------------------------------*/
+
+static GStaticMutex recursion_check_guard = G_STATIC_MUTEX_INIT;
+static gboolean recursion_check = FALSE;
+
+static gboolean
+recursion_check_and_set ()
+{
+ gboolean ret;
+ g_static_mutex_lock (&recursion_check_guard);
+ ret = recursion_check;
+ recursion_check = TRUE;
+ g_static_mutex_unlock (&recursion_check_guard);
+ return ret;
+}
+
+static void
+recursion_check_unset ()
+{
+ g_static_mutex_lock (&recursion_check_guard);
+ recursion_check = FALSE;
+ g_static_mutex_unlock (&recursion_check_guard);
+}
+
/*---------------------------------------------------------------------------*/
/*
/*---------------------------------------------------------------------------*/
/*
+ * Callback for when a registered AtkObject is destroyed.
+ *
* Removes the AtkObject from the reference lookup tables, meaning
* it is no longer exposed over D-Bus.
*/
static void
-deregister_accessible (guint ref)
-{
- g_hash_table_remove(ref2ptr, GINT_TO_POINTER(ref));
-}
-
-/*
- * Callback for when a registered AtkObject is destroyed.
- */
-static void
-deregister_callback (gpointer data, GObject *accessible)
+deregister_accessible (gpointer data, GObject *accessible)
{
guint ref;
g_assert (ATK_IS_OBJECT (accessible));
ref = object_to_ref (ATK_OBJECT(accessible));
if (ref != 0)
{
- deregister_accessible (ref);
+ g_hash_table_remove(ref2ptr, GINT_TO_POINTER(ref));
}
}
g_hash_table_insert (ref2ptr, GINT_TO_POINTER(ref), accessible);
g_object_set_data (G_OBJECT(accessible), "dbus-id", GINT_TO_POINTER(ref));
- g_object_weak_ref(G_OBJECT(accessible), deregister_callback, NULL);
+ g_object_weak_ref(G_OBJECT(accessible), deregister_accessible, NULL);
}
/*---------------------------------------------------------------------------*/
-typedef void (*ActionFunc) (GList **, AtkObject *);
+/*
+ * This function checks that the ref-count of an accessible
+ * is greater than 1.
+ *
+ * There is not currently any remote reference counting
+ * in AT-SPI D-Bus so objects that are remotely owned are not
+ * allowed.
+ *
+ * HACK - Needs permanent soltion.
+ * TODO Add debug wrapper
+ */
+static gboolean
+non_owned_accessible (AtkObject *accessible)
+{
+ if ((G_OBJECT (accessible))->ref_count <= 1)
+ {
+ g_critical ("AT-SPI: Child referenced that is not owned by its parent");
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+}
+
+/*---------------------------------------------------------------------------*/
-/* Return true if action should be performed */
-typedef gboolean (*FilterFunc) (AtkObject *);
+static gboolean
+has_manages_descendants (AtkObject *accessible)
+{
+ AtkStateSet *state;
+ gboolean result = FALSE;
+
+ /* This is dangerous, refing the state set
+ * seems to do wierd things to the tree & cause recursion
+ * by modifying the tree alot.
+ */
+ state = atk_object_ref_state_set (accessible);
+ if (atk_state_set_contains_state (state, ATK_STATE_MANAGES_DESCENDANTS))
+ {
+ g_message ("AT-SPI: Object with 'Manages descendants' states not currently handled by AT-SPI");
+ result = TRUE;
+ }
+ g_object_unref (state);
+
+ return result;
+}
/*
- * This function performs a depth first traversal of a tree of AtkObjects.
+ * Registers a subtree of accessible objects
+ * rooted at the accessible object provided.
*
- * It uses a FilterFunc to determine if a node needs to have an action
- * performed on it.
- *
- * Nodes that are filtered out become leaves and no recursion is performed on
- * them.
+ * The leaf nodes do not have their children
+ * registered. A node is considered a leaf
+ * if it has the state "manages-descendants"
+ * or if it has already been registered.
*/
void
-traverse_atk_tree (AtkObject *accessible,
- GList **visited,
- ActionFunc action,
- FilterFunc filter)
+register_subtree (AtkObject *accessible)
{
AtkObject *current, *tmp;
GQueue *stack;
guint i;
gboolean recurse;
- if (filter (accessible))
+
+ current = g_object_ref (accessible);
+ if (has_manages_descendants (current))
+ {
+ g_object_unref (current);
return;
+ }
stack = g_queue_new ();
- current = g_object_ref (accessible);
- action (visited, current);
+
+ register_accessible (current);
g_queue_push_head (stack, GINT_TO_POINTER (0));
/*
while (!g_queue_is_empty (stack))
{
/* Find the next child node that needs processing */
+
i = GPOINTER_TO_INT(g_queue_peek_head (stack));
recurse = FALSE;
+
while (i < atk_object_get_n_accessible_children (current) &&
recurse == FALSE)
{
tmp = atk_object_ref_accessible_child (current, i);
- /* If filter function */
- if (!filter (tmp))
+
+ /* TODO Add debug wrapper */
+ if (non_owned_accessible (tmp))
{
- recurse = TRUE;
+ i++;
+ continue;
+ }
+
+ if (object_to_ref (tmp))
+ {
+ /* If its already registered, just update */
+ spi_emit_cache_update (tmp, atk_adaptor_app_data->bus);
+ }
+ else if (has_manages_descendants (tmp))
+ {
+ /* If it has manages descendants, just register and update */
+ register_accessible (tmp);
+ spi_emit_cache_update (tmp, atk_adaptor_app_data->bus);
}
else
{
+ recurse = TRUE;
+ }
+
+ if (!recurse)
+ {
i++;
g_object_unref (G_OBJECT (tmp));
}
{
/* Push onto stack */
current = tmp;
- action (visited, current);
+ register_accessible (current);
+
g_queue_peek_head_link (stack)->data = GINT_TO_POINTER (i+1);
g_queue_push_head (stack, GINT_TO_POINTER (0));
}
else
{
/* Pop from stack */
+ spi_emit_cache_update (current, atk_adaptor_app_data->bus);
tmp = current;
current = atk_object_get_parent (current);
g_object_unref (G_OBJECT (tmp));
g_queue_pop_head (stack);
}
}
+ g_queue_free (stack);
}
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
-static gboolean
-register_filter (AtkObject *accessible)
-{
- if (object_to_ref (accessible))
- return TRUE;
- else
- return FALSE;
-}
-
-static void
-register_action (GList **registered, AtkObject *accessible)
-{
- register_accessible (accessible);
- *registered = g_list_prepend (*registered, accessible);
-}
-
-static void
-register_foreach (gpointer data, gpointer user_data)
-{
- spi_emit_cache_update (ATK_OBJECT (data), atk_adaptor_app_data->bus);
-}
-
-static void
-register_subtree (AtkObject *accessible)
-{
- GList *registered = NULL;
-
- traverse_atk_tree (accessible,
- ®istered,
- (ActionFunc) register_action,
- (FilterFunc) register_filter);
-
- g_list_foreach (registered, register_foreach, NULL);
-}
-
-
-static void
-register_ancestors (AtkObject *accessible)
-{
- AtkObject *current;
- guint ref;
- GList *registered = NULL;
-
- current = atk_object_get_parent (accessible);
- while (current)
- {
- ref = atk_dbus_ref_from_object (current);
- if (!ref)
- register_action (®istered, current);
- current = atk_object_get_parent (accessible);
- }
-
- g_list_foreach (registered, register_foreach, NULL);
-}
-
-/*---------------------------------------------------------------------------*/
-
void
atk_dbus_foreach_registered(GHFunc func, gpointer data)
{
atk_dbus_object_to_path (AtkObject *accessible)
{
guint ref;
- g_assert(ATK_IS_OBJECT(accessible));
ref = object_to_ref (accessible);
if (!ref)
AtkPropertyValues *values;
const gchar *pname = NULL;
- accessible = g_value_get_object (¶m_values[0]);
- values = (AtkPropertyValues*) g_value_get_pointer (¶m_values[1]);
+ g_static_rec_mutex_lock (®istration_mutex);
- pname = values[0].property_name;
+ /* Ensure that only registered accessibles
+ * have their signals processed.
+ */
+ accessible = g_value_get_object (¶m_values[0]);
+ if (object_to_ref (accessible))
+ {
+ /* TODO Add debug wrapper */
+ if (recursion_check_and_set ())
+ g_critical ("AT-SPI: Recursive use of registration module");
- if (!object_to_ref (accessible))
- return TRUE;
+ if (!ATK_IS_OBJECT (accessible))
+ g_critical ("AT-SPI: Object data updated when not a valid AtkObject");
- if (strcmp (pname, "accessible-name") == 0 ||
- strcmp (pname, "accessible-description"))
- {
- atk_dbus_update_accessible (accessible);
- }
- else if (strcmp (pname, "accessible-parent"))
- {
- register_ancestors (accessible);
+ values = (AtkPropertyValues*) g_value_get_pointer (¶m_values[1]);
+ pname = values[0].property_name;
+ if (strcmp (pname, "accessible-name") == 0 ||
+ strcmp (pname, "accessible-description"))
+ {
+ update_accessible (accessible);
+ }
+ /* Parent updates not used */
+ /* Parent value us updated buy child-add signal of parent object */
+ /*
+ else if (strcmp (pname, "accessible-parent"))
+ {
+ update_accessible (accessible);
+ }
+ */
+ recursion_check_unset ();
}
+
+ g_static_rec_mutex_unlock (®istration_mutex);
+
return TRUE;
}
AtkObject *accessible;
const gchar *detail = NULL;
AtkObject *child;
- gboolean child_needs_unref = FALSE;
- if (signal_hint->detail)
- detail = g_quark_to_string (signal_hint->detail);
+ g_static_rec_mutex_lock (®istration_mutex);
+ /* Ensure that only registered accessibles
+ * have their signals processed.
+ */
accessible = g_value_get_object (¶m_values[0]);
- if (!strcmp (detail, "add"))
+ if (object_to_ref (accessible))
{
- gpointer child;
- int index = g_value_get_uint (param_values + 1);
- child = g_value_get_pointer (param_values + 2);
+ /* TODO Add debug wrapper */
+ if (recursion_check_and_set ())
+ g_warning ("AT-SPI: Recursive use of registration module");
- if (ATK_IS_OBJECT (child))
- g_object_ref (child);
- else
- child = atk_object_ref_accessible_child (accessible, index);
+ if (!ATK_IS_OBJECT (accessible))
+ g_critical ("AT-SPI: Object children updated when not a valid AtkObject");
+
+ if (signal_hint->detail)
+ detail = g_quark_to_string (signal_hint->detail);
+ if (!strcmp (detail, "add"))
+ {
+ gpointer child;
+ int index = g_value_get_uint (param_values + 1);
+ child = g_value_get_pointer (param_values + 2);
+
+ if (!ATK_IS_OBJECT (child))
+ {
+ child = atk_object_ref_accessible_child (accessible, index);
+ /* TODO Add debug wrapper */
+ if (!non_owned_accessible (child))
+ {
+ register_subtree (child);
+ }
+ }
+ else
+ {
+ register_subtree (child);
+ }
+
+ }
- register_subtree (child);
- g_object_unref (child);
+ recursion_check_unset ();
}
+
+ g_static_rec_mutex_unlock (®istration_mutex);
+
return TRUE;
}
if (!ref2ptr)
ref2ptr = g_hash_table_new(g_direct_hash, g_direct_equal);
+ if (g_thread_supported ())
+ g_message ("AT-SPI: Threads enabled");
+
register_subtree (root);
atk_add_global_event_listener (tree_update_listener, "Gtk:AtkObject:property-change");
#include "spi-common/spi-dbus.h"
-static double
-get_double_from_gvalue (GValue * gvalue)
+static dbus_bool_t
+impl_get_minimumValue (DBusMessageIter * iter,
+ void *user_data)
{
- double retval = 0;
- if (G_TYPE_IS_FUNDAMENTAL (G_VALUE_TYPE (gvalue)))
+ AtkValue *value = (AtkValue *) user_data;
+ GValue src = {0};
+ GValue dest = {0};
+ gdouble dub;
+
+ g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
+
+ atk_value_get_minimum_value (value, &src);
+ g_value_init (&dest, G_TYPE_DOUBLE);
+
+ if (g_value_transform (&src, &dest))
{
- switch (gvalue->g_type)
- {
- case G_TYPE_DOUBLE:
- retval = g_value_get_double (gvalue);
- break;
- case G_TYPE_FLOAT:
- retval = g_value_get_float (gvalue);
- break;
- case G_TYPE_ULONG:
- retval = g_value_get_ulong (gvalue);
- break;
- case G_TYPE_LONG:
- retval = g_value_get_long (gvalue);
- break;
- case G_TYPE_UINT:
- retval = g_value_get_uint (gvalue);
- break;
- case G_TYPE_INT:
- retval = g_value_get_int (gvalue);
- break;
- case G_TYPE_UCHAR:
- retval = g_value_get_uchar (gvalue);
- break;
- case G_TYPE_CHAR:
- retval = g_value_get_char (gvalue);
- break;
- case G_TYPE_BOOLEAN:
- retval = g_value_get_boolean (gvalue);
- break;
- }
+ dub = g_value_get_double (&dest);
+ dbus_message_iter_append_basic (iter, DBUS_TYPE_DOUBLE, &dub);
+ return TRUE;
}
else
{
- g_warning ("SpiValue requested from a non-fundamental type\n");
+ return FALSE;
}
- return retval;
}
-static gboolean
-get_double_from_variant (DBusMessageIter * iter, double *out)
+static dbus_bool_t
+impl_get_maximumValue (DBusMessageIter * iter,
+ void *user_data)
{
- DBusMessageIter sub;
+ AtkValue *value = (AtkValue *) user_data;
+ GValue src = {0};
+ GValue dest = {0};
+ gdouble dub;
- dbus_message_iter_recurse (iter, &sub);
- switch (dbus_message_iter_get_arg_type (&sub))
- {
- case DBUS_TYPE_DOUBLE:
- {
- dbus_message_iter_get_basic (&sub, out);
- return TRUE;
- }
- case DBUS_TYPE_UINT32:
- {
- dbus_uint32_t v;
- dbus_message_iter_get_basic (&sub, &v);
- *out = (double) v;
- return TRUE;
- }
- case DBUS_TYPE_INT32:
- {
- dbus_int32_t v;
- dbus_message_iter_get_basic (&sub, &v);
- *out = (double) v;
- return TRUE;
- }
- case DBUS_TYPE_UINT16:
- {
- dbus_uint16_t v;
- dbus_message_iter_get_basic (&sub, &v);
- *out = (double) v;
- return TRUE;
- }
- case DBUS_TYPE_INT16:
- {
- dbus_int16_t v;
- dbus_message_iter_get_basic (&sub, &v);
- *out = (double) v;
- return TRUE;
- }
- case DBUS_TYPE_BYTE:
- {
- char v;
- dbus_message_iter_get_basic (&sub, &v);
- *out = (double) v;
- return TRUE;
- }
- case DBUS_TYPE_BOOLEAN:
- {
- dbus_bool_t v;
- dbus_message_iter_get_basic (&sub, &v);
- *out = (double) v;
- return TRUE;
- }
- default:
- return FALSE;
- }
-}
+ g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
-static void
-gvalue_set_from_double (GValue * gvalue, double value)
-{
- if (G_TYPE_IS_FUNDAMENTAL (G_VALUE_TYPE (gvalue)))
+ atk_value_get_maximum_value (value, &src);
+ g_value_init (&dest, G_TYPE_DOUBLE);
+
+ if (g_value_transform (&src, &dest))
{
- switch (gvalue->g_type)
- {
- case G_TYPE_DOUBLE:
- g_value_set_double (gvalue, value);
- break;
- case G_TYPE_FLOAT:
- g_value_set_float (gvalue, value);
- break;
- case G_TYPE_ULONG:
- g_value_set_ulong (gvalue, value);
- break;
- case G_TYPE_LONG:
- g_value_set_long (gvalue, value);
- break;
- case G_TYPE_UINT:
- g_value_set_uint (gvalue, value);
- break;
- case G_TYPE_INT:
- g_value_set_int (gvalue, value);
- break;
- case G_TYPE_UCHAR:
- g_value_set_uchar (gvalue, value);
- break;
- case G_TYPE_CHAR:
- g_value_set_char (gvalue, value);
- break;
- case G_TYPE_BOOLEAN:
- g_value_set_boolean (gvalue, ((fabs (value) > 0.5) ? 1 : 0));
- break;
- }
+ dub = g_value_get_double (&dest);
+ dbus_message_iter_append_basic (iter, DBUS_TYPE_DOUBLE, &dub);
+ return TRUE;
}
else
{
- g_warning ("SpiValue change requested for a non-fundamental type\n");
+ return FALSE;
}
}
static dbus_bool_t
-impl_get_minimumValue (DBusMessageIter * iter,
- void *user_data)
+impl_get_minimumIncrement (DBusMessageIter * iter,
+ void *user_data)
{
AtkValue *value = (AtkValue *) user_data;
- GValue gvalue = { 0, };
- g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
- atk_value_get_minimum_value (value, &gvalue);
- return droute_return_v_double (iter, get_double_from_gvalue (&gvalue));
-}
+ GValue src = {0};
+ GValue dest = {0};
+ gdouble dub;
-static dbus_bool_t
-impl_get_maximumValue (DBusMessageIter * iter,
- void *user_data)
-{
- AtkValue *value = (AtkValue *) user_data;
- GValue gvalue = { 0, };
g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
- atk_value_get_maximum_value (value, &gvalue);
- return droute_return_v_double (iter, get_double_from_gvalue (&gvalue));
-}
-static dbus_bool_t
-impl_get_minimumIncrement (DBusMessageIter * iter,
- void *user_data)
-{
- AtkValue *value = (AtkValue *) user_data;
- GValue gvalue = { 0, };
- g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
- atk_value_get_minimum_value (value, &gvalue);
- return droute_return_v_double (iter, get_double_from_gvalue (&gvalue));
+ atk_value_get_minimum_increment (value, &src);
+ g_value_init (&dest, G_TYPE_DOUBLE);
+
+ if (g_value_transform (&src, &dest))
+ {
+ dub = g_value_get_double (&dest);
+ dbus_message_iter_append_basic (iter, DBUS_TYPE_DOUBLE, &dub);
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
}
static dbus_bool_t
impl_get_currentValue (DBusMessageIter * iter,
- void *user_data)
+ void *user_data)
{
AtkValue *value = (AtkValue *) user_data;
- GValue gvalue = { 0, };
+ GValue src = {0};
+ GValue dest = {0};
+ gdouble dub;
+
g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
- atk_value_get_current_value (value, &gvalue);
- return droute_return_v_double (iter, get_double_from_gvalue (&gvalue));
+
+ atk_value_get_current_value (value, &src);
+ g_value_init (&dest, G_TYPE_DOUBLE);
+
+ if (g_value_transform (&src, &dest))
+ {
+ dub = g_value_get_double (&dest);
+ dbus_message_iter_append_basic (iter, DBUS_TYPE_DOUBLE, &dub);
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
}
static dbus_bool_t
impl_set_currentValue (DBusMessageIter * iter,
- void *user_data)
+ void *user_data)
{
AtkValue *value = (AtkValue *) user_data;
- GValue gvalue = { 0, };
- double dbl;
+ GValue src = {0};
+ GValue dest = {0};
+ gdouble dub;
g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
- if (!get_double_from_variant (iter, &dbl))
- return FALSE;
- atk_value_get_current_value (value, &gvalue);
- gvalue_set_from_double (&gvalue, dbl);
- return TRUE;
+
+ dbus_message_iter_get_basic (iter, &dub);
+ g_value_init (&src, G_TYPE_DOUBLE);
+ g_value_set_double (&src, dub);
+
+ atk_value_get_current_value (value, &dest);
+
+ if (g_value_transform (&src, &dest))
+ {
+ atk_value_set_current_value (value, &dest);
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
}
static DRouteProperty properties[] = {