org.gnome.gobject.BindingTransformFunc Maven / Gradle / Ivy
// Java-GI - Java language bindings for GObject-Introspection-based libraries
// Copyright (C) 2022-2024 Jan-Willem Harmannij
//
// SPDX-License-Identifier: LGPL-2.1-or-later
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, see .
//
// This file has been generated with Java-GI.
// Do not edit this file directly!
// Visit for more information.
//
package org.gnome.gobject;
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 BindingTransformFunc} callback.
*/
@FunctionalInterface
@Generated("io.github.jwharm.JavaGI")
public interface BindingTransformFunc {
/**
* A function to be called to transform {@code from_value} to {@code to_value}.
*
* If this is the {@code transform_to} function of a binding, then {@code from_value}
* is the {@code source_property} on the {@code source} object, and {@code to_value} is the
* {@code target_property} on the {@code target} object. If this is the
* {@code transform_from} function of a {@link org.gnome.gobject.BindingFlags#BIDIRECTIONAL} binding,
* then those roles are reversed.
* @version 2.26
*/
boolean run(Binding binding, Value fromValue, Value toValue);
/**
* The {@code upcall} method is called from native code. The parameters
* are marshaled and {@link #run} is executed.
*/
default int upcall(MemorySegment binding, MemorySegment fromValue, MemorySegment toValue,
MemorySegment userData) {
Arena _arena = Arena.ofAuto();
var _result = run((Binding) InstanceCache.getForType(binding, org.gnome.gobject.Binding::new, false), MemorySegment.NULL.equals(fromValue) ? null : new Value(fromValue), MemorySegment.NULL.equals(toValue) ? null : new Value(toValue));
return _result ? 1 : 0;
}
/**
* Creates a native function pointer to the {@link #upcall} method.
*
* @return the native function pointer
*/
default MemorySegment toCallback(Arena arena) {
FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS,
ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS);
MethodHandle _handle = Interop.upcallHandle(MethodHandles.lookup(), BindingTransformFunc.class, _fdesc);
return Linker.nativeLinker().upcallStub(_handle.bindTo(this), _fdesc, arena);
}
}