[at-spi2-core] Several cache-related fixes
- From: Mike Gorse <mgorse src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [at-spi2-core] Several cache-related fixes
- Date: Sat, 4 Dec 2010 10:13:40 +0000 (UTC)
commit 0f8c7f370f7c47f6fe7e3500e5b6db2e2b8f3b16
Author: Mike Gorse <mgorse novell com>
Date: Fri Dec 3 13:04:12 2010 -0500
Several cache-related fixes
atspi/atspi-accessible.c | 36 +++++++++++++++++++++++++++++++++---
atspi/atspi-accessible.h | 2 +-
atspi/atspi-misc.c | 45 +++++++++++++++++++++++++++++++--------------
3 files changed, 65 insertions(+), 18 deletions(-)
---
diff --git a/atspi/atspi-accessible.c b/atspi/atspi-accessible.c
index 759152b..13b0d73 100644
--- a/atspi/atspi-accessible.c
+++ b/atspi/atspi-accessible.c
@@ -39,6 +39,11 @@ atspi_component_interface_init (AtspiComponent *component)
{
}
+static void
+atspi_document_interface_init (AtspiDocument *document)
+{
+}
+
atspi_editable_text_interface_init (AtspiEditableText *editable_text)
{
}
@@ -77,6 +82,7 @@ G_DEFINE_TYPE_WITH_CODE (AtspiAccessible, atspi_accessible, ATSPI_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (ATSPI_TYPE_ACTION, atspi_action_interface_init)
G_IMPLEMENT_INTERFACE (ATSPI_TYPE_COLLECTION, atspi_collection_interface_init)
G_IMPLEMENT_INTERFACE (ATSPI_TYPE_COMPONENT, atspi_component_interface_init)
+ G_IMPLEMENT_INTERFACE (ATSPI_TYPE_DOCUMENT, atspi_document_interface_init)
G_IMPLEMENT_INTERFACE (ATSPI_TYPE_EDITABLE_TEXT, atspi_editable_text_interface_init)
G_IMPLEMENT_INTERFACE (ATSPI_TYPE_HYPERTEXT, atspi_hypertext_interface_init)
G_IMPLEMENT_INTERFACE (ATSPI_TYPE_IMAGE, atspi_image_interface_init)
@@ -326,11 +332,19 @@ atspi_accessible_get_parent (AtspiAccessible *obj, GError **error)
*
**/
gint
-atspi_accessible_get_child_count (AtspiAccessible *obj, GError *error)
+atspi_accessible_get_child_count (AtspiAccessible *obj, GError **error)
{
g_return_val_if_fail (obj != NULL, -1);
- /* TODO: MANAGES_DESCENDANTS */
+ if (!(obj->cached_properties & ATSPI_CACHE_CHILDREN))
+ {
+ dbus_int32_t ret;
+ if (!_atspi_dbus_get_property (obj, atspi_interface_accessible,
+ "ChildCount", error, "i", &ret))
+ return -1;
+ return ret;
+ }
+
return g_list_length (obj->children);
}
@@ -353,7 +367,15 @@ atspi_accessible_get_child_at_index (AtspiAccessible *obj,
g_return_val_if_fail (obj != NULL, NULL);
- /* TODO: ManagesDescendants */
+ if (!(obj->cached_properties & ATSPI_CACHE_CHILDREN))
+ {
+ DBusMessage *reply;
+ reply = _atspi_dbus_call_partial (obj, atspi_interface_accessible,
+ "GetChildAtIndex", error, "i",
+ child_index);
+ return _atspi_dbus_return_accessible_from_message (reply);
+ }
+
child = g_list_nth_data (obj->children, child_index);
if (!child)
return NULL;
@@ -378,6 +400,14 @@ atspi_accessible_get_index_in_parent (AtspiAccessible *obj, GError **error)
g_return_val_if_fail (obj != NULL, -1);
if (!obj->accessible_parent) return -1;
+ if (!(obj->accessible_parent->cached_properties & ATSPI_CACHE_CHILDREN))
+ {
+ dbus_uint32_t ret = -1;
+ _atspi_dbus_call (obj, atspi_interface_accessible,
+ "GetIndexInParent", NULL, "=>u", &ret);
+ return ret;
+ }
+
l = obj->accessible_parent->children;
while (l)
{
diff --git a/atspi/atspi-accessible.h b/atspi/atspi-accessible.h
index 4e7658e..487d0e5 100644
--- a/atspi/atspi-accessible.h
+++ b/atspi/atspi-accessible.h
@@ -72,7 +72,7 @@ gchar * atspi_accessible_get_description (AtspiAccessible *obj, GError **error);
AtspiAccessible * atspi_accessible_get_parent (AtspiAccessible *obj, GError **error);
-gint atspi_accessible_get_child_count (AtspiAccessible *obj, GError *error);
+gint atspi_accessible_get_child_count (AtspiAccessible *obj, GError **error);
AtspiAccessible * atspi_accessible_get_child_at_index (AtspiAccessible *obj, gint child_index, GError **error);
diff --git a/atspi/atspi-misc.c b/atspi/atspi-misc.c
index c49526a..b8497e9 100644
--- a/atspi/atspi-misc.c
+++ b/atspi/atspi-misc.c
@@ -32,6 +32,8 @@
#include <stdio.h>
#include <string.h>
+static void handle_get_items (DBusPendingCall *pending, void *user_data);
+
static DBusConnection *bus = NULL;
static GHashTable *apps = NULL;
static GHashTable *live_refs = NULL;
@@ -138,6 +140,9 @@ get_application (const char *bus_name)
{
AtspiApplication *app = NULL;
char *bus_name_dup;
+ DBusMessage *message;
+ DBusError error;
+ DBusPendingCall *pending = NULL;
if (!app_hash)
{
@@ -154,18 +159,26 @@ get_application (const char *bus_name)
app->bus_name = bus_name_dup;
app->hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
g_hash_table_insert (app_hash, bus_name_dup, app);
+ dbus_error_init (&error);
+ message = dbus_message_new_method_call (bus_name, "/org/a11y/atspi/cache",
+ atspi_interface_cache, "GetItems");
+
+ dbus_connection_send_with_reply (_atspi_bus (), message, &pending, 2000);
+ dbus_pending_call_set_notify (pending, handle_get_items, app, NULL);
return app;
}
static AtspiAccessible *
ref_accessible (const char *app_name, const char *path)
{
- AtspiApplication *app = get_application (app_name);
+ AtspiApplication *app;
AtspiAccessible *a;
if (!strcmp (path, ATSPI_DBUS_PATH_NULL))
return NULL;
+ app = get_application (app_name);
+
if (!strcmp (path, "/org/a11y/atspi/accessible/root"))
{
if (!app->root)
@@ -416,30 +429,30 @@ add_accessible_from_iter (DBusMessageIter *iter)
_atspi_dbus_set_state (accessible, &iter_struct);
dbus_message_iter_next (&iter_struct);
+ accessible->cached_properties |= ATSPI_CACHE_NAME | ATSPI_CACHE_ROLE | ATSPI_CACHE_PARENT;
+ if (!atspi_state_set_contains (accessible->states,
+ ATSPI_STATE_MANAGES_DESCENDANTS))
+ accessible->cached_properties |= ATSPI_CACHE_CHILDREN;
+
/* This is a bit of a hack since the cache holds a ref, so we don't need
* the one provided for us anymore */
g_object_unref (accessible);
}
static void
-add_accessibles (const char *app_name)
+handle_get_items (DBusPendingCall *pending, void *user_data)
{
- DBusError error;
- DBusMessage *message, *reply;
+ AtspiApplication *app = user_data;
+ DBusMessage *reply = dbus_pending_call_steal_reply (pending);
DBusMessageIter iter, iter_array;
- AtspiApplication *app = get_application (app_name);
- /* TODO: Move this functionality into app initializer? */
- dbus_error_init (&error);
- message = dbus_message_new_method_call (app_name, "/org/a11y/atspi/cache", atspi_interface_cache, "GetItems");
- reply = _atspi_dbus_send_with_reply_and_block (message);
- if (!reply || strcmp (dbus_message_get_signature (reply), "a((so)(so)(so)a(so)assusau)") != 0)
+ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
{
- g_warning ("at-spi: Error in GetItems");
+ dbus_message_unref (reply);
+ g_warning ("Atspi: Error in GetItems");
return;
- if (reply)
- dbus_message_unref (reply);
}
+
dbus_message_iter_init (reply, &iter);
dbus_message_iter_recurse (&iter, &iter_array);
while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
@@ -495,7 +508,6 @@ ref_accessible_desktop (AtspiApplication *app)
{
const char *app_name, *path;
get_reference_from_iter (&iter_array, &app_name, &path);
- add_accessibles (app_name);
add_app_to_desktop (desktop, app_name);
}
dbus_message_unref (reply);
@@ -1041,6 +1053,11 @@ _atspi_dbus_get_property (gpointer obj, const char *interface, const char *name,
goto done;
}
dbus_message_iter_init (reply, &iter);
+ if (dbus_message_iter_get_arg_type (&iter) != 'v')
+ {
+ g_warning ("at-spi: expected a variant when fetching %s from interface %s\n", name, interface);
+ goto done;
+ }
dbus_message_iter_recurse (&iter, &iter_variant);
if (dbus_message_iter_get_arg_type (&iter_variant) != type[0])
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]