Exemplo n.º 1
0
  public static String toStringAllLibraries() {
    StringBuilder b = new StringBuilder();
    for (JNILibrary lib : cache.values()) {
      b.append(lib.toString()).append("\n");
    }

    return b.toString();
  }
Exemplo n.º 2
0
  /**
   * Find symbol.
   *
   * @param m the m
   * @return the jNI symbol
   */
  public static JNISymbol findSymbol(Method m) {
    for (JNILibrary lib : cache.values()) {
      JNISymbol sym = lib.getSymbol(m);
      if (sym != null) {
        return sym;
      }
    }

    return null;
  }
Exemplo n.º 3
0
  /**
   * Register.
   *
   * @param natives the natives
   * @param jni the jni
   * @param preload the preload
   */
  public static void register(String[] natives, String[] jni, Class<?>[] preload) {

    /*
     * Load JNI libraries. These libraries have definitions for our class
     * methods marked with native modifier. JNI libraries are loaded using
     * System.loadLibrary() call.
     */
    for (String name : jni) {
      JNILibrary.loadLibrary(name);
    }

    /*
     * Load 3rd party, external native raw libraries. These libraries are opened
     * using dlopen call, and not loaded like JNI libraries. They are typically
     * loaded as a dependency to one of the JNI libraries, but not necessarily.
     * Any native library can be opened this way.
     */
    for (String name : natives) {
      NativeLibrary.loadLibrary(name);
    }

    /*
     * Pre-load a list of classes. This forces each class to be loaded and
     * initialized. It also allows each of those classes to register themselves
     * and initialize their own libraries.
     */
    for (Class<?> clazz : preload) {
      try {
        Class.forName(clazz.getCanonicalName());
      } catch (ClassNotFoundException e) {
        e.printStackTrace();
      }
    }
  }
Exemplo n.º 4
0
  /**
   * Register native methods.
   *
   * @param defaultApi the default api
   * @param methods the methods
   * @return true, if successful
   */
  public static boolean registerNativeMethods(String defaultApi, Method[] methods) {
    methods = filterAllNativeMethods(methods);

    for (Method method : methods) {
      JNILibrary.findSymbol(method);
    }

    return true;
  }
Exemplo n.º 5
0
 /**
  * Open.
  *
  * @param name the name
  * @return the jNI library
  */
 public static JNILibrary open(String name) {
   return JNILibrary.loadLibrary(name);
 }