altosuilib: Try to detect the architecture when loading JNI lib
[fw/altos] / altosuilib / AltosUILib.java
index 1b1214052f8f9598f46b8895456d6a3f95a23b76..ccadf07cc851e8e678522b35bdd11a0d5cf1396f 100644 (file)
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altosuilib_1;
+package org.altusmetrum.altosuilib_3;
 
 import java.awt.*;
 import libaltosJNI.*;
 
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_5.*;
 
 public class AltosUILib extends AltosLib {
 
@@ -80,22 +80,42 @@ public class AltosUILib extends AltosLib {
 
        static public boolean initialized = false;
        static public boolean loaded_library = false;
+       static public boolean has_bluetooth = false;
+
+       static final String[] library_names_32 = { "altos", "altos32", "altos64" };
+       static final String[] library_names_64 = { "altos", "altos64", "altos32" };
 
        public static boolean load_library() {
                if (!initialized) {
-                       try {
-                               System.loadLibrary("altos");
-                               libaltos.altos_init();
-                               loaded_library = true;
-                       } catch (UnsatisfiedLinkError e) {
+                       String model = System.getProperty("sun.arch.data.model", "missing");
+                       boolean is_64 = false;
+                       if (model.equals("64")) {
+                               is_64 = true;
+                       } else if (model.equals("32")) {
+                               ;
+                       } else {
+                               String arch = System.getProperty("os.arch", "missing");
+                               if (arch.endsWith("64"))
+                                       is_64 = true;
+                       }
+                       for (String name : is_64 ? library_names_64 : library_names_32) {
                                try {
-                                       System.loadLibrary("altos64");
+                                       System.loadLibrary(name);
                                        libaltos.altos_init();
                                        loaded_library = true;
-                               } catch (UnsatisfiedLinkError e2) {
+                                       break;
+                               } catch (UnsatisfiedLinkError e) {
+                                       System.out.printf("Link error %s\n", e.getMessage());
                                        loaded_library = false;
                                }
                        }
+
+                       String OS = System.getProperty("os.name");
+
+                       if (OS.startsWith("Linux")) {
+                               has_bluetooth = true;
+                       }
+
                        initialized = true;
                }
                return loaded_library;