001    /*
002     * To change this template, choose Tools | Templates
003     * and open the template in the editor.
004     */
005    
006    package org.bridj;
007    
008    import org.bridj.Pointer;
009    import org.bridj.ann.Runtime;
010    
011    /**
012     * Native C callback (beware : don't let your callbacks be GC'd before they're used).<br>
013     * To protect a callback against the GC, you can keep a reference to your callback or use {@link BridJ#protectFromGC(org.bridj.NativeObject) } / {@link BridJ#unprotectFromGC(org.bridj.NativeObject) }.<br>
014     * A callback is a Java object with only one abstract method exposed as a C function pointer to the native world.<br>
015     * Here's an example of callback definition (use JNAerator to generate them automatically) :
016     * <pre>{@code
017     *  // typedef int (*MyCallback)(int a, int b);
018     *  public static abstract class MyCallback extends Callback {
019                    public abstract int doSomething(int a, int b);
020            }
021     * }</pre>
022     * @author Olivier Chafik
023     */
024    @Runtime(CRuntime.class)
025    public abstract class Callback<C extends Callback<C>> extends NativeObject implements CallbackInterface {
026        public Pointer<C> toPointer() {
027                    return (Pointer)Pointer.pointerTo(this);
028            }
029    }