[java-atk-wrapper] Delegate hashCode call to EDT



commit 0bd69a89b833baf05e77b56db3789e24c36b248c
Author: Giuseppe <giuseppecapaldo93 gmail com>
Date:   Mon Jun 17 21:38:26 2019 +0200

    Delegate hashCode call to EDT

 jni/src/jawimpl.c                              | 23 ++++----------
 jni/src/jawobject.c                            | 11 ++-----
 wrapper/org/GNOME/Accessibility/AtkObject.java | 44 ++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 24 deletions(-)
---
diff --git a/jni/src/jawimpl.c b/jni/src/jawimpl.c
index 9baadb1..9f987c3 100644
--- a/jni/src/jawimpl.c
+++ b/jni/src/jawimpl.c
@@ -58,13 +58,9 @@ static gboolean jaw_debug = FALSE;
 static void
 object_table_insert (JNIEnv *jniEnv, jobject ac, JawImpl* jaw_impl)
 {
-  jclass classAccessibleContext = (*jniEnv)->FindClass( jniEnv,
-                                                       "javax/accessibility/AccessibleContext");
-  jmethodID jmid = (*jniEnv)->GetMethodID(jniEnv,
-                                          classAccessibleContext,
-                                          "hashCode",
-                                          "()I");
-  jaw_impl->hash_key = (gint)(*jniEnv)->CallIntMethod(jniEnv, ac, jmid);
+  jclass atkObject = (*jniEnv)->FindClass (jniEnv,"org/GNOME/Accessibility/AtkObject");
+  jmethodID jmid = (*jniEnv)->GetStaticMethodID (jniEnv, atkObject, "hashCode", 
"(Ljavax/accessibility/AccessibleContext;)I");
+  jaw_impl->hash_key = (gint)(*jniEnv)->CallStaticIntMethod (jniEnv, atkObject, jmid, ac);
   g_mutex_lock(&objectTableMutex);
   g_hash_table_insert(objectTable, GINT_TO_POINTER(jaw_impl->hash_key), jaw_impl);
   g_mutex_unlock(&objectTableMutex);
@@ -73,21 +69,16 @@ object_table_insert (JNIEnv *jniEnv, jobject ac, JawImpl* jaw_impl)
 static JawImpl*
 object_table_lookup (JNIEnv *jniEnv, jobject ac)
 {
-  jclass classAccessibleContext = (*jniEnv)->FindClass( jniEnv,
-                                                       "javax/accessibility/AccessibleContext" );
-  jmethodID jmid = (*jniEnv)->GetMethodID(jniEnv,
-                                          classAccessibleContext,
-                                          "hashCode",
-                                          "()I" );
-  gint hash_key = (gint)(*jniEnv)->CallIntMethod( jniEnv, ac, jmid );
+  jclass atkObject = (*jniEnv)->FindClass (jniEnv,"org/GNOME/Accessibility/AtkObject");
+  jmethodID jmid = (*jniEnv)->GetStaticMethodID (jniEnv, atkObject, "hashCode", 
"(Ljavax/accessibility/AccessibleContext;)I");
+  gint hash_key = (gint)(*jniEnv)->CallStaticIntMethod (jniEnv, atkObject, jmid, ac);
   gpointer value = NULL;
   g_mutex_lock(&objectTableMutex);
   if (objectTable==NULL)
   {
-    return NULL;
     g_mutex_unlock(&objectTableMutex);
+    return NULL;
   }
-
   value = g_hash_table_lookup(objectTable, GINT_TO_POINTER(hash_key));
   g_mutex_unlock(&objectTableMutex);
   return (JawImpl*)value;
diff --git a/jni/src/jawobject.c b/jni/src/jawobject.c
index ccf23fd..77fd818 100644
--- a/jni/src/jawobject.c
+++ b/jni/src/jawobject.c
@@ -711,13 +711,9 @@ jaw_object_table_lookup (JNIEnv *jniEnv, jobject ac)
 {
   GHashTable *object_table = jaw_impl_get_object_hash_table();
   GMutex *object_table_mutex = jaw_impl_get_object_hash_table_mutex();
-  jclass classAccessibleContext = (*jniEnv)->FindClass( jniEnv,
-                                                       "javax/accessibility/AccessibleContext" );
-  jmethodID jmid = (*jniEnv)->GetMethodID(jniEnv,
-                                          classAccessibleContext,
-                                          "hashCode",
-                                          "()I" );
-  gint hash_key = (gint)(*jniEnv)->CallIntMethod( jniEnv, ac, jmid );
+  jclass atkObject = (*jniEnv)->FindClass (jniEnv, "org/GNOME/Accessibility/AtkObject");
+  jmethodID jmid = (*jniEnv)->GetStaticMethodID (jniEnv, atkObject, "hashCode", 
"(Ljavax/accessibility/AccessibleContext;)I");
+  gint hash_key = (gint)(*jniEnv)->CallStaticIntMethod (jniEnv, atkObject, jmid, ac);
   gpointer value = NULL;
   if (object_table == NULL)
     return NULL;
@@ -731,4 +727,3 @@ jaw_object_table_lookup (JNIEnv *jniEnv, jobject ac)
 #ifdef __cplusplus
 }
 #endif
-
diff --git a/wrapper/org/GNOME/Accessibility/AtkObject.java b/wrapper/org/GNOME/Accessibility/AtkObject.java
new file mode 100644
index 0000000..3196563
--- /dev/null
+++ b/wrapper/org/GNOME/Accessibility/AtkObject.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2018, Red Hat, Inc.
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package org.GNOME.Accessibility;
+
+import javax.accessibility.*;
+import java.util.Locale;
+
+/**
+* AtkObject:
+*   That class is used to wrap AccessibleContext Java object
+*   to avoid the concurrency of AWT objects.
+* @autor Giuseppe Capaldo
+*/
+public class AtkObject{
+
+    public static int hashCode(AccessibleContext ac){
+        return AtkUtil.invokeInSwing( () -> { return ac.hashCode(); }, 0);
+    }
+
+}


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