[java-atk-wrapper] Fixed bug 606402 - Attempting to run swing applications with the JAW installed frequently causes the



commit e4485926d888d50d1e7bf434c2ab31fe3024005f
Author: Ke Wang <ke wang sun com>
Date:   Thu Jan 14 16:16:16 2010 +0800

    Fixed bug 606402 - Attempting to run swing applications with the JAW installed frequently causes the JRE to report a fatal runtime error

 jni/src/AtkWrapper.c                               |   19 +++++++++++++++++++
 wrapper/org/GNOME/Accessibility/AtkWrapper.java.in |   14 ++++++++++----
 2 files changed, 29 insertions(+), 4 deletions(-)
---
diff --git a/jni/src/AtkWrapper.c b/jni/src/AtkWrapper.c
index 891a857..10cc1a4 100644
--- a/jni/src/AtkWrapper.c
+++ b/jni/src/AtkWrapper.c
@@ -46,6 +46,9 @@ struct _DummyDispatch
 	GDestroyNotify destroy;
 };
 
+GMutex *atk_bridge_mutex = NULL;
+GCond *atk_bridge_cond = NULL;
+
 GMutex *key_dispatch_mutex = NULL;
 GCond *key_dispatch_cond = NULL;
 static gint key_dispatch_result = KEY_DISPATCH_NOT_DISPATCHED;
@@ -95,6 +98,8 @@ static void jaw_exit_func ()
 static gboolean
 jaw_load_atk_bridge (gpointer p)
 {
+	g_mutex_lock(atk_bridge_mutex);
+
 	if (!g_module_supported()) {
 		return NULL;
 	}
@@ -123,6 +128,9 @@ jaw_load_atk_bridge (gpointer p)
 	(dl_init)();
 	g_atexit( jaw_exit_func );
 
+	g_cond_signal(atk_bridge_cond);
+	g_mutex_unlock(atk_bridge_mutex);
+
 	return FALSE;
 }
 
@@ -155,6 +163,9 @@ JNIEXPORT void JNICALL Java_org_GNOME_Accessibility_AtkWrapper_initNativeLibrary
 
 	jaw_impl_init_mutex();
 
+	atk_bridge_mutex = g_mutex_new();
+	atk_bridge_cond = g_cond_new();
+
 	key_dispatch_mutex = g_mutex_new();
 	key_dispatch_cond = g_cond_new();
 
@@ -165,8 +176,16 @@ JNIEXPORT void JNICALL Java_org_GNOME_Accessibility_AtkWrapper_initNativeLibrary
 	gdk_threads_add_idle(jaw_dummy_idle_func, NULL);
 	g_idle_add(jaw_load_atk_bridge, NULL);
 
+	// We need to wait for the completion of the loading of ATK Bridge
+	// in order to ensure event listeners in ATK Bridge are properly
+	// registered before any emission of AWT event.
+	g_mutex_lock(atk_bridge_mutex);
+
 	GThread *main_loop_thread = g_thread_create( jni_main_loop,
 			(gpointer)main_loop, FALSE, NULL);
+	
+	g_cond_wait(atk_bridge_cond, atk_bridge_mutex);
+	g_mutex_unlock(atk_bridge_mutex);
 }
 
 typedef enum _SigalType {
diff --git a/wrapper/org/GNOME/Accessibility/AtkWrapper.java.in b/wrapper/org/GNOME/Accessibility/AtkWrapper.java.in
index 50893cb..1bfd317 100644
--- a/wrapper/org/GNOME/Accessibility/AtkWrapper.java.in
+++ b/wrapper/org/GNOME/Accessibility/AtkWrapper.java.in
@@ -41,10 +41,6 @@ public class AtkWrapper {
 				}
 			}
 			
-			if (accessibilityEnabled) {
-				System.loadLibrary("atk-wrapper");
-				AtkWrapper.initNativeLibrary();
-			}
 		} catch (Exception e) { }
 	}
 
@@ -134,7 +130,17 @@ public class AtkWrapper {
 	};
 
 	final AWTEventListener globalListener = new AWTEventListener() {
+		private boolean firstEvent = true;
+
 		public void eventDispatched(AWTEvent e) {
+			if (firstEvent && accessibilityEnabled) {
+				firstEvent = false;
+				try {
+					System.loadLibrary("atk-wrapper");
+					AtkWrapper.initNativeLibrary();
+				} catch (Exception ex) {}
+			}
+
 			if( e instanceof WindowEvent ) {
 				switch( e.getID() ) {
 				case WindowEvent.WINDOW_OPENED:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]