com.sun.jna.Native.register()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(272)

本文整理了Java中com.sun.jna.Native.register()方法的一些代码示例,展示了Native.register()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Native.register()方法的具体详情如下:
包路径:com.sun.jna.Native
类名称:Native
方法名:register

Native.register介绍

[英]When called from a class static initializer, maps all native methods found within that class to native libraries via the JNA raw calling interface.
[中]从类静态初始值设定项调用时,通过JNA原始调用接口将该类中找到的所有本机方法映射到本机库。

代码示例

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/**
 * Init the native binding to the underlying system library.
 * @return <code>true</code> if the link is effective and <code>false</code> otherwise.
 */
public static void init() throws UnsatisfiedLinkError {
  Native.unregister(JOpenVRLibrary.class);
  
  String path = System.getProperty(JNA_OPENVR_LIBRARY_PATH);
  if (path != null){
    
   JNA_LIBRARY_NAME      = path;
    
   logger.config("Using OpenVR implementation located at "+JNA_LIBRARY_NAME);
   
   JNA_NATIVE_LIB = NativeLibrary.getInstance(JOpenVRLibrary.JNA_LIBRARY_NAME);
   Native.register(JOpenVRLibrary.class, JOpenVRLibrary.JNA_NATIVE_LIB);
  } else {
   
   JNA_LIBRARY_NAME      = "openvr_api";
   
   logger.config("Using embedded OpenVR implementation "+JOpenVRLibrary.JNA_LIBRARY_NAME);
   
   JNA_NATIVE_LIB = NativeLibrary.getInstance(JOpenVRLibrary.JNA_LIBRARY_NAME);
   Native.register(JOpenVRLibrary.class, JOpenVRLibrary.JNA_NATIVE_LIB);
  }
}

代码示例来源:origin: apache/geode

public static void lockMemory() {
 try {
  Native.register(Platform.C_LIBRARY_NAME);
  int result = mlockall(1);
  if (result == 0) {
   return;
  }
 } catch (Throwable t) {
  throw new IllegalStateException("Error trying to lock memory", t);
 }
 int lastError = Native.getLastError();
 String message = "mlockall failed: " + lastError;
 if (lastError == 1 || lastError == 12) { // EPERM || ENOMEM
  message = "Unable to lock memory due to insufficient free space or privileges.  "
    + "Please check the RLIMIT_MEMLOCK soft resource limit (ulimit -l) and "
    + "increase the available memory if needed";
 }
 throw new IllegalStateException(message);
}

代码示例来源:origin: org.elasticsearch/elasticsearch

private JNAKernel32Library() {
  if (Constants.WINDOWS) {
    try {
      Native.register("kernel32");
      logger.debug("windows/Kernel32 library loaded");
    } catch (NoClassDefFoundError e) {
      logger.warn("JNA not found. native methods and handlers will be disabled.");
    } catch (UnsatisfiedLinkError e) {
      logger.warn("unable to link Windows/Kernel32 library. native methods and handlers will be disabled.");
    }
  }
}

代码示例来源:origin: net.java.dev.jna/jna

/**
 * When called from a class static initializer, maps all native methods
 * found within that class to native libraries via the JNA raw calling
 * interface.  Uses the class loader of the given class to search for the
 * native library in the resource path if it is not found in the system
 * library load path or <code>jna.library.path</code>.
 * @param cls Class with native methods to register
 * @param libName name of or path to native library to which functions
 * should be bound
 */
public static void register(Class<?> cls, String libName) {
  NativeLibrary library =
      NativeLibrary.getInstance(libName, Collections.singletonMap(Library.OPTION_CLASSLOADER, cls.getClassLoader()));
  register(cls, library);
}

代码示例来源:origin: net.java.dev.jna/jna

/**
 * When called from a class static initializer, maps all native methods
 * found within that class to native libraries via the JNA raw calling
 * interface.
 * @param lib native library to which functions should be bound
 */
public static void register(NativeLibrary lib) {
  register(findDirectMappedClass(getCallingClass()), lib);
}

代码示例来源:origin: net.java.dev.jna/jna

/**
 * When called from a class static initializer, maps all native methods
 * found within that class to native libraries via the JNA raw calling
 * interface.
 * @param libName library name to which functions should be bound
 */
public static void register(String libName) {
  register(findDirectMappedClass(getCallingClass()), libName);
}

代码示例来源:origin: ev3dev-lang-java/ev3dev-lang-java

public NativeLibc() {
  synchronized (NativeLibc.class) {
    if (!initialized) {
      try {
        Native.register(Platform.C_LIBRARY_NAME);
        initialized = true;
      } catch (Exception e) {
        throw new IllegalArgumentException("native libc load failed", e);
      }
    }
  }
}

代码示例来源:origin: org.opennms.core/org.opennms.core.jicmpv6

Native.register((String)null);

代码示例来源:origin: org.opennms.core/org.opennms.core.jicmpv6

Native.register((String)null);

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

