org.gnome.gobject.InstanceInitFunc Maven / Gradle / Ivy
Show all versions of gobject Show documentation
// This file was automatically generated by Java-GI. Do not edit this file
// directly! Visit for more information.
//
// The API documentation in this file was derived from GObject-Introspection
// metadata and may include text or comments from the original C sources.
//
// Copyright (c), upstream authors as identified in the GObject-Introspection
// metadata.
//
// This generated file is distributed under the same license as the original
// GObject-Introspection data, unless otherwise specified. Users of this file
// are responsible for complying with any licenses or terms required by the
// original authors.
//
// THIS FILE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT.
//
package org.gnome.gobject;
import io.github.jwharm.javagi.base.FunctionPointer;
import io.github.jwharm.javagi.gobject.InstanceCache;
import io.github.jwharm.javagi.interop.Interop;
import java.lang.FunctionalInterface;
import java.lang.foreign.Arena;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.Linker;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import javax.annotation.processing.Generated;
/**
* Functional interface declaration of the {@code InstanceInitFunc} callback.
*
* @see InstanceInitFunc#run
*/
@FunctionalInterface
@Generated("io.github.jwharm.JavaGI")
public interface InstanceInitFunc extends FunctionPointer {
/**
* A callback function used by the type system to initialize a new
* instance of a type.
*
* This function initializes all instance members and allocates any resources
* required by it.
*
* Initialization of a derived instance involves calling all its parent
* types instance initializers, so the class member of the instance
* is altered during its initialization to always point to the class that
* belongs to the type the current initializer was introduced for.
*
* The extended members of {@code instance} are guaranteed to have been filled with
* zeros before this function is called.
*/
void run(TypeInstance instance, TypeClass gClass);
/**
* The {@code upcall} method is called from native code. The parameters
* are marshaled and {@link #run} is executed.
*/
default void upcall(MemorySegment instance, MemorySegment gClass) {
Arena _arena = Arena.ofAuto();
run(MemorySegment.NULL.equals(instance) ? null : new TypeInstance(instance), (TypeClass) InstanceCache.getForTypeClass(gClass, TypeClass::new, false));
}
/**
* Creates a native function pointer to the {@link #upcall} method.
*
* @return the native function pointer
*/
default MemorySegment toCallback(Arena arena) {
FunctionDescriptor _fdesc = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS,
ValueLayout.ADDRESS);
MethodHandle _handle = Interop.upcallHandle(MethodHandles.lookup(), InstanceInitFunc.class, _fdesc);
return Linker.nativeLinker().upcallStub(_handle.bindTo(this), _fdesc, arena);
}
}