Refine search
/** * Obtain a <code>Function</code> representing a native * function pointer. In general, this function should be used by dynamic * languages; Java code should allow JNA to bind to a specific Callback * interface instead by defining a return type or Structure field type. * * <p>The allocated instance represents a pointer to the native * function pointer. * * @param p Native function pointer */ public static Function getFunction(Pointer p) { return getFunction(p, 0, null); }
/** Chain invocation to the native function. */ @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (Library.Handler.OBJECT_TOSTRING.equals(method)) { String str = "Proxy interface to " + function; Method m = (Method)options.get(Function.OPTION_INVOKING_METHOD); Class<?> cls = findCallbackClass(m.getDeclaringClass()); str += " (" + cls.getName() + ")"; return str; } else if (Library.Handler.OBJECT_HASHCODE.equals(method)) { return Integer.valueOf(hashCode()); } else if (Library.Handler.OBJECT_EQUALS.equals(method)) { Object o = args[0]; if (o != null && Proxy.isProxyClass(o.getClass())) { return Function.valueOf(Proxy.getInvocationHandler(o) == this); } return Boolean.FALSE; } if (Function.isVarArgs(method)) { args = Function.concatenateVarArgs(args); } return function.invoke(method.getReturnType(), args, options); }
/** * Call the native function being represented by this object * * @param callFlags calling convention to be used * @param args * Arguments to pass to the native function * @param wide whether the native string uses <code>wchar_t</code>; * if false, <code>char</code> is assumed * @return The value returned by the target native function, as a String */ private String invokeString(int callFlags, Object[] args, boolean wide) { Pointer ptr = invokePointer(callFlags, args); String s = null; if (ptr != null) { if (wide) { s = ptr.getWideString(0); } else { s = ptr.getString(0, encoding); } } return s; }
result = null; } else if (returnType==boolean.class || returnType==Boolean.class) { result = valueOf(Native.invokeInt(this, this.peer, callFlags, args) != 0); } else if (returnType==byte.class || returnType==Byte.class) { result = Byte.valueOf((byte)Native.invokeInt(this, this.peer, callFlags, args)); result = Double.valueOf(Native.invokeDouble(this, this.peer, callFlags, args)); } else if (returnType==String.class) { result = invokeString(callFlags, args, false); } else if (returnType==WString.class) { String s = invokeString(callFlags, args, true); if (s != null) { result = new WString(s); return invokePointer(callFlags, args); } else if (Structure.class.isAssignableFrom(returnType)) { if (Structure.ByValue.class.isAssignableFrom(returnType)) { result = s; } else { result = invokePointer(callFlags, args); if (result != null) { Structure s = Structure.newInstance((Class<? extends Structure>)returnType, (Pointer)result); result = invokePointer(callFlags, args); if (result != null) { result = CallbackReference.getCallback(returnType, (Pointer)result); Pointer p = invokePointer(callFlags, args);
protected int _invokeNativeInt(int vtableId, Object[] args) { Pointer vptr = this.getPointer().getPointer(0); // we take the vtable id and multiply with the pointer size (4 bytes on // 32bit OS) Function func = Function.getFunction(vptr.getPointer(vtableId * Native.POINTER_SIZE)); return func.invokeInt(args); }
protected Object _invokeNativeObject(int vtableId, Object[] args, Class<?> returnType) { Pointer vptr = this.getPointer().getPointer(0); // we take the vtable id and multiply with the pointer size (4 bytes on // 32bit OS) Function func = Function.getFunction(vptr.getPointer(vtableId * Native.POINTER_SIZE)); return func.invoke(returnType, args); }
protected void _invokeNativeVoid(int vtableId, Object[] args) { Pointer vptr = this.getPointer().getPointer(0); // we take the vtable id and multiply with the pointer size (4 bytes on // 32bit OS) Function func = Function.getFunction(vptr.getPointer(vtableId * Native.POINTER_SIZE)); func.invokeVoid(args); }
@Override public int AddRef() { Function f = Function.getFunction(vTable[1], Function.ALT_CONVENTION); return f.invokeInt(new Object[]{interfacePointer}); }
/** * Call the native function being represented by this object * * @param args * Arguments to pass to the native function */ public void invoke(Object[] args) { invoke(Void.class, args); }
public final IRubyObject invoke(Ruby runtime, Function function, Object[] args) { Pointer address = function.invokePointer(args); if (address == null) { return runtime.getNil(); } int len = (int) address.indexOf(0, (byte) 0); if (len == 0) { return RubyString.newEmptyString(runtime); } ByteList bl = new ByteList(len); bl.length(len); address.read(0, bl.unsafeBytes(), bl.begin(), len); return RubyString.newString(runtime, bl); } public static final FunctionInvoker INSTANCE = new StringInvoker();
Object result = null; if (returnType == null || returnType==void.class || returnType==Void.class) { invokeVoid(callingConvention, args); result = null; result = Boolean.valueOf(invokeInt(callingConvention, args) != 0); result = new Character((char)invokeInt(callingConvention, args)); result = new Integer(invokeInt(callingConvention, args)); result = new Long(invokeLong(callingConvention, args)); result = new Float(invokeFloat(callingConvention, args)); result = new Double(invokeDouble(callingConvention, args)); if (Structure.ByValue.class.isAssignableFrom(returnType)) { Structure s = invokeStructure(callingConvention, args, Structure.newInstance(returnType)); s.read(); result = invokePointer(callingConvention, args); if (result != null) { Structure s = Structure.newInstance(returnType); result = invokePointer(callingConvention, args); if (result != null) {
boolean isVarArgs = args.length > 0 && invokingMethod != null ? isVarArgs(invokingMethod) : false; int fixedArgs = args.length > 0 && invokingMethod != null ? fixedArgs(invokingMethod) : 0; for (int i=0; i < args.length; i++) { Class<?> paramType = invokingMethod != null : paramTypes[i]) : null; args[i] = convertArgument(args, i, invokingMethod, mapper, allowObjects, paramType); Object result = invoke(args, nativeReturnType, allowObjects, fixedArgs);
/** * Obtain a <code>Function</code> representing a native * function pointer. In general, this function should be used by dynamic * languages; Java code should allow JNA to bind to a specific Callback * interface instead by defining a return type or Structure field type. * * <p>The allocated instance represents a pointer to the native * function pointer. * * @param p * Native function pointer * @param callFlags * Function <a href="#callflags">call flags</a> * @param encoding * Encoding to use for conversion between Java and native * strings. */ public static Function getFunction(Pointer p, int callFlags, String encoding) { return new Function(p, callFlags, encoding); }
if (arg == null || isPrimitiveArray(arg.getClass())) { return arg; if (!Structure.ByReference[].class.isAssignableFrom(expectedType)) { if (byRef) { throw new IllegalArgumentException("Function " + getName() + " declared Structure[] at parameter " + index + " but array of " throw new IllegalArgumentException("Function " + getName() + " declared Structure[] at parameter " + index + " but element " + i + arg.getClass().getName() + " at parameter " + index + " of function " + getName());
/** Looks up the method name by adding a "W" or "A" suffix as appropriate. */ public String getFunctionName(NativeLibrary library, Method method) { String name = method.getName(); if (!name.endsWith("W") && !name.endsWith("A")) { try { name = library.getFunction(name + suffix, StdCallLibrary.STDCALL_CONVENTION).getName(); } catch(UnsatisfiedLinkError e) { // ignore and let caller use undecorated name } } return name; } }
public final IRubyObject invoke(Ruby runtime, Function function, Object[] args) { return new JNAMemoryPointer(runtime, function.invokePointer(args)); } public static final FunctionInvoker INSTANCE = new PointerInvoker();
Method invokingMethod = (Method)options.get(OPTION_INVOKING_METHOD); for (int i=0; i < args.length; i++) { args[i] = convertArgument(args, i, invokingMethod, mapper);
if (arg == null || isPrimitiveArray(arg.getClass())) { return arg;
/** * Release. * * @return the ulong */ public int Release() { Pointer vptr = this.getPointer().getPointer(0); Function func = Function.getFunction(vptr.getPointer(8)); return func.invokeInt(new Object[] { this.getPointer() }); } }
result = null; } else if (returnType==boolean.class || returnType==Boolean.class) { result = valueOf(Native.invokeInt(this, this.peer, callFlags, args) != 0); } else if (returnType==byte.class || returnType==Byte.class) { result = Byte.valueOf((byte)Native.invokeInt(this, this.peer, callFlags, args)); result = Double.valueOf(Native.invokeDouble(this, this.peer, callFlags, args)); } else if (returnType==String.class) { result = invokeString(callFlags, args, false); } else if (returnType==WString.class) { String s = invokeString(callFlags, args, true); if (s != null) { result = new WString(s); return invokePointer(callFlags, args); } else if (Structure.class.isAssignableFrom(returnType)) { if (Structure.ByValue.class.isAssignableFrom(returnType)) { result = s; } else { result = invokePointer(callFlags, args); if (result != null) { Structure s = Structure.newInstance(returnType, (Pointer)result); result = invokePointer(callFlags, args); if (result != null) { result = CallbackReference.getCallback(returnType, (Pointer)result); Pointer p = invokePointer(callFlags, args);