/** Return the preferred {@link TypeMapper} for the given native interface. * See {@link com.sun.jna.Library#OPTION_TYPE_MAPPER}. */ public static TypeMapper getTypeMapper(Class<?> cls) { Map<String, ?> options = getLibraryOptions(cls); return (TypeMapper) options.get(Library.OPTION_TYPE_MAPPER); }
/** * @param cls The native interface type * @return The preferred structure alignment for the given native interface. * @see com.sun.jna.Library#OPTION_STRUCTURE_ALIGNMENT */ public static int getStructureAlignment(Class<?> cls) { Integer alignment = (Integer)getLibraryOptions(cls).get(Library.OPTION_STRUCTURE_ALIGNMENT); return alignment == null ? Structure.ALIGN_DEFAULT : alignment; }
/** * @param cls The native interface type * @return The preferred string encoding for the given native interface. * If there is no setting, defaults to the {@link #getDefaultStringEncoding()}. * @see com.sun.jna.Library#OPTION_STRING_ENCODING */ public static String getStringEncoding(Class<?> cls) { Map<String, ?> options = getLibraryOptions(cls); String encoding = (String) options.get(Library.OPTION_STRING_ENCODING); return encoding != null ? encoding : getDefaultStringEncoding(); }
Map<String, Object> foptions = new HashMap<String, Object>(Native.getLibraryOptions(type)); foptions.put(Function.OPTION_INVOKING_METHOD, getCallbackMethod(type)); NativeFunctionHandler h = new NativeFunctionHandler(p, ctype, foptions);
/** Native code may call this method with direct=true. */ private static Pointer getFunctionPointer(Callback cb, boolean direct) { Pointer fp = null; if (cb == null) { return null; } if ((fp = getNativeFunctionPointer(cb)) != null) { return fp; } Map<String, ?> options = Native.getLibraryOptions(cb.getClass()); int callingConvention = cb instanceof AltCallingConvention ? Function.ALT_CONVENTION : (options != null && options.containsKey(Library.OPTION_CALLING_CONVENTION) ? ((Integer)options.get(Library.OPTION_CALLING_CONVENTION)).intValue() : Function.C_CONVENTION); Map<Callback, CallbackReference> map = direct ? directCallbackMap : callbackMap; synchronized(pointerCallbackMap) { CallbackReference cbref = map.get(cb); if (cbref == null) { cbref = new CallbackReference(cb, callingConvention, direct); map.put(cb, cbref); pointerCallbackMap.put(cbref.getTrampoline(), new WeakReference<Callback>(cb)); if (initializers.containsKey(cb)) { cbref.setCallbackOptions(Native.CB_HAS_INITIALIZER); } } return cbref.getTrampoline(); } }
/** Return the preferred {@link TypeMapper} for the given native interface. * See {@link com.sun.jna.Library#OPTION_TYPE_MAPPER}. */ public static TypeMapper getTypeMapper(Class<?> cls) { Map<String, ?> options = getLibraryOptions(cls); return (TypeMapper) options.get(Library.OPTION_TYPE_MAPPER); }
/** * @param cls The native interface type * @return The preferred structure alignment for the given native interface. * @see com.sun.jna.Library#OPTION_STRUCTURE_ALIGNMENT */ public static int getStructureAlignment(Class<?> cls) { Integer alignment = (Integer)getLibraryOptions(cls).get(Library.OPTION_STRUCTURE_ALIGNMENT); return alignment == null ? Structure.ALIGN_DEFAULT : alignment.intValue(); }
/** * @param cls The native interface type * @return The preferred string encoding for the given native interface. * If there is no setting, defaults to the {@link #getDefaultStringEncoding()}. * @see com.sun.jna.Library#OPTION_STRING_ENCODING */ public static String getStringEncoding(Class<?> cls) { Map<String, ?> options = getLibraryOptions(cls); String encoding = (String) options.get(Library.OPTION_STRING_ENCODING); return encoding != null ? encoding : getDefaultStringEncoding(); }
private interface NativeFunctionProxy { }
Map options = getLibraryOptions(cls); if (options != null && options.containsKey(Library.OPTION_STRUCTURE_ALIGNMENT)) {
Map<String, Object> foptions = new HashMap<String, Object>(Native.getLibraryOptions(type)); foptions.put(Function.OPTION_INVOKING_METHOD, getCallbackMethod(type)); NativeFunctionHandler h = new NativeFunctionHandler(p, ctype, foptions);
/** Native code may call this method with direct=true. */ private static Pointer getFunctionPointer(Callback cb, boolean direct) { Pointer fp = null; if (cb == null) { return null; } if ((fp = getNativeFunctionPointer(cb)) != null) { return fp; } Map<String, ?> options = Native.getLibraryOptions(cb.getClass()); int callingConvention = cb instanceof AltCallingConvention ? Function.ALT_CONVENTION : (options != null && options.containsKey(Library.OPTION_CALLING_CONVENTION) ? ((Integer)options.get(Library.OPTION_CALLING_CONVENTION)).intValue() : Function.C_CONVENTION); Map<Callback, CallbackReference> map = direct ? directCallbackMap : callbackMap; synchronized(pointerCallbackMap) { CallbackReference cbref = map.get(cb); if (cbref == null) { cbref = new CallbackReference(cb, callingConvention, direct); map.put(cb, cbref); pointerCallbackMap.put(cbref.getTrampoline(), new WeakReference<Callback>(cb)); if (initializers.containsKey(cb)) { cbref.setCallbackOptions(Native.CB_HAS_INITIALIZER); } } return cbref.getTrampoline(); } }