Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
BEGIN LICENSE BLOCK ***** Version: EPL 1.0/GPL 2.0/LGPL 2.1 The contents of this file are subject to the Eclipse Public License Version 1.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.eclipse.org/legal/epl-v10.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. Copyright (C) 2008 JRuby project Alternatively, the contents of this file may be used under the terms of either of the GNU General Public License Version 2 or later (the "GPL"), or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), in which case the provisions of the GPL or the LGPL are applicable instead of those above. If you wish to allow use of your version of this file only under the terms of either the GPL or the LGPL, and not to allow others to use your version of this file under the terms of the EPL, indicate your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL or the LGPL. If you do not delete the provisions above, a recipient may use your version of this file under the terms of any one of the EPL, the GPL or the LGPL. END LICENSE BLOCK ***
 
 
 package org.jruby.ext.ffi;
 
 import java.util.List;
 import org.jruby.Ruby;
A factory that can create a FFI Provider
 
 public abstract class Factory {
 
     private static final class SingletonHolder {
 
         private static final Factory INSTANCE = getInstance();
 
         private static final Factory getInstance() {
             final String providerName = System.getProperty("ffi.factory");
             Factory factory = null;
             List<StringproviderNames = new ArrayList<String>();
             List<Throwableerrors = new ArrayList<Throwable>();
 
             if (providerName != null) {
                 providerNames.add(providerName);
             }
             final String prefix = Factory.class.getPackage().getName();
             providerNames.add(prefix + ".jffi.Factory");
             for (String className : providerNames) {
                 try {
                     factory = (Factory) Class.forName(classNametrue, Ruby.getClassLoader()).newInstance();
                     break;
                 } catch (Throwable ex) {
                     errors.add(ex);
                 }
             }
 
             if (factory == null) {
                 StringBuilder sb = new StringBuilder();
                 for (Throwable t : errors) {
                     sb.append(t.getLocalizedMessage()).append('\n');
                 }
 
                 factory = new NoImplFactory(sb.toString());
             }
             return factory;
         }
     }
 
     protected Factory() {
     }

    
Gets an instance of FFIProvider

Returns:
an instance of FFIProvider
 
     public static final Factory getInstance() {
         return .;
     }
    
    
Registers FFI ruby classes/modules

Parameters:
module the module to register the classes under
 
     public void init(Ruby runtimeRubyModule ffi) {
         synchronized (ffi) {
             if (ffi.getClass("Type") == null) {
                 Type.createTypeClass(runtimeffi);
            }
            DataConverter.createDataConverterModule(runtimeffi);
            if (ffi.getClass(.) == null) {
                AbstractMemory.createAbstractMemoryClass(runtimeffi);
            }
            if (ffi.getClass("Buffer") == null) {
                Buffer.createBufferClass(runtimeffi);
            }
            if (ffi.getClass("Pointer") == null) {
                Pointer.createPointerClass(runtimeffi);
            }
            if (ffi.getClass("AutoPointer") == null) {
                AutoPointer.createAutoPointerClass(runtimeffi);
            }
            if (ffi.getClass("MemoryPointer") == null) {
                MemoryPointer.createMemoryPointerClass(runtimeffi);
            }
            if (ffi.getClass("Struct") == null) {
                Struct.createStructClass(runtimeffi);
            }
            if (ffi.getClass(.) == null) {
                StructLayout.createStructLayoutClass(runtimeffi);
            }
            if (ffi.getClass("StructByValue") == null) {
                StructByValue.createStructByValueClass(runtimeffi);
            }
            if (ffi.getClass(.) == null) {
                AbstractInvoker.createAbstractInvokerClass(runtimeffi);
            }
            if (ffi.getClass(.) == null) {
                CallbackInfo.createCallbackInfoClass(runtimeffi);
            }
            if (ffi.getClass("Enum") == null) {
                Enum.createEnumClass(runtimeffi);
            }
            if (ffi.getClass("Type").getClass("Mapped") == null) {
                MappedType.createConverterTypeClass(runtimeffi);
            }
            if (ffi.getClass(.) == null) {
                FileDescriptorIO.createFileDescriptorIOClass(runtimeffi);
            }
            ffi.setConstant("TypeDefs", RubyHash.newHash(runtime));
            Platform.createPlatformModule(runtimeffi);
            IOModule.createIOModule(runtimeffi);
            
            StructByReference.createStructByReferenceClass(runtimeffi);
        }
    }
    
    
Allocates memory on the native C heap and wraps it in a MemoryIO accessor.

Parameters:
size The number of bytes to allocate.
clear If the memory should be cleared.
Returns:
A new AllocatedDirectMemoryIO.
    public abstract MemoryIO allocateDirectMemory(Ruby runtimeint sizeboolean clear);

    
Allocates memory on the native C heap and wraps it in a MemoryIO accessor.

Parameters:
size The number of bytes to allocate.
align The minimum alignment of the memory
clear If the memory should be cleared.
Returns:
A new AllocatedDirectMemoryIO.
    public abstract MemoryIO allocateDirectMemory(Ruby runtimeint sizeint alignboolean clear);

    
Allocates transient native memory (not from C heap) and wraps it in a MemoryIO accessor.

Parameters:
size The number of bytes to allocate.
align The minimum alignment of the memory
clear If the memory should be cleared.
Returns:
A new AllocatedDirectMemoryIO.
    public abstract MemoryIO allocateTransientDirectMemory(Ruby runtimeint sizeint alignboolean clear);

    
Wraps a native C memory address in a MemoryIO accessor.

Parameters:
address The native address to wrap.
Returns:
A new MemoryIO.
    public abstract MemoryIO wrapDirectMemory(Ruby runtimelong address);
    public abstract CallbackManager getCallbackManager();
    public abstract AbstractInvoker newFunction(Ruby runtimePointer addressCallbackInfo cbInfo);
    public abstract int sizeOf(NativeType type);
    public abstract int alignmentOf(NativeType type);
New to GrepCode? Check out our FAQ X