Example #1
0
 /**
  * Create a new <code>Function</code> that is linked with a native function that follows the given
  * calling convention.
  *
  * <p>The allocated instance represents a pointer to the given function address, called with the
  * given calling convention.
  *
  * @param functionAddress Address of the native function
  * @param callFlags Function <a href="#callflags">call flags</a>
  * @param encoding Encoding for conversion between Java and native strings.
  */
 Function(Pointer functionAddress, int callFlags, String encoding) {
   checkCallingConvention(callFlags & MASK_CC);
   if (functionAddress == null || functionAddress.peer == 0) {
     throw new NullPointerException("Function address may not be null");
   }
   this.functionName = functionAddress.toString();
   this.callFlags = callFlags;
   this.peer = functionAddress.peer;
   this.options = Collections.EMPTY_MAP;
   this.encoding = encoding != null ? encoding : Native.getDefaultStringEncoding();
 }
Example #2
0
 /**
  * Create a new <code>Function</code> that is linked with a native function that follows the given
  * calling convention.
  *
  * <p>The allocated instance represents a pointer to the named native function from the supplied
  * library, called with the given calling convention.
  *
  * @param library {@link NativeLibrary} in which to find the function
  * @param functionName Name of the native function to be linked with
  * @param callFlags Function <a href="#callflags">call flags</a>
  * @param encoding Encoding for conversion between Java and native strings.
  * @throws UnsatisfiedLinkError if the given function name is not found within the library.
  */
 Function(NativeLibrary library, String functionName, int callFlags, String encoding) {
   checkCallingConvention(callFlags & MASK_CC);
   if (functionName == null) throw new NullPointerException("Function name must not be null");
   this.library = library;
   this.functionName = functionName;
   this.callFlags = callFlags;
   this.options = library.options;
   this.encoding = encoding != null ? encoding : Native.getDefaultStringEncoding();
   try {
     this.peer = library.getSymbolAddress(functionName);
   } catch (UnsatisfiedLinkError e) {
     throw new UnsatisfiedLinkError(
         "Error looking up function '" + functionName + "': " + e.getMessage());
   }
 }