diff options
author | Mike Gorse <mgorse@suse.com> | 2012-04-06 16:06:04 -0500 |
---|---|---|
committer | Mike Gorse <mgorse@suse.com> | 2012-04-06 16:06:04 -0500 |
commit | f2f3ce25b78b759612cf7b426695c0235e736ed7 (patch) | |
tree | 6f75a0d1679b5c030916461fb6d2160fc6dfa7e0 /atspi | |
parent | 37171ce568201a2942e543c3f6af6db4da5cb194 (diff) | |
download | at-spi2-core-f2f3ce25b78b759612cf7b426695c0235e736ed7.tar.gz |
Add startup_time parameter to atspi_set_timeout
Add a parameter to allow timeouts not to be enforced until an
application has been running for a given amount of time. Might help
prevent timeout exceptions for applications that get bogged down
performing tasks at initialization.
See https://bugzilla.gnome.org/show_bug.cgi?id=672784
Diffstat (limited to 'atspi')
-rw-r--r-- | atspi/atspi-application.h | 2 | ||||
-rw-r--r-- | atspi/atspi-misc.c | 34 | ||||
-rw-r--r-- | atspi/atspi-misc.h | 2 |
3 files changed, 34 insertions, 4 deletions
diff --git a/atspi/atspi-application.h b/atspi/atspi-application.h index f209275a..2627038c 100644 --- a/atspi/atspi-application.h +++ b/atspi/atspi-application.h @@ -28,6 +28,7 @@ #include <dbus/dbus.h> #include "atspi-accessible.h" +#include <sys/time.h> #define ATSPI_TYPE_APPLICATION (atspi_application_get_type ()) #define ATSPI_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ATSPI_TYPE_APPLICATION, AtspiApplication)) @@ -48,6 +49,7 @@ struct _AtspiApplication gchar *toolkit_name; gchar *toolkit_version; gchar *atspi_version; + struct timeval time_added; }; typedef struct _AtspiApplicationClass AtspiApplicationClass; diff --git a/atspi/atspi-misc.c b/atspi/atspi-misc.c index 0b60fb64..7b7346a2 100644 --- a/atspi/atspi-misc.c +++ b/atspi/atspi-misc.c @@ -38,6 +38,8 @@ static void handle_get_items (DBusPendingCall *pending, void *user_data); static DBusConnection *bus = NULL; static GHashTable *live_refs = NULL; +static gint method_call_timeout = 800; +static gint app_startup_time = 1000; GMainLoop *atspi_main_loop; gboolean atspi_no_cache; @@ -202,6 +204,7 @@ get_application (const char *bus_name) if (!app) return NULL; app->hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); app->bus = dbus_connection_ref (_atspi_bus ()); + gettimeofday (&app->time_added, NULL); app->cache = ATSPI_CACHE_UNDEFINED; g_hash_table_insert (app_hash, bus_name_dup, app); dbus_error_init (&error); @@ -835,7 +838,6 @@ atspi_init (void) dbus_bus_register (bus, &error); atspi_dbus_connection_setup_with_g_main(bus, g_main_context_default()); dbus_connection_add_filter (bus, atspi_dbus_filter, NULL, NULL); - dbind_set_timeout (800); match = g_strdup_printf ("type='signal',interface='%s',member='AddAccessible'", atspi_interface_cache); dbus_error_init (&error); dbus_bus_add_match (bus, match, &error); @@ -996,6 +998,22 @@ check_app (AtspiApplication *app, GError **error) return TRUE; } +static void +set_timeout (AtspiApplication *app) +{ + struct timeval tv; + int diff; + + if (app && app_startup_time > 0) + { + gettimeofday (&tv, NULL); + diff = (tv.tv_sec - app->time_added.tv_sec) * 1000 + (tv.tv_usec - app->time_added.tv_usec) / 1000; + dbind_set_timeout (MAX(method_call_timeout, app_startup_time - diff)); + } + else + dbind_set_timeout (method_call_timeout); +} + dbus_bool_t _atspi_dbus_call (gpointer obj, const char *interface, const char *method, GError **error, const char *type, ...) { @@ -1009,6 +1027,7 @@ _atspi_dbus_call (gpointer obj, const char *interface, const char *method, GErro va_start (args, type); dbus_error_init (&err); + set_timeout (aobj->app); retval = dbind_method_call_reentrant_va (aobj->app->bus, aobj->app->bus_name, aobj->path, interface, method, &err, type, args); @@ -1064,6 +1083,7 @@ _atspi_dbus_call_partial_va (gpointer obj, dbus_message_iter_init_append (msg, &iter); dbind_any_marshal_va (&iter, &p, args); + set_timeout (aobj->app); reply = dbind_send_and_allow_reentry (aobj->app->bus, msg, &err); check_for_hang (reply, &err, aobj->app->bus, aobj->app->bus_name); out: @@ -1106,6 +1126,7 @@ _atspi_dbus_get_property (gpointer obj, const char *interface, const char *name, } dbus_message_append_args (message, DBUS_TYPE_STRING, &interface, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID); dbus_error_init (&err); + set_timeout (aobj->app); reply = dbind_send_and_allow_reentry (aobj->app->bus, message, &err); check_for_hang (reply, &err, aobj->app->bus, aobj->app->bus_name); dbus_message_unref (message); @@ -1170,6 +1191,7 @@ _atspi_dbus_send_with_reply_and_block (DBusMessage *message, GError **error) bus = (app ? app->bus : _atspi_bus()); dbus_error_init (&err); + set_timeout (app); reply = dbind_send_and_allow_reentry (bus, message, &err); _atspi_process_deferred_messages ((gpointer)TRUE); dbus_message_unref (message); @@ -1450,9 +1472,15 @@ atspi_get_a11y_bus (void) * larger than 3 seconds. * * @val: The timeout value, in milliseconds, or -1 to disable the timeout. + * @startup_time: The amount of time, in milliseconds, to allow to pass + * before enforcing timeouts on an application. Can be used to prevent + * timeout exceptions if an application is likely to block for an extended + * period of time on initialization. -1 can be passed to disable this + * behavior. */ void -atspi_set_timeout (gint val) +atspi_set_timeout (gint val, gint startup_time) { - dbind_set_timeout (val); + method_call_timeout = val; + app_startup_time = startup_time; } diff --git a/atspi/atspi-misc.h b/atspi/atspi-misc.h index 2d3b3f4c..be550c11 100644 --- a/atspi/atspi-misc.h +++ b/atspi/atspi-misc.h @@ -38,5 +38,5 @@ DBusConnection * atspi_get_a11y_bus (); void -atspi_set_timeout (gint val); +atspi_set_timeout (gint val, gint startup_time); #endif /* _ATSPI_MISC_H_ */ |