Enable caching on a call to atspi_accessible_set_cache_mask
authorMike Gorse <mgorse@novell.com>
Mon, 5 Mar 2012 23:32:32 +0000 (17:32 -0600)
committerMike Gorse <mgorse@novell.com>
Mon, 5 Mar 2012 23:32:32 +0000 (17:32 -0600)
Previously, caching was always disabled unless atspi_event_main() was
called to start a main loop, since we need to handle the case of a
simple application/script that performs an action and then sleeps rather
than entering a main loop. In such a case, libatspi will not be able to
detect that an event has been fired to update the cache, so caching
should be disabled. However, an application may want to start a main
loop through some other mechanism than by calling atspi-event_main(),
and caching should be done in such a case. So we'll assume that, if
atspi_accessible_set_cache_mask is called, then the application expects
caching to work and will run a main loop one way or another. Note that
it is possible for a script to run a main loop in some instances but not
others, and, in such a case, if it is not using atspi_event_main(), then
it should set caching to ATSPI_CACHE_NONE when not in a main loop and
back to ATSPI_CACHE_DEFAULT when running a main loop.

atspi/atspi-accessible.c

index 468c384..9534bae 100644 (file)
@@ -25,6 +25,8 @@
 #include "atspi-private.h"
 #include <string.h>
 
+static gboolean enable_caching = FALSE;
+
 static void
 atspi_action_interface_init (AtspiAction *action)
 {
@@ -1466,6 +1468,7 @@ atspi_accessible_set_cache_mask (AtspiAccessible *accessible, AtspiCache mask)
   g_return_if_fail (accessible->parent.app != NULL);
   g_return_if_fail (accessible == accessible->parent.app->root);
   accessible->parent.app->cache = mask;
+  enable_caching = TRUE;
 }
 
 /**
@@ -1556,7 +1559,8 @@ _atspi_accessible_test_cache (AtspiAccessible *accessible, AtspiCache flag)
   AtspiCache result = accessible->cached_properties & mask & flag;
   if (accessible->states && atspi_state_set_contains (accessible->states, ATSPI_STATE_TRANSIENT))
     return FALSE;
-  return (result != 0 && atspi_main_loop && !atspi_no_cache);
+  return (result != 0 && (atspi_main_loop || enable_caching) &&
+          !atspi_no_cache);
 }
 
 void