GlueGen: com.jogamp.gluegen.CCodeUnit Class Reference

GlueGen v2.6.0-rc-20250722 GlueGen, Native Binding Generator for Java™ (public API).

Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
com.jogamp.gluegen.CCodeUnit Class Reference

C code unit (a generated C source file), covering multiple `FunctionEmitter` allowing to unify output, decoration and dynamic helper code injection per unit. More...

Inheritance diagram for com.jogamp.gluegen.CCodeUnit:
Collaboration diagram for com.jogamp.gluegen.CCodeUnit:

## Public Member Functions

| CCodeUnit (final String filename, final String cUnitName, final Object generator) throws IOException
void | emitHeader (final String packageName, final String className, final List< String > customCode)
void | emitJNIEnvDecl ()
| Emits `getJNIEnvDecl()`. More...
void | emitJNIOnLoadJNIEnvCode (final String libraryBasename)
| Emits `getJNIOnLoadJNIEnvCode(String)`. More...
String | toString ()
Public Member Functions inherited from com.jogamp.gluegen.CodeUnit
boolean | addTailCode (final String c)
| Add a tail code to this unit. More...
void | emitln ()
void | emitln (final String s)
void | emit (final String s)
void | emitf (final String s, final Object... args)
void | emitTailCode ()
void | close ()
String | toString ()

## Static Public Member Functions

static final String | getJNIEnvDecl ()
| Returns native JNI declarations for `JVMUtil_GetJavaVM()`, `JVMUtil_GetJNIEnv(..)` and `JVMUtil_ReleaseJNIEnv(..)`. More...
static final String | getJNIOnLoadJNIEnvCode (final String libraryBasename)
| Returns native JNI code `JNI_OnLoad(..)` used for dynamic libraries, `JNI_OnLoad_{libraryBasename}(..)` used for static libraries, `JVMUtil_GetJNIEnv(..)` etc. More...

## Public Attributes

final String | cUnitName
| base c-unit name with suffix. More...
Public Attributes inherited from com.jogamp.gluegen.CodeUnit
final String | filename
final PrintWriter | output

## Static Public Attributes

static final String | NewDirectByteBufferCopyUnitCode

## Additional Inherited Members

Protected Member Functions inherited from com.jogamp.gluegen.CodeUnit
| CodeUnit (final String filename, final Object generator) throws IOException

## Detailed Description

C code unit (a generated C source file), covering multiple `FunctionEmitter` allowing to unify output, decoration and dynamic helper code injection per unit.

Definition at line 37 of file CCodeUnit.java.

## Constructor & Destructor Documentation

## ◆ CCodeUnit()

com.jogamp.gluegen.CCodeUnit.CCodeUnit | ( | final String | filename,
|  | final String | cUnitName,
|  | final Object | generator
| ) |  | throws IOException

Parameters

  filename | the class's full filename to open w/ write access
  cUnitName | the base c-unit name, i.e. c-file basename with suffix
  generator | informal optional object that is creating this unit, used to be mentioned in a warning message if not null.

Exceptions

  IOException |

Definition at line 47 of file CCodeUnit.java.

Here is the call graph for this function:

## Member Function Documentation

## ◆ emitHeader()

void com.jogamp.gluegen.CCodeUnit.emitHeader | ( | final String | packageName,
|  | final String | className,
|  | final List< String > | customCode
| ) |  |

Definition at line 53 of file CCodeUnit.java.

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ emitJNIEnvDecl()

void com.jogamp.gluegen.CCodeUnit.emitJNIEnvDecl | ( |  | ) |

Emits `getJNIEnvDecl()`.

Definition at line 77 of file CCodeUnit.java.

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ emitJNIOnLoadJNIEnvCode()

void com.jogamp.gluegen.CCodeUnit.emitJNIOnLoadJNIEnvCode | ( | final String | libraryBasename | ) |

Emits `getJNIOnLoadJNIEnvCode(String)`.

Definition at line 82 of file CCodeUnit.java.

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ getJNIEnvDecl()

