Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  
  package org.jruby.ext.ffi.jffi;
  
  import org.jruby.Ruby;
 
 @JRubyClass(name = "FFI::VariadicInvoker", parent = "Object")
 public class VariadicInvoker extends RubyObject {
     private final CallingConvention convention;
     private final Pointer address;
     private final FunctionInvoker functionInvoker;
     private final com.kenai.jffi.Type returnType;
 
     public static RubyClass createVariadicInvokerClass(Ruby runtimeRubyModule module) {
         RubyClass result = module.defineClassUnder("VariadicInvoker",
                 runtime.getObject(),
                 .);
         result.defineAnnotatedMethods(VariadicInvoker.class);
         result.defineAnnotatedConstants(VariadicInvoker.class);
 
         return result;
     }
    
Creates a new Invoker instance.

Parameters:
arity
 
     private VariadicInvoker(Ruby runtimeIRubyObject klazzPointer address,
             FunctionInvoker functionInvokercom.kenai.jffi.Type returnType,
             CallingConvention convention) {
         super(runtime, (RubyClassklazz);
         this. = address;
         this. = functionInvoker;
         this. = returnType;
         this. = convention;
     }
    
    
Returns the org.jruby.runtime.Arity of this function.

Returns:
The Arity of the native function.
 
     public final Arity getArity() {
         return .;
     }
 
     @JRubyMethod(name = { "__new" }, meta = true, required = 3, optional = 1)
     public static VariadicInvoker newInvoker(ThreadContext contextIRubyObject klassIRubyObject[] args) {
 
         if (!(args[0] instanceof Pointer)) {
             throw context.runtime.newTypeError(args[0], context.runtime.getFFI().);
         }
 
         final Pointer address = (Pointerargs[0];
         
         if (!(args[1] instanceof Type)) {
             throw context.runtime.newTypeError("invalid return type");
         }
         
         final Type returnType = (Typeargs[1];
         final CallingConvention conv = "stdcall".equals(args[2].toString())
                 ? . : .;
 
         FunctionInvoker functionInvoker = DefaultMethodFactory.getFunctionInvoker(returnType);
         return new VariadicInvoker(context.runtimeklassaddress,
                 functionInvoker, FFIUtil.getFFIType(returnType), conv);
     }
 
     @JRubyMethod(name = { "invoke" })
     public IRubyObject invoke(ThreadContext contextIRubyObject typesArgIRubyObject paramsArg) {
         IRubyObject[] types = ((RubyArraytypesArg).toJavaArrayMaybeUnsafe();
         IRubyObject[] params = ((RubyArrayparamsArg).toJavaArrayMaybeUnsafe();
         com.kenai.jffi.Type[] ffiParamTypes = new com.kenai.jffi.Type[types.length];
         ParameterMarshaller[] marshallers = new ParameterMarshaller[types.length];
 
         for (int i = 0; i < types.length; ++i) {
             Type type = (Typetypes[i];
             switch (NativeType.valueOf(type)) {
                 case :
                 case :
                 case :
                     ffiParamTypes[i] = ....;
                     marshallers[i] = DefaultMethodFactory.getMarshaller(.);
                     break;
                 case :
                case :
                case :
                    ffiParamTypes[i] = ....;
                    marshallers[i] = DefaultMethodFactory.getMarshaller(.);
                    break;
                case :
                case :
                    ffiParamTypes[i] = ....;
                    marshallers[i] = DefaultMethodFactory.getMarshaller(.);
                    break;
                default:
                    ffiParamTypes[i] = FFIUtil.getFFIType(type);
                    marshallers[i] = DefaultMethodFactory.getMarshaller((Typetypes[i], .null);
                    break;
            }
        }
        Invocation invocation = new Invocation(context);
        Function function = new Function(.getAddress(), ffiParamTypes);
        try {
            HeapInvocationBuffer args = new HeapInvocationBuffer(function);
            for (int i = 0; i < marshallers.length; ++i) {
                marshallers[i].marshal(invocationargsparams[i]);
            }
            return .invoke(contextfunctionargs);
        } finally {
            invocation.finish();
        }
    }
New to GrepCode? Check out our FAQ X