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

org.gnome.glib.Private 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.glib;

import io.github.jwharm.javagi.base.ManagedInstance;
import io.github.jwharm.javagi.interop.Interop;
import java.lang.Deprecated;
import java.lang.foreign.Arena;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;
import javax.annotation.processing.Generated;
import org.jetbrains.annotations.Nullable;

/**
 * The {@code GPrivate} struct is an opaque data structure to represent a
 * thread-local data key. It is approximately equivalent to the
 * pthread_setspecific()/pthread_getspecific() APIs on POSIX and to
 * TlsSetValue()/TlsGetValue() on Windows.
 * 

* If you don't already know why you might want this functionality, * then you probably don't need it. *

* {@code GPrivate} is a very limited resource (as far as 128 per program, * shared between all libraries). It is also not possible to destroy a * {@code GPrivate} after it has been used. As such, it is only ever acceptable * to use {@code GPrivate} in static scope, and even then sparingly so. *

* See G_PRIVATE_INIT() for a couple of examples. *

* The {@code GPrivate} structure should be considered opaque. It should only * be accessed via the g_private_ functions. */ @Generated("io.github.jwharm.JavaGI") public class Private extends ManagedInstance { static { GLib.javagi$ensureInitialized(); } /** * Create a Private proxy instance for the provided memory address. * * @param address the memory address of the native object */ public Private(MemorySegment address) { super(Interop.reinterpret(address, getMemoryLayout().byteSize())); } /** * Allocate a new Private. * * @param arena to control the memory allocation scope */ public Private(Arena arena) { super(arena.allocate(getMemoryLayout())); } /** * Allocate a new Private. * The memory is allocated with {@link Arena#ofAuto}. */ public Private() { super(Arena.ofAuto().allocate(getMemoryLayout())); } /** * Allocate a new Private with the fields set to the provided values. * * @param p value for the field {@code p} * @param notify value for the field {@code notify} * @param future value for the field {@code future} * @param arena to control the memory allocation scope */ public Private(MemorySegment p, DestroyNotify notify, MemorySegment[] future, Arena arena) { this(arena); writeP(p); writeNotify(notify, arena); writeFuture(future, arena); } /** * Allocate a new Private with the fields set to the provided values. * The memory is allocated with {@link Arena#ofAuto}. * * @param p value for the field {@code p} * @param notify value for the field {@code notify} * @param future value for the field {@code future} */ public Private(MemorySegment p, DestroyNotify notify, MemorySegment[] future) { this(Arena.ofAuto()); writeP(p); writeNotify(notify, Arena.ofAuto()); writeFuture(future, Arena.ofAuto()); } /** * The memory layout of the native struct. * @return the memory layout */ public static MemoryLayout getMemoryLayout() { return MemoryLayout.structLayout( ValueLayout.ADDRESS.withName("p"), ValueLayout.ADDRESS.withName("notify"), MemoryLayout.sequenceLayout(2, ValueLayout.ADDRESS).withName("future") ).withName("GPrivate"); } /** * Allocate a new Private. * * @param arena to control the memory allocation scope * @return a new, uninitialized {@link Private} * @deprecated Replaced by {@link Private#Private(Arena)} */ @Deprecated public static Private allocate(Arena arena) { MemorySegment segment = arena.allocate(getMemoryLayout()); return new Private(segment); } /** * Allocate a new Private with the fields set to the provided values. * * @param arena to control the memory allocation scope * @param p value for the field {@code p} * @param notify value for the field {@code notify} * @param future value for the field {@code future} * @return a new {@link Private} with the fields set to the provided values * @deprecated Replaced by {@link Private#Private(java.lang.foreign.MemorySegment, org.gnome.glib.DestroyNotify, java.lang.foreign.MemorySegment[], Arena)} */ @Deprecated public static Private allocate(Arena arena, MemorySegment p, DestroyNotify notify, MemorySegment[] future) { return new Private(p, notify, future, arena); } /** * Read the value of the field {@code p}. * * @return The value of the field {@code p} */ public MemorySegment readP() { var _result = (MemorySegment) getMemoryLayout() .varHandle(MemoryLayout.PathElement.groupElement("p")).get(handle()); return _result; } /** * Write a value in the field {@code p}. * * @param p The new value for the field {@code p} */ public void writeP(MemorySegment p) { getMemoryLayout().varHandle(MemoryLayout.PathElement.groupElement("p")) .set(handle(), (p == null ? MemorySegment.NULL : p)); } /** * Read the value of the field {@code notify}. * * @return The value of the field {@code notify} */ public DestroyNotify readNotify() { Arena _arena = Arena.ofAuto(); var _result = (MemorySegment) getMemoryLayout() .varHandle(MemoryLayout.PathElement.groupElement("notify")).get(handle()); return null /* Unsupported parameter type */; } /** * Write a value in the field {@code notify}. * * @param notify The new value for the field {@code notify} * @param _arena to control the memory allocation scope */ public void writeNotify(DestroyNotify notify, Arena _arena) { getMemoryLayout().varHandle(MemoryLayout.PathElement.groupElement("notify")) .set(handle(), (notify == null ? MemorySegment.NULL : notify.toCallback(_arena))); } /** * Read the value of the field {@code future}. * * @return The value of the field {@code future} */ public MemorySegment[] readFuture() { Arena _arena = Arena.ofAuto(); var _result = (MemorySegment) getMemoryLayout() .varHandle(MemoryLayout.PathElement.groupElement("future")).get(handle()); return Interop.getAddressArrayFrom(_result, 2, false); } /** * Write a value in the field {@code future}. * * @param future The new value for the field {@code future} * @param _arena to control the memory allocation scope */ public void writeFuture(MemorySegment[] future, Arena _arena) { getMemoryLayout().varHandle(MemoryLayout.PathElement.groupElement("future")) .set(handle(), (future == null ? MemorySegment.NULL : Interop.allocateNativeArray(future, false, _arena))); } /** * Returns the current value of the thread local variable {@code key}. *

* If the value has not yet been set in this thread, {@code null} is returned. * Values are never copied between threads (when a new thread is * created, for example). * @return the thread-local value */ public MemorySegment get() { MemorySegment _result; try { FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS); _result = (MemorySegment) Interop.downcallHandle("g_private_get", _fdesc, false) .invokeExact(handle()); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } return _result; } /** * Sets the thread local variable {@code key} to have the value {@code value} in the * current thread. *

* This function differs from g_private_set() in the following way: if * the previous value was non-{@code null} then the {@code GDestroyNotify} handler for * {@code key} is run on it. * @param value the new value */ public void replace(@Nullable MemorySegment value) { try { FunctionDescriptor _fdesc = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.ADDRESS); Interop.downcallHandle("g_private_replace", _fdesc, false).invokeExact(handle(), (MemorySegment) (value == null ? MemorySegment.NULL : value)); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } } /** * Sets the thread local variable {@code key} to have the value {@code value} in the * current thread. *

* This function differs from g_private_replace() in the following way: * the {@code GDestroyNotify} for {@code key} is not called on the old value. * @param value the new value */ public void set(@Nullable MemorySegment value) { try { FunctionDescriptor _fdesc = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.ADDRESS); Interop.downcallHandle("g_private_set", _fdesc, false).invokeExact(handle(), (MemorySegment) (value == null ? MemorySegment.NULL : value)); } catch (Throwable _err) { throw new AssertionError("Unexpected exception occurred: ", _err); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy