All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nextbreakpoint.freeimage4java.FI_InitProc Maven / Gradle / Ivy

// Generated by jextract

package com.nextbreakpoint.freeimage4java;

import java.lang.invoke.*;
import java.lang.foreign.*;
import java.nio.ByteOrder;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

import static java.lang.foreign.ValueLayout.*;
import static java.lang.foreign.MemoryLayout.PathElement.*;

/**
 * {@snippet lang=c :
 * typedef void (*FI_InitProc)(Plugin *, int)
 * }
 */
public class FI_InitProc {

    FI_InitProc() {
        // Should not be called directly
    }

    /**
     * The function pointer signature, expressed as a functional interface
     */
    public interface Function {
        void apply(MemorySegment plugin, int format_id);
    }

    private static final FunctionDescriptor $DESC = FunctionDescriptor.ofVoid(
        Libfreeimage.C_POINTER,
        Libfreeimage.C_INT
    );

    /**
     * The descriptor of this function pointer
     */
    public static FunctionDescriptor descriptor() {
        return $DESC;
    }

    private static final MethodHandle UP$MH = Libfreeimage.upcallHandle(FI_InitProc.Function.class, "apply", $DESC);

    /**
     * Allocates a new upcall stub, whose implementation is defined by {@code fi}.
     * The lifetime of the returned segment is managed by {@code arena}
     */
    public static MemorySegment allocate(FI_InitProc.Function fi, Arena arena) {
        return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena);
    }

    private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);

    /**
     * Invoke the upcall stub {@code funcPtr}, with given parameters
     */
    public static void invoke(MemorySegment funcPtr,MemorySegment plugin, int format_id) {
        try {
             DOWN$MH.invokeExact(funcPtr, plugin, format_id);
        } catch (Throwable ex$) {
            throw new AssertionError("should not reach here", ex$);
        }
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy