本文整理了Java中com.sun.jna.Function
类的一些代码示例,展示了Function
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Function
类的具体详情如下:
包路径:com.sun.jna.Function
类名称:Function
[英]An abstraction for a native function pointer. An instance of Function
represents a pointer to some native function. #invoke(Class,Object[],Map) is the primary means to call the function.
Function call behavior may be modified by passing one of the following call flags:
Function
的实例表示指向某个本机函数的指针#调用(类、对象[]、映射)是调用函数的主要方法。代码示例来源:origin: net.java.dev.jna/jna
/**
* 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);
}
代码示例来源:origin: net.java.dev.jna/jna
/** 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);
}
代码示例来源:origin: net.java.dev.jna/jna
/**
* 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;
}
代码示例来源:origin: net.java.dev.jna/jna
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);
代码示例来源:origin: net.java.dev.jna/jna-platform
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);
}
代码示例来源:origin: net.java.dev.jna/jna-platform
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);
}
代码示例来源:origin: net.java.dev.jna/jna-platform
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);
}
代码示例来源:origin: net.java.dev.jna/jna-platform
@Override
public int AddRef() {
Function f = Function.getFunction(vTable[1], Function.ALT_CONVENTION);
return f.invokeInt(new Object[]{interfacePointer});
}
代码示例来源:origin: net.java.dev.jna/jna
/**
* 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);
}
代码示例来源:origin: org.netbeans.api/org-jruby
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();
代码示例来源:origin: com.sun.jna/jna
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) {
代码示例来源:origin: net.java.dev.jna/jna
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);
代码示例来源:origin: net.java.dev.jna/jna
/**
* 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);
}
代码示例来源:origin: net.java.dev.jna/jna
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());
代码示例来源:origin: net.java.dev.jna/jna
/** 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;
}
}
代码示例来源:origin: org.netbeans.api/org-jruby
public final IRubyObject invoke(Ruby runtime, Function function, Object[] args) {
return new JNAMemoryPointer(runtime, function.invokePointer(args));
}
public static final FunctionInvoker INSTANCE = new PointerInvoker();
代码示例来源:origin: com.sun.jna/jna
Method invokingMethod = (Method)options.get(OPTION_INVOKING_METHOD);
for (int i=0; i < args.length; i++) {
args[i] = convertArgument(args, i, invokingMethod, mapper);
代码示例来源:origin: com.sun.jna/jna
if (arg == null || isPrimitiveArray(arg.getClass())) {
return arg;
代码示例来源:origin: net.java.dev.jna/platform
/**
* 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() });
}
}
代码示例来源:origin: org.elasticsearch/jna
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);
内容来源于网络,如有侵权,请联系作者删除!