static final String com.jogamp.gluegen.CCodeUnit.getJNIEnvDecl | ( |  | ) |

static

Returns native JNI declarations for `JVMUtil_GetJavaVM()`, `JVMUtil_GetJNIEnv(..)` and `JVMUtil_ReleaseJNIEnv(..)`.

See `getJNIOnLoadJNIEnvCode(String)` for details.

Returns
  the code

See also
  getJNIOnLoadJNIEnvCode(String)

Definition at line 118 of file CCodeUnit.java.

Here is the caller graph for this function:

## ◆ getJNIOnLoadJNIEnvCode()

static final String com.jogamp.gluegen.CCodeUnit.getJNIOnLoadJNIEnvCode | ( | final String | libraryBasename | ) |

static

Returns native JNI code `JNI_OnLoad(..)` used for dynamic libraries, `JNI_OnLoad_{libraryBasename}(..)` used for static libraries, `JVMUtil_GetJNIEnv(..)` etc.

The `JNI_OnLoad*(..)` methods set a `static JavaVM* {libraryBasename}_jvmHandle`, which in turn is utilized by `JVMUtil_GetJNIEnv(..)` to attach a new thread to the `JavaVM*` generating a new `JNIEnv*`- or just to retrieve the thread's `JNIEnv*`, if already attached to the `JavaVM*`.

Parameters

  libraryBasename | library basename to generate the `JNI_OnLoad_{libraryBasename}(..)` variant for statically linked libraries.

Returns
  the code

See also
  #getJNIOnLoadJNIEnvDecl(String)

Definition at line 137 of file CCodeUnit.java.

Here is the caller graph for this function:

## ◆ toString()

String com.jogamp.gluegen.CCodeUnit.toString | ( |  | ) |

Reimplemented from com.jogamp.gluegen.CodeUnit.

Definition at line 87 of file CCodeUnit.java.

## Member Data Documentation

## ◆ cUnitName

final String com.jogamp.gluegen.CCodeUnit.cUnitName

base c-unit name with suffix.

Definition at line 39 of file CCodeUnit.java.

## ◆ NewDirectByteBufferCopyUnitCode

final String com.jogamp.gluegen.CCodeUnit.NewDirectByteBufferCopyUnitCode

static

Initial value:
=
"static const char * nameCopyNativeToDirectByteBuffer = \"copyNativeToDirectByteBuffer\";\n"+
"static const char * nameCopyNativeToDirectByteBufferSignature = \"(JJ)Ljava/nio/ByteBuffer;\";\n"+
"\n"+
"static jobject JVMUtil_NewDirectByteBufferCopy(JNIEnv *env, jclass clazzBuffers, void * source_address, size_t capacity) {\n"+
" jmethodID cstrBuffersNew = (*env)->GetStaticMethodID(env, clazzBuffers, nameCopyNativeToDirectByteBuffer, nameCopyNativeToDirectByteBufferSignature);\n"+
" if(NULL==cstrBuffersNew) {\n"+
" fprintf(stderr, \"Can't get method Buffers.%s(%s)\\n\", nameCopyNativeToDirectByteBuffer, nameCopyNativeToDirectByteBufferSignature);\n"+
" (*env)->FatalError(env, nameCopyNativeToDirectByteBuffer);\n"+
" return JNI_FALSE;\n"+
" }\n"+
" jobject jbyteBuffer = (*env)->CallStaticObjectMethod(env, clazzBuffers, cstrBuffersNew, (jlong)(intptr_t)source_address, (jlong)capacity);\n"+
" if( (*env)->ExceptionCheck(env) ) {\n"+
" (*env)->ExceptionDescribe(env);\n"+
" (*env)->ExceptionClear(env);\n"+
" (*env)->FatalError(env, \"Exception occurred\");\n"+
" return NULL;\n"+
" }\n"+
" return jbyteBuffer;\n"+
"}\n"

Definition at line 89 of file CCodeUnit.java.

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

- src/java/com/jogamp/gluegen/CCodeUnit.java