* test/test-simple.c (global_listener_cb): bin bogosity.
(test_keylisteners): disable, still doesn't work reliably,
certainly not on my system anyway.
* atk-bridge/bridge.c (spi_atk_bridge_key_listener):
don't leak a reference on the DEC. This round-trip
fetching of the DEC per keystroke sucks, it should be
cached.
* cspi/spi-private.h,
* cspi/cspi-lowlevel.h,
* cspi/bonobo/cspi-bonobo-listener.[ch],
* cspi/bonobo/cspi-bonobo.c: get the copyright
notices better - there is still a large amount of
work in at-spi falsely attributed solely to Sun.
* cspi/spi_main.c (cspi_object_ref): kill bogus
hash lookup, just increment the ref.
(SPI_freeString): make explicit the fact that we
handle NULL strings just fine.
(report_leaked_ref): obey coding standards.
(cspi_object_hash, cspi_object_equal): kill retval.
(cspi_object_release): only release if not on loan.
(cspi_object_get_ref): add 'loan' concept, bin 'do_ref'.
(cspi_object_borrow, cspi_object_return): impl.
* cspi/bonobo/cspi-bonobo-listener.c (cspi_event):
use cspi_object_borrow / return.
git-svn-id: http://svn.gnome.org/svn/at-spi/trunk@331
e2bd861d-eb25-0410-b326-
f6ed22b6b98c
+2002-08-12 Michael Meeks <michael@ximian.com>
+
+ * test/test-simple.c (global_listener_cb): bin bogosity.
+ (test_keylisteners): disable, still doesn't work reliably,
+ certainly not on my system anyway.
+
+ * atk-bridge/bridge.c (spi_atk_bridge_key_listener):
+ don't leak a reference on the DEC. This round-trip
+ fetching of the DEC per keystroke sucks, it should be
+ cached.
+
+ * cspi/spi-private.h,
+ * cspi/cspi-lowlevel.h,
+ * cspi/bonobo/cspi-bonobo-listener.[ch],
+ * cspi/bonobo/cspi-bonobo.c: get the copyright
+ notices better - there is still a large amount of
+ work in at-spi falsely attributed solely to Sun.
+
+ * cspi/spi_main.c (cspi_object_ref): kill bogus
+ hash lookup, just increment the ref.
+ (SPI_freeString): make explicit the fact that we
+ handle NULL strings just fine.
+ (report_leaked_ref): obey coding standards.
+ (cspi_object_hash, cspi_object_equal): kill retval.
+ (cspi_object_release): only release if not on loan.
+ (cspi_object_get_ref): add 'loan' concept, bin 'do_ref'.
+ (cspi_object_borrow, cspi_object_return): impl.
+
+ * cspi/bonobo/cspi-bonobo-listener.c (cspi_event):
+ use cspi_object_borrow / return.
+
2002-08-12 Darren Kenny <darren.kenny@sun.com>
* cspi/bonobo/cspi-bonobo-listener.c:
result = Accessibility_DeviceEventController_notifyListenersSync (
controller, &key_event, &ev);
+ bonobo_object_release_unref (controller, &ev);
CORBA_exception_free (&ev);
}
* AT-SPI - Assistive Technology Service Provider Interface
* (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
*
- * Copyright 2001 Sun Microsystems Inc.
+ * Copyright 2002 Ximian Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
GList *l;
CSpiEventListener *clistener = (CSpiEventListener *) listener;
AccessibleEvent aevent;
- Accessible *source = cspi_object_add (cspi_dup_ref(event->source));
+ Accessible *source = cspi_object_borrow (event->source);
aevent.type = event->type;
aevent.source = source;
eh->cb.event (&aevent, eh->user_data);
}
- cspi_object_unref( source );
+ cspi_object_return (source);
}
static void
* AT-SPI - Assistive Technology Service Provider Interface
* (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
*
- * Copyright 2001 Sun Microsystems Inc.
+ * Copyright 2002 Ximian, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
*
* Copyright 2001 Sun Microsystems Inc.
+ * 2002 Ximian Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* AT-SPI - Assistive Technology Service Provider Interface
* (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
*
- * Copyright 2001 Sun Microsystems Inc.
+ * Copyright 2002 Ximian, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* AT-SPI - Assistive Technology Service Provider Interface
* (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
*
- * Copyright 2001 Sun Microsystems Inc.
+ * Copyright 2002 Ximian, Inc.
+ * 2002 Sun Microsystems Inc.
+ *
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
struct _Accessible {
CORBA_Object objref;
/* And some other bits */
- guint ref_count;
+ guint on_loan : 1;
+ guint ref_count : 30;
};
#define CSPI_OBJREF(a) (((Accessible *)(a))->objref)
CORBA_Environment *cspi_ev (void);
SPIBoolean cspi_exception (void);
Accessibility_Registry cspi_registry (void);
-Accessible *cspi_object_add (CORBA_Object corba_object);
-Accessible *cspi_object_add_ref (CORBA_Object corba_object,
- gboolean do_ref);
-void cspi_object_ref (Accessible *accessible);
-void cspi_object_unref (Accessible *accessible);
-SPIBoolean cspi_accessible_is_a (Accessible *obj,
- const char *interface_name);
+Accessible *cspi_object_add (CORBA_Object corba_object);
+void cspi_object_ref (Accessible *accessible);
+void cspi_object_unref (Accessible *accessible);
+Accessible *cspi_object_borrow (CORBA_Object corba_object);
+void cspi_object_return (Accessible *accessible);
+SPIBoolean cspi_accessible_is_a (Accessible *accessible,
+ const char *interface_name);
#define cspi_return_if_fail(val) \
if (!(val)) \
cspi_object_hash (gconstpointer key)
{
CORBA_Object object = (CORBA_Object) key;
- guint retval;
-
- retval = CORBA_Object_hash (object, 0, &ev);
- return retval;
+ return CORBA_Object_hash (object, 0, &ev);
}
static gboolean
{
CORBA_Object objecta = (CORBA_Object) a;
CORBA_Object objectb = (CORBA_Object) b;
- gboolean retval;
-
- retval = CORBA_Object_is_equivalent (objecta, objectb, &ev);
- return retval;
+ return CORBA_Object_is_equivalent (objecta, objectb, &ev);
}
static void
-cspi_object_release (gpointer value)
+cspi_object_release (gpointer value)
{
Accessible *a = (Accessible *) value;
g_print ("releasing %p => %p\n", a, a->objref);
#endif
- cspi_release_unref (a->objref);
+ if (!a->on_loan)
+ {
+ cspi_release_unref (a->objref);
+ }
memset (a, 0xaa, sizeof (Accessible));
a->ref_count = -1;
}
SPIBoolean
-cspi_accessible_is_a (Accessible *obj,
+cspi_accessible_is_a (Accessible *accessible,
const char *interface_name)
{
SPIBoolean retval;
Bonobo_Unknown unknown;
- if (obj == NULL)
+ if (accessible == NULL)
{
return FALSE;
}
- unknown = Bonobo_Unknown_queryInterface (CSPI_OBJREF (obj),
+ unknown = Bonobo_Unknown_queryInterface (CSPI_OBJREF (accessible),
interface_name, cspi_ev ());
if (ev._major != CORBA_NO_EXCEPTION)
cspi_registry (void)
{
if (!cspi_ping (registry))
- registry = cspi_init ();
+ {
+ registry = cspi_init ();
+ }
return registry;
}
return retval;
}
-Accessible *
-cspi_object_new (CORBA_Object corba_object)
-{
- Accessible *ref;
-
- if (corba_object == CORBA_OBJECT_NIL)
- {
- ref = NULL;
- }
- else if (!cspi_check_ev ("pre method check: add"))
- {
- ref = NULL;
- }
- else
- {
- ref = malloc (sizeof (Accessible));
-// ref->objref = CORBA_Object_duplicate (corba_object, cspi_ev ());
- ref->objref = corba_object;
- ref->ref_count = 1;
- }
-
- return ref;
-}
-
-Accessible *
-cspi_object_add (CORBA_Object corba_object)
-{
- return cspi_object_add_ref (corba_object, FALSE);
-}
-
-Accessible *
-cspi_object_add_ref (CORBA_Object corba_object, gboolean do_ref)
+/*
+ * This method swallows the corba_object BonoboUnknown
+ * reference, and returns an Accessible associated with it.
+ * If the reference is loaned, it means it is only valid
+ * between a borrow / return pair.
+ */
+static Accessible *
+cspi_object_get_ref (CORBA_Object corba_object, gboolean on_loan)
{
Accessible *ref;
{
g_assert (ref->ref_count > 0);
ref->ref_count++;
- if (!do_ref)
- cspi_release_unref (corba_object);
+ if (!on_loan)
+ {
+ if (ref->on_loan) /* Convert to a permanant ref */
+ {
+ ref->on_loan = FALSE;
+ }
+ else
+ {
+ cspi_release_unref (corba_object);
+ }
+ }
#ifdef DEBUG_OBJECTS
g_print ("returning cached %p => %p\n", ref, ref->objref);
#endif
}
else
{
- ref = cspi_object_new (corba_object);
-
+ ref = malloc (sizeof (Accessible));
+ ref->objref = corba_object;
+ ref->ref_count = 1;
+ ref->on_loan = on_loan;
#ifdef DEBUG_OBJECTS
g_print ("allocated %p => %p\n", ref, corba_object);
#endif
- if (do_ref) {
-#ifdef JAVA_BRIDGE_BUG_IS_FIXED
- g_assert (CORBA_Object_is_a (corba_object,
- "IDL:Bonobo/Unknown:1.0", cspi_ev ()));
-#endif
- Bonobo_Unknown_ref (corba_object, cspi_ev ());
- }
g_hash_table_insert (cspi_get_live_refs (), ref->objref, ref);
}
}
return ref;
}
+Accessible *
+cspi_object_add (CORBA_Object corba_object)
+{
+ return cspi_object_get_ref (corba_object, FALSE);
+}
+
+Accessible *
+cspi_object_borrow (CORBA_Object corba_object)
+{
+ return cspi_object_get_ref (corba_object, TRUE);
+}
+
+void
+cspi_object_return (Accessible *accessible)
+{
+ g_return_if_fail (accessible != NULL);
+
+ if (!accessible->on_loan ||
+ accessible->ref_count == 1)
+ {
+ cspi_object_unref (accessible);
+ }
+ else /* Convert to a permanant ref */
+ {
+ accessible->on_loan = FALSE;
+ accessible->objref = cspi_dup_ref (accessible->objref);
+ accessible->ref_count--;
+ }
+}
+
void
cspi_object_ref (Accessible *accessible)
{
g_return_if_fail (accessible != NULL);
- if (g_hash_table_lookup (cspi_get_live_refs (), accessible->objref) == NULL) {
- accessible->objref = cspi_dup_ref (accessible->objref);
- g_hash_table_insert (cspi_get_live_refs (), accessible->objref, accessible);
- } else {
- accessible->ref_count++;
- }
+ accessible->ref_count++;
}
void
static void
report_leaked_ref (gpointer key, gpointer val, gpointer user_data)
{
- Accessible *a = (Accessible *) val;
- char *name, *role;
- name = Accessible_getName (a);
- if (cspi_exception ()) name = NULL;
- role = Accessible_getRoleName (a);
- if (cspi_exception ()) role = NULL;
- fprintf (stderr, "leaked object %s, role %s\n", (name) ? name : "<?>",
- (role) ? role : "<?>");
- if (name) SPI_freeString (name);
+ char *name, *role;
+ Accessible *a = (Accessible *) val;
+
+ name = Accessible_getName (a);
+ if (cspi_exception ())
+ {
+ name = NULL;
+ }
+
+ role = Accessible_getRoleName (a);
+ if (cspi_exception ())
+ {
+ role = NULL;
+ }
+
+ fprintf (stderr, "leaked %d references to object %s, role %s\n",
+ a->ref_count, name ? name : "<?>", role ? role : "<?>");
+
+ SPI_freeString (name);
}
*
* Free a character string returned from an at-spi call. Clients of
* at-spi should use this function instead of free () or g_free().
+ * A NULL string @s will be silently ignored.
* This API should not be used to free strings
* from other libraries or allocated by the client.
**/
void
SPI_freeString (char *s)
{
- CORBA_free (s);
+ if (s)
+ {
+ CORBA_free (s);
+ }
}
#include <cspi/spi-private.h>
static Accessibility_TEXT_BOUNDARY_TYPE
-get_accessible_text_boundary_type (
- AccessibleTextBoundaryType type)
+get_accessible_text_boundary_type (AccessibleTextBoundaryType type)
{
switch (type)
{
</para>
@objref:
+@on_loan:
@ref_count:
<!-- ##### FUNCTION Accessible_ref ##### -->
fprintf (stderr, "Fielded focus event ...\n");
- /*
- * must ref before doing "direct pointer" identity comparisons,
- * e.g. "accessible == a".
- * Alternatively, one can use cspi_object_equal (a, b)
- */
- Accessible_ref (event->source);
-
if (!do_poke) {
desktop = SPI_getDesktop (0);
application = Accessible_getChildAtIndex (desktop, 0);
print_tree = TRUE;
validate_accessible (event->source, TRUE, TRUE);
-
- Accessible_unref (event->source);
}
static SPIBoolean
*s = *stroke;
- if (s->type == SPI_KEY_PRESSED) key_press_received = TRUE;
- else if (s->type == SPI_KEY_RELEASED) key_release_received = TRUE;
+ if (s->type == SPI_KEY_PRESSED)
+ key_press_received = TRUE;
+ else if (s->type == SPI_KEY_RELEASED)
+ key_release_received = TRUE;
return TRUE;
}
static void
test_keylisteners (void)
{
+#ifdef BILL_MAKES_THIS_WORK_RELIABLY
int i;
AccessibleKeystroke stroke;
AccessibleKeystrokeListener *key_listener;
g_assert (SPI_generateMouseEvent (-50, -50, "rel"));
g_assert (SPI_generateMouseEvent (-50, -50, "rel"));
g_assert (SPI_generateMouseEvent (-1, -1, "b1c"));
+#endif
}
int