Package org.javagi.gobject
Class InstanceCache
java.lang.Object
org.javagi.gobject.InstanceCache
Caches TypeInstances so the same instance is used for the same memory
address.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable ProxygetForType(MemorySegment address, Function<MemorySegment, ? extends Proxy> fallback) Get aProxyobject for the provided native memory address.static @Nullable ProxygetForTypeClass(@Nullable MemorySegment address, Function<MemorySegment, ? extends Proxy> fallback) Get aProxyobject for the provided native memory address of a TypeClass.static voidnewGObject(GObject proxy, @Nullable Type objectType, long size, @Nullable Object @Nullable ... properties) Construct a new GObject instance and set the provided Java proxy to its address.static Proxyput(MemorySegment address, GObject object) Add the new GObject instance to the cache.static intremoveToggleRef(MemorySegment address)
-
Field Details
-
REMOVE_TOGGLE_REF
-
-
Constructor Details
-
InstanceCache
public InstanceCache()
-
-
Method Details
-
getForType
public static @Nullable Proxy getForType(MemorySegment address, Function<MemorySegment, ? extends Proxy> fallback) Get aProxyobject for the provided native memory address. If a Proxy object does not yet exist for this address, a new Proxy object is instantiated and added to the cache. The type of the Proxy object is read from the gtype field of the native instance. Invalid references are removed from the cache using a GObject toggle reference.- Parameters:
address- memory address of the native objectfallback- fallback constructor to use when the type is not found in the TypeCache- Returns:
- a Proxy instance for the provided memory address
-
getForTypeClass
public static @Nullable Proxy getForTypeClass(@Nullable MemorySegment address, Function<MemorySegment, ? extends Proxy> fallback) Get aProxyobject for the provided native memory address of a TypeClass. The type of the Proxy object is read from the gtype field of the native TypeClass.- Parameters:
address- memory address of the native objectfallback- fallback constructor to use when the type is not found in the TypeCache- Returns:
- a Proxy instance for the provided memory address
-
put
Add the new GObject instance to the cache. Floating references are sunk, and a toggle reference is installed.- Parameters:
address- the memory address of the native instanceobject- the GObject instance- Returns:
- the cached GObject instance
-
newGObject
public static void newGObject(GObject proxy, @Nullable Type objectType, long size, @Nullable Object @Nullable ... properties) Construct a new GObject instance and set the provided Java proxy to its address.- Parameters:
proxy- the Java Proxy for the newly constructed GObject instanceobjectType- the GType, ifnullit will be queried from the TypeCachesize- the size of the native instanceproperties- pairs of property names and values (optional). A trailingnullwill be added automatically.
-
removeToggleRef
-