001    package org.bridj;
002    
003    import java.lang.reflect.Type;
004    
005    /**
006     * Interface that each specific pluggable native runtime must implement.<br>
007     * A runtime is attached to a class via the {@link org.bridj.ann.Runtime} annotation, so any runtime can be added in thirdparty libraries.<br>
008     * A runtime typically defines NativeObject subclasses and deals with their instances lifecycle through the type information metadata {@link TypeInfo} class.<br>
009     * @author ochafik
010     */
011    public interface BridJRuntime {
012    
013            /**
014         * Type information metadata + lifecycle management methods.<br>
015         * This class is not meant to be used by end users, it's used by runtimes.
016         */
017            public interface TypeInfo<T extends NativeObject> {
018                    T cast(Pointer peer);
019                    void initialize(T instance);
020                    void initialize(T instance, Pointer peer);
021                    void initialize(T instance, int constructorId, Object[] args);
022            void destroy(T instance);
023                    T createReturnInstance();
024            T clone(T instance) throws CloneNotSupportedException;
025                    BridJRuntime getRuntime();
026                    Type getType();
027    
028                    boolean equal(T instance, T other);
029                    int compare(T instance, T other);
030            long sizeOf();
031            void writeToNative(T instance);
032            String describe(T instance);
033            String describe();
034            void readFromNative(T instance);
035            void copyNativeObjectToAddress(T instance, Pointer<T> ptr);
036            }
037            Type getType(NativeObject instance);
038    
039            void register(Type type);
040            void unregister(Type type);
041            <T extends NativeObject> TypeInfo<T> getTypeInfo(final Type type);
042    
043        boolean isAvailable();
044            <T extends NativeObject> Class<? extends T> getActualInstanceClass(Pointer<T> pInstance, Type officialType);
045        
046    }