/** * Creates a new instance of <tt>Function</tt>. * * @param address The native address of the function to invoke. * @param returnType The return type of the native function. * @param paramTypes The parameter types the function accepts. * @param convention The calling convention of the function. * @param saveErrno Whether the errno should be saved or not */ public Function(long address, Type returnType, Type[] paramTypes, CallingConvention convention, boolean saveErrno) { this.functionAddress = address; this.callContext = CallContext.getCallContext(returnType, paramTypes, convention, saveErrno); this.contextAddress = callContext.getAddress(); }
/** * Creates a new instance of <tt>Function</tt>. * * @param address The native address of the function to invoke. * @param returnType The return type of the native function. * @param paramTypes The parameter types the function accepts. * @param convention The calling convention of the function. * @param saveErrno Whether the errno should be saved or not */ public Function(long address, Type returnType, Type[] paramTypes, CallingConvention convention, boolean saveErrno) { this.functionAddress = address; this.callContext = CallContext.getCallContext(returnType, paramTypes, convention, saveErrno); this.contextAddress = callContext.getAddress(); }
/** * Creates a new instance of <tt>Function</tt>. * * @param address The native address of the function to invoke. * @param returnType The return type of the native function. * @param paramTypes The parameter types the function accepts. * @param convention The calling convention of the function. * @param saveErrno Whether the errno should be saved or not */ public Function(long address, Type returnType, Type[] paramTypes, CallingConvention convention, boolean saveErrno) { this.functionAddress = address; this.callContext = CallContext.getCallContext(returnType, paramTypes, convention, saveErrno); this.contextAddress = callContext.getAddress(); }
@Override public synchronized Invoker get(Object key) { if (!(key instanceof Method)) { throw new IllegalArgumentException("key not instance of Method"); } Method m = (Method) key; long address = library.getSymbolAddress(m.getName()); if (address == 0) { return new FunctionNotFoundInvoker(m, m.getName()); } Type[] parameterTypes = new Type[m.getParameterTypes().length]; Converter[] parameterConverters = new Converter[parameterTypes.length]; for (int i = 0; i < parameterTypes.length; i++) { Class javaType = m.getParameterTypes()[i]; parameterTypes[i] = jffiType(javaType, m.getParameterAnnotations()[i]); parameterConverters[i] = Converter.parameterConverter(javaType); } return new ConvertingInvoker(NumericInvoker.create(CallContext.getCallContext(jffiType(m.getReturnType(), m.getAnnotations()), parameterTypes, CallingConvention.DEFAULT, true), address), Converter.resultConverter(m.getReturnType()), parameterConverters); }