public final class Natives extends Object
This class provides utility functions for working with the underlying native
bindings, creating NativeObject from pointers and extracting native
pointers from NativeObjects. It should normally only be necessary to make use
of these methods if extending the bindings externally or interacting with
other native code.
| Modifier and Type | Method and Description |
|---|---|
static <T extends NativeObject> |
callerOwnsReturn(org.freedesktop.gstreamer.lowlevel.GPointer ptr,
Class<T> cls)
Get a
NativeObject instance of the requested type for the
provided Pointer, for use with native functions returning
Transfer Full or Transfer Floating results. |
static <T extends NativeObject> |
callerOwnsReturn(com.sun.jna.Pointer ptr,
Class<T> cls)
Get a
NativeObject instance of the requested type for the
provided Pointer, for use with native functions returning
Transfer Full or Transfer Floating results. |
static org.freedesktop.gstreamer.lowlevel.GPointer |
getPointer(NativeObject obj)
Get the underlying native typed GPointer for a
NativeObject. |
static com.sun.jna.Pointer |
getRawPointer(NativeObject obj)
Get the underlying raw native Pointer for a
NativeObject. |
static NativeObject.Initializer |
initializer(com.sun.jna.Pointer ptr)
Create a
NativeObject.Initializer for the provided Pointer. |
static NativeObject.Initializer |
initializer(com.sun.jna.Pointer ptr,
boolean needRef)
Create a
NativeObject.Initializer for the provided Pointer. |
static NativeObject.Initializer |
initializer(com.sun.jna.Pointer ptr,
boolean needRef,
boolean ownsHandle)
Create a
NativeObject.Initializer for the provided Pointer. |
static <T extends NativeObject> |
objectFor(org.freedesktop.gstreamer.lowlevel.GPointer ptr,
Class<T> cls,
boolean needRef,
boolean ownsHandle)
Get a
NativeObject instance of the requested type for the
provided Pointer. |
static <T extends NativeObject> |
objectFor(com.sun.jna.Pointer ptr,
Class<T> cls,
boolean needRef,
boolean ownsHandle)
Get a
NativeObject instance of the requested type for the
provided Pointer. |
static boolean |
ownsReference(NativeObject obj)
Return whether underlying native pointer is owned by this object.
|
static <T extends RefCountedObject> |
ref(T obj)
Increase the reference count of a
RefCountedObject |
static <T extends NativeObject> |
registration(Class<T> javaType,
String gTypeName,
Function<NativeObject.Initializer,? extends T> factory)
Create a
NativeObject.TypeRegistration for linking
NativeObject subclasses to GTypes. |
static <T extends RefCountedObject> |
unref(T obj)
Decrease the reference count of a
RefCountedObject |
static boolean |
validReference(NativeObject obj)
Returns whether this object is valid or not.
|
public static final NativeObject.Initializer initializer(com.sun.jna.Pointer ptr)
NativeObject.Initializer for the provided Pointer.
This initializer will own the handle.
This initializer will not request a ref increase (only relevant if used
with instance of RefCountedObject)
ptr - native pointerpublic static final NativeObject.Initializer initializer(com.sun.jna.Pointer ptr, boolean needRef)
NativeObject.Initializer for the provided Pointer.
This initializer will own the handle.
ptr - native pointerneedRef - whether to request a ref increase (only relevant if used
with instance of RefCountedObject)public static final NativeObject.Initializer initializer(com.sun.jna.Pointer ptr, boolean needRef, boolean ownsHandle)
NativeObject.Initializer for the provided Pointer.ptr - native pointerneedRef - whether to request a ref increase (only relevant if used
with instance of RefCountedObject)ownsHandle - whether the NativeObject will own the handle, and
should dispose of the native resource when GC'd or explicitly disposed.public static <T extends NativeObject> T objectFor(com.sun.jna.Pointer ptr, Class<T> cls, boolean needRef, boolean ownsHandle)
NativeObject instance of the requested type for the
provided Pointer. Will return a cached instance if one already exists.T - NativeObject type to returnptr - native Pointercls - Class of type TneedRef - whether to request a ref increase (only relevant if T is
subclass of RefCountedObject)ownsHandle - whether the NativeObject will own the handle, and
should dispose of the native resource when GC'd or explicitly disposed.public static <T extends NativeObject> T objectFor(org.freedesktop.gstreamer.lowlevel.GPointer ptr, Class<T> cls, boolean needRef, boolean ownsHandle)
NativeObject instance of the requested type for the
provided Pointer. Will return a cached instance if one already exists.T - NativeObject type to returnptr - native Pointercls - Class of type TneedRef - whether to request a ref increase (only relevant if T is
subclass of RefCountedObject)ownsHandle - whether the NativeObject will own the handle, and
should dispose of the native resource when GC'd or explicitly disposed.public static <T extends NativeObject> T callerOwnsReturn(com.sun.jna.Pointer ptr, Class<T> cls)
NativeObject instance of the requested type for the
provided Pointer, for use with native functions returning
Transfer Full or Transfer Floating results.
This method will return a cached instance if one already exists. If the
cached instance is a RefCountedObject this method will release a
reference.
T - NativeObject type to returnptr - native Pointercls - Class of type Tpublic static <T extends NativeObject> T callerOwnsReturn(org.freedesktop.gstreamer.lowlevel.GPointer ptr, Class<T> cls)
NativeObject instance of the requested type for the
provided Pointer, for use with native functions returning
Transfer Full or Transfer Floating results.
This method will return a cached instance if one already exists. If the
cached instance is a RefCountedObject this method will release a
reference.
T - NativeObject type to returnptr - native Pointercls - Class of type Tpublic static com.sun.jna.Pointer getRawPointer(NativeObject obj)
NativeObject.obj - native objectIllegalStateException - if the native reference has been
invalidated or disposedpublic static org.freedesktop.gstreamer.lowlevel.GPointer getPointer(NativeObject obj)
NativeObject.obj - native objectIllegalStateException - if the native reference has been
invalidated or disposedpublic static boolean ownsReference(NativeObject obj)
obj - native object which may hold a reference to native pointerpublic static boolean validReference(NativeObject obj)
obj - native objectpublic static <T extends RefCountedObject> T ref(T obj)
RefCountedObjectT - type of objectobj - object to increase reference count onpublic static <T extends RefCountedObject> T unref(T obj)
RefCountedObjectT - type of objectobj - object to decrease reference count onpublic static <T extends NativeObject> NativeObject.TypeRegistration<T> registration(Class<T> javaType, String gTypeName, Function<NativeObject.Initializer,? extends T> factory)
NativeObject.TypeRegistration for linking
NativeObject subclasses to GTypes.
Be careful to respect the link between Java type hierarchy of registered
classes and the underlying GType hierarchy. eg. if the GType is a
subclass of GObject then the Java type must extend from GObject
The factory function should normally be a constructor reference.
Registrations can be provided externally using
NativeObject.TypeProvider instances registered for use with
ServiceLoader
T - Java typejavaType - Java type classgTypeName - name of the GTypefactory - a factory function to return an instance of T given a
NativeObject.Initializer. Normally a constructor reference -
T::newCopyright © 2021 gstreamer-java. All rights reserved.