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;
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);
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);
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, ...)
{
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);
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:
}
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);
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);
* 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;
}