001/* 002 * BridJ - Dynamic and blazing-fast native interop for Java. 003 * http://bridj.googlecode.com/ 004 * 005 * Copyright (c) 2010-2013, Olivier Chafik (http://ochafik.com/) 006 * All rights reserved. 007 * 008 * Redistribution and use in source and binary forms, with or without 009 * modification, are permitted provided that the following conditions are met: 010 * 011 * * Redistributions of source code must retain the above copyright 012 * notice, this list of conditions and the following disclaimer. 013 * * Redistributions in binary form must reproduce the above copyright 014 * notice, this list of conditions and the following disclaimer in the 015 * documentation and/or other materials provided with the distribution. 016 * * Neither the name of Olivier Chafik nor the 017 * names of its contributors may be used to endorse or promote products 018 * derived from this software without specific prior written permission. 019 * 020 * THIS SOFTWARE IS PROVIDED BY OLIVIER CHAFIK AND CONTRIBUTORS ``AS IS'' AND ANY 021 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 022 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 023 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 024 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 025 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 026 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 027 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 028 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 029 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 030 */ 031package org.bridj; 032 033import java.lang.reflect.Type; 034 035/** 036 * Interface that each specific pluggable native runtime must implement.<br> 037 * A runtime is attached to a class via the {@link org.bridj.ann.Runtime} 038 * annotation, so any runtime can be added in thirdparty libraries.<br> 039 * A runtime typically defines NativeObject subclasses and deals with their 040 * instances lifecycle through the type information metadata {@link TypeInfo} 041 * class.<br> 042 * 043 * @author ochafik 044 */ 045public interface BridJRuntime { 046 047 /** 048 * Type information metadata + lifecycle management methods.<br> 049 * This class is not meant to be used by end users, it's used by runtimes. 050 */ 051 public interface TypeInfo<T extends NativeObject> { 052 053 T cast(Pointer peer); 054 055 void initialize(T instance); 056 057 void initialize(T instance, Pointer peer); 058 059 void initialize(T instance, int constructorId, Object[] args); 060 061 void destroy(T instance); 062 063 T createReturnInstance(); 064 065 T clone(T instance) throws CloneNotSupportedException; 066 067 BridJRuntime getRuntime(); 068 069 Type getType(); 070 071 boolean equal(T instance, T other); 072 073 int compare(T instance, T other); 074 075 long sizeOf(); 076 077 void writeToNative(T instance); 078 079 String describe(T instance); 080 081 String describe(); 082 083 void readFromNative(T instance); 084 085 void copyNativeObjectToAddress(T instance, Pointer<T> ptr); 086 } 087 088 Type getType(NativeObject instance); 089 090 void register(Type type); 091 092 void unregister(Type type); 093 094 <T extends NativeObject> TypeInfo<T> getTypeInfo(final Type type); 095 096 Type getType(final Class<?> cls, Object[] targs, int[] typeParamCount); 097 098 boolean isAvailable(); 099 100 <T extends NativeObject> Class<? extends T> getActualInstanceClass(Pointer<T> pInstance, Type officialType); 101}