/** * Create a new {@link Function} that is linked with a native * function that follows a given calling flags. * * @param functionName * Name of the native function to be linked with * @param callFlags * Flags affecting the function invocation * @param encoding * Encoding to use to convert between Java and native * strings. * @throws UnsatisfiedLinkError if the function is not found */ public Function getFunction(String functionName, int callFlags, String encoding) { if (functionName == null) { throw new NullPointerException("Function name may not be null"); } synchronized (functions) { String key = functionKey(functionName, callFlags, encoding); Function function = functions.get(key); if (function == null) { function = new Function(this, functionName, callFlags, encoding); functions.put(key, function); } return function; } }
private NativeLibrary(String libraryName, String libraryPath, long handle, Map<String, ?> options) { this.libraryName = getLibraryName(libraryName); this.libraryPath = libraryPath; this.handle = handle; Object option = options.get(Library.OPTION_CALLING_CONVENTION); int callingConvention = option instanceof Number ? ((Number)option).intValue() : Function.C_CONVENTION; this.callFlags = callingConvention; this.options = options; this.encoding = (String)options.get(Library.OPTION_STRING_ENCODING); if (this.encoding == null) { this.encoding = Native.getDefaultStringEncoding(); } // Special workaround for w32 kernel32.GetLastError // Short-circuit the function to use built-in GetLastError access if (Platform.isWindows() && "kernel32".equals(this.libraryName.toLowerCase())) { synchronized(functions) { Function f = new Function(this, "GetLastError", Function.ALT_CONVENTION, encoding) { @Override Object invoke(Object[] args, Class<?> returnType, boolean b, int fixedArgs) { return Integer.valueOf(Native.getLastError()); } @Override Object invoke(Method invokingMethod, Class<?>[] paramTypes, Class<?> returnType, Object[] inArgs, Map<String, ?> options) { return Integer.valueOf(Native.getLastError()); } }; functions.put(functionKey("GetLastError", callFlags, encoding), f); } } }
/** * Create a new {@link Function} that is linked with a native * function that follows a given calling flags. * * @param functionName * Name of the native function to be linked with * @param callFlags * Flags affecting the function invocation * @param encoding * Encoding to use to convert between Java and native * strings. * @throws UnsatisfiedLinkError if the function is not found */ public Function getFunction(String functionName, int callFlags, String encoding) { if (functionName == null) { throw new NullPointerException("Function name may not be null"); } synchronized (functions) { String key = functionKey(functionName, callFlags, encoding); Function function = functions.get(key); if (function == null) { function = new Function(this, functionName, callFlags, encoding); functions.put(key, function); } return function; } }
private NativeLibrary(String libraryName, String libraryPath, long handle, Map<String, ?> options) { this.libraryName = getLibraryName(libraryName); this.libraryPath = libraryPath; this.handle = handle; Object option = options.get(Library.OPTION_CALLING_CONVENTION); int callingConvention = option instanceof Number ? ((Number)option).intValue() : Function.C_CONVENTION; this.callFlags = callingConvention; this.options = options; this.encoding = (String)options.get(Library.OPTION_STRING_ENCODING); if (this.encoding == null) { this.encoding = Native.getDefaultStringEncoding(); } // Special workaround for w32 kernel32.GetLastError // Short-circuit the function to use built-in GetLastError access if (Platform.isWindows() && "kernel32".equals(this.libraryName.toLowerCase())) { synchronized(functions) { Function f = new Function(this, "GetLastError", Function.ALT_CONVENTION, encoding) { @Override Object invoke(Object[] args, Class<?> returnType, boolean b, int fixedArgs) { return Integer.valueOf(Native.getLastError()); } @Override Object invoke(Method invokingMethod, Class<?>[] paramTypes, Class<?> returnType, Object[] inArgs, Map<String, ?> options) { return Integer.valueOf(Native.getLastError()); } }; functions.put(functionKey("GetLastError", callFlags, encoding), f); } } }