Monado OpenXR Runtime
org.freedesktop.monado.auxiliary.NativeCounterpart Class Reference

Object that tracks the native counterpart object for a type. More...

Public Member Functions

 NativeCounterpart (long nativePointer) throws InvalidParameterException
 Constructor. More...
 
void markAsUsedByNativeCode ()
 Set the flag to indicate that native code is using this. More...
 
void markAsDiscardedByNative (String TAG)
 Change the flag and notify those waiting on it, to indicate that native code is done with this object. More...
 
long getNativePointer ()
 Retrieve the native pointer value. More...
 
boolean blockUntilNativeDiscard (@NonNull String TAG)
 Wait until markAsDiscardedByNative has been called indicating that the native code is done with this. More...
 

Detailed Description

Object that tracks the native counterpart object for a type.

Must be initialized on construction, and may have its native code destroyed/discarded, but may not "re-seat" it to new native code pointer.

Use as a member of any type with a native counterpart (a native-allocated-and-owned object that holds a reference to the owning class). Include the following field and delegating method to use (note: assumes you have a tag for logging purposes as TAG)

private final NativeCounterpart nativeCounterpart;

@Keep
public void markAsDiscardedByNative() {
    nativeCounterpart.markAsDiscardedByNative(TAG);
}

Then, initialize it in your constructor, call markAsUsedByNativeCode() where desired (often in your constructor), and call getNativePointer() and
blockUntilNativeDiscard()
as needed.

Your native code can use this to turn a void* into a jlong: static_cast<long
long>(reinterpret_cast<intptr_t>(nativePointer))

Constructor & Destructor Documentation

◆ NativeCounterpart()

org.freedesktop.monado.auxiliary.NativeCounterpart.NativeCounterpart ( long  nativePointer) throws InvalidParameterException
inline

Constructor.

Parameters
nativePointerThe native pointer, cast appropriately. Must be non-zero. Can cast like: static_cast<long long>(reinterpret_cast<intptr_t>(nativePointer))

Member Function Documentation

◆ blockUntilNativeDiscard()

boolean org.freedesktop.monado.auxiliary.NativeCounterpart.blockUntilNativeDiscard ( @NonNull String  TAG)
inline

Wait until markAsDiscardedByNative has been called indicating that the native code is done with this.

Be sure to check the result!

Parameters
TAGYour owning class's logging tag
Returns
true if this class has successfully been discarded by native.

◆ getNativePointer()

long org.freedesktop.monado.auxiliary.NativeCounterpart.getNativePointer ( )
inline

Retrieve the native pointer value.

Will be 0 if discarded by native code!.

Returns
pointer (cast as a long)

◆ markAsDiscardedByNative()

void org.freedesktop.monado.auxiliary.NativeCounterpart.markAsDiscardedByNative ( String  TAG)
inline

Change the flag and notify those waiting on it, to indicate that native code is done with this object.

Parameters
TAGYour owning class's logging tag

Referenced by org.freedesktop.monado.auxiliary.MonadoView.markAsDiscardedByNative(), and org.freedesktop.monado.ipc.Client.markAsDiscardedByNative().

◆ markAsUsedByNativeCode()

void org.freedesktop.monado.auxiliary.NativeCounterpart.markAsUsedByNativeCode ( )
inline

Set the flag to indicate that native code is using this.

Only call this once, probably in your constructor unless you have a good reason to call it elsewhere.

Referenced by org.freedesktop.monado.ipc.Client.Client(), and org.freedesktop.monado.auxiliary.MonadoView.waitGetSurfaceHolder().


The documentation for this class was generated from the following file: