[at-spi2-core] Add startup_time parameter to atspi_set_timeout
- From: Mike Gorse <mgorse src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [at-spi2-core] Add startup_time parameter to atspi_set_timeout
- Date: Fri, 6 Apr 2012 21:07:06 +0000 (UTC)
commit f2f3ce25b78b759612cf7b426695c0235e736ed7
Author: Mike Gorse <mgorse suse com>
Date: Fri Apr 6 16:06:04 2012 -0500
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
atspi/atspi-application.h | 2 +
atspi/atspi-misc.c | 34 +++++++++++++++++++++++++++--
atspi/atspi-misc.h | 2 +-
doc/libatspi/tmpl/atspi-application.sgml | 1 +
doc/libatspi/tmpl/atspi-collection.sgml | 2 +-
5 files changed, 36 insertions(+), 5 deletions(-)
---
diff --git a/atspi/atspi-application.h b/atspi/atspi-application.h
index f209275..2627038 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 0b60fb6..7b7346a 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 2d3b3f4..be550c1 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_ */
diff --git a/doc/libatspi/tmpl/atspi-application.sgml b/doc/libatspi/tmpl/atspi-application.sgml
index 09f953b..e6a6316 100644
--- a/doc/libatspi/tmpl/atspi-application.sgml
+++ b/doc/libatspi/tmpl/atspi-application.sgml
@@ -36,6 +36,7 @@ atspi-application
@toolkit_name:
@toolkit_version:
@atspi_version:
+ time_added:
<!-- ##### STRUCT AtspiApplicationClass ##### -->
<para>
diff --git a/doc/libatspi/tmpl/atspi-collection.sgml b/doc/libatspi/tmpl/atspi-collection.sgml
index 5502900..1e604b2 100644
--- a/doc/libatspi/tmpl/atspi-collection.sgml
+++ b/doc/libatspi/tmpl/atspi-collection.sgml
@@ -64,7 +64,7 @@ or client-side search of the object tree.
@rule:
@sortby:
@tree:
- recurse:
+ limit_scope:
@count:
@traverse:
@error:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]