private JNAKernel32Library() {
  if (Constants.WINDOWS) {
    try {
      Native.register("kernel32");
      logger.debug("windows/Kernel32 library loaded");
    } catch (NoClassDefFoundError e) {
      logger.warn("JNA not found. native methods and handlers will be disabled.");
    } catch (UnsatisfiedLinkError e) {
      logger.warn("unable to link Windows/Kernel32 library. native methods and handlers will be disabled.");
    }
  }
}

代码示例来源:origin: com.squareup.jnagmp/jnagmp

private static void load(String name) {
 NativeLibrary library = NativeLibrary.getInstance(name, LibGmp.class.getClassLoader());
 Native.register(LibGmp.class, library);
 Native.register(SIZE_T_CLASS, library);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

private JNAKernel32Library() {
  if (Constants.WINDOWS) {
    try {
      Native.register("kernel32");
      logger.debug("windows/Kernel32 library loaded");
    } catch (NoClassDefFoundError e) {
      logger.warn("JNA not found. native methods and handlers will be disabled.");
    } catch (UnsatisfiedLinkError e) {
      logger.warn("unable to link Windows/Kernel32 library. native methods and handlers will be disabled.");
    }
  }
}

代码示例来源:origin: square/jna-gmp

private static void load(String name) {
 NativeLibrary library = NativeLibrary.getInstance(name, LibGmp.class.getClassLoader());
 Native.register(LibGmp.class, library);
 Native.register(SIZE_T_CLASS, library);
}

代码示例来源:origin: apache/servicemix-bundles

private JNAKernel32Library() {
  if (Constants.WINDOWS) {
    try {
      Native.register("kernel32");
      logger.debug("windows/Kernel32 library loaded");
    } catch (NoClassDefFoundError e) {
      logger.warn("JNA not found. native methods and handlers will be disabled.");
    } catch (UnsatisfiedLinkError e) {
      logger.warn("unable to link Windows/Kernel32 library. native methods and handlers will be disabled.");
    }
  }
}

代码示例来源:origin: terl/lazysodium-java

/**
 * Please note that the libsodium.so
 * file HAS to be built for the platform this program will run on.
 *
 * @param path Absolute path to libsodium.so.
 */
public SodiumJava(String path) {
  Native.register(SodiumJava.class, path);
  onRegistered();
}

代码示例来源:origin: org.elasticsearch/jna

/**
 * When called from a class static initializer, maps all native methods
 * found within that class to native libraries via the JNA raw calling
 * interface.  Uses the class loader of the given class to search for the
 * native library in the resource path if it is not found in the system
 * library load path or <code>jna.library.path</code>.
 * @param cls Class with native methods to register
 * @param libName name of or path to native library to which functions
 * should be bound
 */
public static void register(Class<?> cls, String libName) {
  NativeLibrary library =
      NativeLibrary.getInstance(libName, Collections.singletonMap(Library.OPTION_CLASSLOADER, cls.getClassLoader()));
  register(cls, library);
}

代码示例来源:origin: org.elasticsearch/jna

/**
 * When called from a class static initializer, maps all native methods
 * found within that class to native libraries via the JNA raw calling
 * interface.
 * @param lib native library to which functions should be bound
 */
public static void register(NativeLibrary lib) {
  register(findDirectMappedClass(getCallingClass()), lib);
}

代码示例来源:origin: org.elasticsearch/jna

/**
 * When called from a class static initializer, maps all native methods
 * found within that class to native libraries via the JNA raw calling
 * interface.
 * @param libName library name to which functions should be bound
 */
public static void register(String libName) {
  register(findDirectMappedClass(getCallingClass()), libName);
}

代码示例来源:origin: org.apache.geode/gemfire-core

public static void lockMemory() {
 int result = 0;
 try {
  Native.register(Platform.C_LIBRARY_NAME);
  result = mlockall(1);
  if (result == 0) {
   return;
  }
 } catch (Throwable t) {
  throw new IllegalStateException("Error trying to lock memory", t);
 }
 int errno = Native.getLastError();
 String msg = "mlockall failed: " + errno;
 if (errno == 1 || errno == 12) {  // EPERM || ENOMEM
  msg = "Unable to lock memory due to insufficient free space or privileges.  " 
    + "Please check the RLIMIT_MEMLOCK soft resource limit (ulimit -l) and " 
    + "increase the available memory if needed";
 }
 throw new IllegalStateException(msg);
}

代码示例来源:origin: harbby/presto-connectors

private JNAKernel32Library() {
  if (Constants.WINDOWS) {
    try {
      Native.register("kernel32");
      logger.debug("windows/Kernel32 library loaded");
    } catch (NoClassDefFoundError e) {
      logger.warn("JNA not found. native methods and handlers will be disabled.");
    } catch (UnsatisfiedLinkError e) {
      logger.warn("unable to link Windows/Kernel32 library. native methods and handlers will be disabled.");
    }
  }
}

相关文章

微信公众号

最新文章

更多

Native类方法