Top Description Inners Fields Constructors Methods
com.jogamp.gluegen

public Class CMethodBindingEmitter

extends FunctionEmitter
Class Inheritance
Known Direct Subclasses
com.jogamp.gluegen.procaddress.ProcAddressCMethodBindingEmitter
Imports
java.util.*, java.io.*, java.text.MessageFormat, com.jogamp.common.os.MachineDataInfo, com.jogamp.gluegen.Logging.LoggerIf, com.jogamp.gluegen.cgram.types.*

Emits the C-side component of the Java<->C JNI binding.

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
CMethodBindingEmitter.DefaultCommentEmitter

Class that emits a generic comment for CMethodBindingEmitters; the comment includes the C signature of the native method that is being bound by the emitter java method.

Field Summary

Modifier and TypeField and Description
protected static final String
protected static final String
protected static final String
protected MethodBinding
private final String
className

Name of the class in which the corresponding Java method resides.

protected static final CommentEmitter
protected boolean
protected boolean
private boolean
private final boolean
isJavaMethodStatic

Whether or not the Java-side of the Java<->C JNI binding for this emitter's MethodBinding is static.

private final boolean
isOverloadedBinding

Whether or not the Java<->C JNI binding for this emitter's MethodBinding is overloaded.

protected final Logging.LoggerIf
protected MachineDataInfo
private final String
packageName

Name of the package in which the corresponding Java method resides.

private MessageFormat
returnValueCapacityExpression

Capacity of the return value in the event that it is encapsulated in a java.nio.Buffer.

private MessageFormat
returnValueLengthExpression

Length of the returned array.

protected static final String
private List<String>
temporaryCVariableAssignments

Optional List of Strings containing assignments to temporary C variables to make after the call is completed.

private List<String>
temporaryCVariableDeclarations

Optional List of Strings containing temporary C variables to declare.

Inherited from com.jogamp.gluegen.FunctionEmitter:
cfgSTATIC

Constructor Summary

AccessConstructor and Description
public
CMethodBindingEmitter(final MethodBinding binding, final PrintWriter output, final String javaPackageName, final String javaClassName, final boolean isOverloadedBinding, final boolean isJavaMethodStatic, final boolean forImplementingMethodCall, final boolean forIndirectBufferAndArrayImplementation, final MachineDataInfo machDesc, final JavaConfiguration configuration)

Constructs an emitter for the specified binding, and sets a default comment emitter that will emit the signature of the C function that is being bound.

Method Summary

Modifier and TypeMethod and Description
protected String[]
protected String
byteOffsetArgName(final int i)

protected String
protected static String
protected int
emitArguments(final PrintWriter writer)

Implements abstract com.jogamp.gluegen.FunctionEmitter.emitArguments.

Returns the number of arguments emitted.
protected void
protected void
protected int
emitBodyPassCArguments(final PrintWriter writer)

Returns the number of arguments passed so calling code knows whether to print a comma

protected void
protected void
emitBodyUserVariableAssignments(final PrintWriter writer)

Emits the user-defined C variable assignments from the TemporaryCVariableAssignments directive in the .cfg file.

protected void
emitBodyUserVariableDeclarations(final PrintWriter writer)

Emits the user-defined C variable declarations from the TemporaryCVariableDeclarations directive in the .cfg file.

protected void
protected void
emitBodyVariablePostCallCleanup(final PrintWriter writer)

Code to clean up any variables that were declared in emitBodyVariableDeclarations(), AFTER calling the actual C function.

protected void
emitBodyVariablePreCallSetup(final PrintWriter writer)

Code to init the variables that were declared in emitBodyVariableDeclarations(), PRIOR TO calling the actual C function.

private void
emitCalloc(final PrintWriter writer, final String targetVarName, final String elementTypeString, final String numElementsExpression, final String mallocFailureErrorString)

private void
emitGetDirectBufferAddress(final PrintWriter writer, final String sourceVarName, final String receivingVarTypeString, final String receivingVarName, final boolean receivingIsPtrPtr, final String byteOffsetVarName, final boolean emitElseClause)

private void
emitGetStringChars(final PrintWriter writer, final String sourceVarName, final String receivingVarName, final boolean isUTF8, final boolean emitElseClause)

private void
emitMalloc(final PrintWriter writer, final String targetVarName, final String elementTypeString, final boolean elementTypeIsConst, final String numElementsExpression, final String mallocFailureErrorString)

protected void
private void
emitOutOfMemoryCheck(final PrintWriter writer, final String varName, final String errorMessage)

private void
emitPointerConversion(final PrintWriter writer, final MethodBinding binding, final JavaType type, final Type cType, final String incomingArgumentName, final String cVariableName, String byteOffsetVarName)

private boolean
emitPointerDeclaration(final PrintWriter writer, final JavaType javaType, final Type cType, final String cVariableName, final String javaArgumentName)

private void
emitReturnDirectBufferAddress(final PrintWriter writer, final String sourceVarName, final String receivingVarTypeString, final String receivingVarName, final boolean receivingIsPtrPtr, final String byteOffsetVarName)

protected void
public final boolean
forIndirectBufferAndArrayImplementation()

Is this CMethodBindingEmitter implementing the case of an indirect buffer or array being passed down to C code?

public final MethodBinding
public FunctionSymbol
public String
protected String
public String
public final boolean
getIsJavaMethodStatic()

Is the Java side of the Java<->C JNI binding for this emitter's MethodBinding a static method?.

public final boolean
getIsOverloadedBinding()

Is the Java<->C JNI binding for this emitter's MethodBinding one of several overloaded methods with the same name?

public String
getJavaClassName()

Get the name of the package in which the corresponding Java method resides.

public String
getJavaPackageName()

Get the name of the class in which the corresponding Java method resides.

public final MachineDataInfo
getMachineDataInfo()

Used for certain internal type size computations

public String
public final MessageFormat
getReturnValueCapacityExpression()

Get the expression for the capacity of the returned java.nio.Buffer.

public final MessageFormat
getReturnValueLengthExpression()

Get the expression for the length of the returned array

public final List<String>
getTemporaryCVariableAssignments()

Returns the List of Strings containing assignments for temporary C variables which are made after the underlying function call.

public final List<String>
getTemporaryCVariableDeclarations()

Returns the List of Strings containing declarations for temporary C variables to be assigned to after the underlying function call.

protected String
isNIOArgName(final int i)

protected String
protected boolean
isUTF8Type(Type type)

Checks a type to see whether it is for a UTF-8 pointer type (i.e., "const char *", "const char **").

protected boolean
protected String
jniMangle(final MethodBinding binding)

protected void
jniMangle(final Class<?> c, final StringBuilder res, final boolean syntheticArgument)

protected String
protected void
setIsCStructFunctionPointer(final boolean v)

If method originates from a struct, see MethodBinding#hasContainingType(), it can either purposed to call a native static function (default) or a struct's function pointer.

public final void
setReturnValueCapacityExpression(final MessageFormat
a MessageFormat which, when applied to an array of type String[] that contains each of the arguments names of the Java-side binding, returns an expression that will (when compiled by a C compiler) evaluate to an integer-valued expression. The value of this expression is the capacity of the java.nio.Buffer returned from this method.
expression
)

If this function returns a void* encapsulated in a java.nio.Buffer (or compound type wrapper), sets the expression for the capacity of the returned Buffer.

public final void
setReturnValueLengthExpression(final MessageFormat
a MessageFormat which, when applied to an array of type String[] that contains each of the arguments names of the Java-side binding, returns an expression that will (when compiled by a C compiler) evaluate to an integer-valued expression. The value of this expression is the length of the array returned from this method.
expression
)

If this function returns an array, sets the expression for the length of the returned array.

public final void
setTemporaryCVariableAssignments(final List<String> arg)

Sets up a List of Strings containing assignments for temporary C variables which are made after the underlying function call.

public final void
setTemporaryCVariableDeclarations(final List<String> arg)

Sets up a List of Strings containing declarations for temporary C variables to be assigned to after the underlying function call.

Inherited from com.jogamp.gluegen.FunctionEmitter:
addModifieraddModifiersclearModifiersemitemitemitDocCommentemitModifiersemitSignaturegetBaseIndentStringgetCommentEmittergetCommentEndStringgetCommentStartStringgetDefaultOutputgetModifiershasModifierisInterfaceremoveModifiersetCommentEmittertoString

Field Detail

arrayIdxback to summary
protected static final String arrayIdx
arrayResback to summary
protected static final String arrayRes
arrayResLengthback to summary
protected static final String arrayResLength
bindingback to summary
protected MethodBinding binding
classNameback to summary
private final String className

Name of the class in which the corresponding Java method resides.

defaultCommentEmitterback to summary
protected static final CommentEmitter defaultCommentEmitter
forImplementingMethodCallback to summary
protected boolean forImplementingMethodCall
forIndirectBufferAndArrayImplementationback to summary
protected boolean forIndirectBufferAndArrayImplementation
isCStructFunctionPointerback to summary
private boolean isCStructFunctionPointer
isJavaMethodStaticback to summary
private final boolean isJavaMethodStatic

Whether or not the Java-side of the Java<->C JNI binding for this emitter's MethodBinding is static.

isOverloadedBindingback to summary
private final boolean isOverloadedBinding

Whether or not the Java<->C JNI binding for this emitter's MethodBinding is overloaded.

LOGback to summary
protected final Logging.LoggerIf LOG
machDescback to summary
protected MachineDataInfo machDesc
packageNameback to summary
private final String packageName

Name of the package in which the corresponding Java method resides.

returnValueCapacityExpressionback to summary
private MessageFormat returnValueCapacityExpression

Capacity of the return value in the event that it is encapsulated in a java.nio.Buffer. Is ignored if binding.getJavaReturnType().isNIOBuffer() == false;

returnValueLengthExpressionback to summary
private MessageFormat returnValueLengthExpression

Length of the returned array. Is ignored if binding.getJavaReturnType().isArray() is false.

STRING_CHARS_PREFIXback to summary
protected static final String STRING_CHARS_PREFIX
temporaryCVariableAssignmentsback to summary
private List<String> temporaryCVariableAssignments

Optional List of Strings containing assignments to temporary C variables to make after the call is completed.

temporaryCVariableDeclarationsback to summary
private List<String> temporaryCVariableDeclarations

Optional List of Strings containing temporary C variables to declare.

Constructor Detail

CMethodBindingEmitterback to summary
public CMethodBindingEmitter(final MethodBinding binding, final PrintWriter output, final String javaPackageName, final String javaClassName, final boolean isOverloadedBinding, final boolean isJavaMethodStatic, final boolean forImplementingMethodCall, final boolean forIndirectBufferAndArrayImplementation, final MachineDataInfo machDesc, final JavaConfiguration configuration)

Constructs an emitter for the specified binding, and sets a default comment emitter that will emit the signature of the C function that is being bound.

Method Detail

argumentNameArrayback to summary
protected String[] argumentNameArray()
byteOffsetArgNameback to summary
protected String byteOffsetArgName(final int i)
byteOffsetArrayArgNameback to summary
protected String byteOffsetArrayArgName(final int i)
cThisArgumentNameback to summary
protected static String cThisArgumentName()
emitArgumentsback to summary
protected int emitArguments(final PrintWriter writer)

Implements abstract com.jogamp.gluegen.FunctionEmitter.emitArguments.

Doc from com.jogamp.gluegen.FunctionEmitter.emitArguments.

Returns the number of arguments emitted.

Annotations
@Override
emitBodyback to summary
protected void emitBody(final PrintWriter writer)

Implements abstract com.jogamp.gluegen.FunctionEmitter.emitBody.

Annotations
@Override
emitBodyCallCFunctionback to summary
protected void emitBodyCallCFunction(final PrintWriter writer)
emitBodyPassCArgumentsback to summary
protected int emitBodyPassCArguments(final PrintWriter writer)

Returns the number of arguments passed so calling code knows whether to print a comma

emitBodyReturnResultback to summary
protected void emitBodyReturnResult(final PrintWriter writer)
emitBodyUserVariableAssignmentsback to summary
protected void emitBodyUserVariableAssignments(final PrintWriter writer)

Emits the user-defined C variable assignments from the TemporaryCVariableAssignments directive in the .cfg file.

emitBodyUserVariableDeclarationsback to summary
protected void emitBodyUserVariableDeclarations(final PrintWriter writer)

Emits the user-defined C variable declarations from the TemporaryCVariableDeclarations directive in the .cfg file.

emitBodyVariableDeclarationsback to summary
protected void emitBodyVariableDeclarations(final PrintWriter writer)
emitBodyVariablePostCallCleanupback to summary
protected void emitBodyVariablePostCallCleanup(final PrintWriter writer)

Code to clean up any variables that were declared in emitBodyVariableDeclarations(), AFTER calling the actual C function.

emitBodyVariablePreCallSetupback to summary
protected void emitBodyVariablePreCallSetup(final PrintWriter writer)

Code to init the variables that were declared in emitBodyVariableDeclarations(), PRIOR TO calling the actual C function.

emitCallocback to summary
private void emitCalloc(final PrintWriter writer, final String targetVarName, final String elementTypeString, final String numElementsExpression, final String mallocFailureErrorString)
emitGetDirectBufferAddressback to summary
private void emitGetDirectBufferAddress(final PrintWriter writer, final String sourceVarName, final String receivingVarTypeString, final String receivingVarName, final boolean receivingIsPtrPtr, final String byteOffsetVarName, final boolean emitElseClause)
emitGetStringCharsback to summary
private void emitGetStringChars(final PrintWriter writer, final String sourceVarName, final String receivingVarName, final boolean isUTF8, final boolean emitElseClause)
emitMallocback to summary
private void emitMalloc(final PrintWriter writer, final String targetVarName, final String elementTypeString, final boolean elementTypeIsConst, final String numElementsExpression, final String mallocFailureErrorString)
emitNameback to summary
protected void emitName(final PrintWriter writer)

Implements abstract com.jogamp.gluegen.FunctionEmitter.emitName.

Annotations
@Override
emitOutOfMemoryCheckback to summary
private void emitOutOfMemoryCheck(final PrintWriter writer, final String varName, final String errorMessage)
emitPointerConversionback to summary
private void emitPointerConversion(final PrintWriter writer, final MethodBinding binding, final JavaType type, final Type cType, final String incomingArgumentName, final String cVariableName, String byteOffsetVarName)
emitPointerDeclarationback to summary
private boolean emitPointerDeclaration(final PrintWriter writer, final JavaType javaType, final Type cType, final String cVariableName, final String javaArgumentName)
emitReturnDirectBufferAddressback to summary
private void emitReturnDirectBufferAddress(final PrintWriter writer, final String sourceVarName, final String receivingVarTypeString, final String receivingVarName, final boolean receivingIsPtrPtr, final String byteOffsetVarName)
emitReturnTypeback to summary
protected void emitReturnType(final PrintWriter writer)

Implements abstract com.jogamp.gluegen.FunctionEmitter.emitReturnType.

Annotations
@Override
forIndirectBufferAndArrayImplementationback to summary
public final boolean forIndirectBufferAndArrayImplementation()

Is this CMethodBindingEmitter implementing the case of an indirect buffer or array being passed down to C code?

getBindingback to summary
public final MethodBinding getBinding()
getCSymbolback to summary
public FunctionSymbol getCSymbol()

Implements abstract com.jogamp.gluegen.FunctionEmitter.getCSymbol.

Annotations
@Override
getImplNameback to summary
public String getImplName()

Implements abstract com.jogamp.gluegen.FunctionEmitter.getImplName.

Annotations
@Override
getImplSuffixback to summary
protected String getImplSuffix()
getInterfaceNameback to summary
public String getInterfaceName()

Implements abstract com.jogamp.gluegen.FunctionEmitter.getInterfaceName.

Annotations
@Override
getIsJavaMethodStaticback to summary
public final boolean getIsJavaMethodStatic()

Is the Java side of the Java<->C JNI binding for this emitter's MethodBinding a static method?.

getIsOverloadedBindingback to summary
public final boolean getIsOverloadedBinding()

Is the Java<->C JNI binding for this emitter's MethodBinding one of several overloaded methods with the same name?

getJavaClassNameback to summary
public String getJavaClassName()

Get the name of the package in which the corresponding Java method resides.

getJavaPackageNameback to summary
public String getJavaPackageName()

Get the name of the class in which the corresponding Java method resides.

getMachineDataInfoback to summary
public final MachineDataInfo getMachineDataInfo()

Used for certain internal type size computations

getNativeNameback to summary
public String getNativeName()

Implements abstract com.jogamp.gluegen.FunctionEmitter.getNativeName.

Annotations
@Override
getReturnValueCapacityExpressionback to summary
public final MessageFormat getReturnValueCapacityExpression()

Get the expression for the capacity of the returned java.nio.Buffer.

getReturnValueLengthExpressionback to summary
public final MessageFormat getReturnValueLengthExpression()

Get the expression for the length of the returned array

getTemporaryCVariableAssignmentsback to summary
public final List<String> getTemporaryCVariableAssignments()

Returns the List of Strings containing assignments for temporary C variables which are made after the underlying function call. A null argument indicates that no manual assignments are to be made.

getTemporaryCVariableDeclarationsback to summary
public final List<String> getTemporaryCVariableDeclarations()

Returns the List of Strings containing declarations for temporary C variables to be assigned to after the underlying function call.

isNIOArgNameback to summary
protected String isNIOArgName(final int i)
isNIOArgNameback to summary
protected String isNIOArgName(final String s)
isUTF8Typeback to summary
protected boolean isUTF8Type(Type type)

Checks a type to see whether it is for a UTF-8 pointer type (i.e., "const char *", "const char **"). False implies that this type is for a Unicode pointer type ("jchar *", "jchar **").

javaArgTypeNeedsDataCopyback to summary
protected boolean javaArgTypeNeedsDataCopy(final JavaType javaArgType)
jniMangleback to summary
protected String jniMangle(final MethodBinding binding)
jniMangleback to summary
protected void jniMangle(final Class<?> c, final StringBuilder res, final boolean syntheticArgument)
pointerConversionArgumentNameback to summary
protected String pointerConversionArgumentName(final String argName)
setIsCStructFunctionPointerback to summary
protected void setIsCStructFunctionPointer(final boolean v)

If method originates from a struct, see MethodBinding#hasContainingType(), it can either purposed to call a native static function (default) or a struct's function pointer.

setReturnValueCapacityExpressionback to summary
public final void setReturnValueCapacityExpression(final MessageFormat expression)

If this function returns a void* encapsulated in a java.nio.Buffer (or compound type wrapper), sets the expression for the capacity of the returned Buffer.

Parameters
expression:MessageFormat

a MessageFormat which, when applied to an array of type String[] that contains each of the arguments names of the Java-side binding, returns an expression that will (when compiled by a C compiler) evaluate to an integer-valued expression. The value of this expression is the capacity of the java.nio.Buffer returned from this method.

Exceptions
IllegalArgumentException:
if the binding.getJavaReturnType().isNIOBuffer() == false and binding.getJavaReturnType().isCompoundTypeWrapper() == false
setReturnValueLengthExpressionback to summary
public final void setReturnValueLengthExpression(final MessageFormat expression)

If this function returns an array, sets the expression for the length of the returned array.

Parameters
expression:MessageFormat

a MessageFormat which, when applied to an array of type String[] that contains each of the arguments names of the Java-side binding, returns an expression that will (when compiled by a C compiler) evaluate to an integer-valued expression. The value of this expression is the length of the array returned from this method.

Exceptions
IllegalArgumentException:
if the binding.getJavaReturnType().isNIOBuffer() == false
setTemporaryCVariableAssignmentsback to summary
public final void setTemporaryCVariableAssignments(final List<String> arg)

Sets up a List of Strings containing assignments for temporary C variables which are made after the underlying function call. A null argument indicates that no manual assignments are to be made.

setTemporaryCVariableDeclarationsback to summary
public final void setTemporaryCVariableDeclarations(final List<String> arg)

Sets up a List of Strings containing declarations for temporary C variables to be assigned to after the underlying function call. A null argument indicates that no manual declarations are to be made.

com.jogamp.gluegen back to summary

protected Class CMethodBindingEmitter.DefaultCommentEmitter

extends Object
implements CommentEmitter
Class Inheritance
  • java.lang.Object
  • com.jogamp.gluegen.CMethodBindingEmitter.DefaultCommentEmitter
All Implemented Interfaces
com.jogamp.gluegen.CommentEmitter

Class that emits a generic comment for CMethodBindingEmitters; the comment includes the C signature of the native method that is being bound by the emitter java method.

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public void
emit(final FunctionEmitter emitter, final PrintWriter writer)

Implements com.jogamp.gluegen.CommentEmitter.emit.

Emit the body of a comment for the specified function; do NOT emit the open (e.g., comment "/*") or close (e.g., "*\/") characters.
protected void
emitBeginning(final CMethodBindingEmitter emitter, final PrintWriter writer)

protected void
emitEnding(final CMethodBindingEmitter emitter, final PrintWriter writer)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

DefaultCommentEmitterback to summary
protected DefaultCommentEmitter()

Method Detail

emitback to summary
public void emit(final FunctionEmitter emitter, final PrintWriter writer)

Implements com.jogamp.gluegen.CommentEmitter.emit.

Doc from com.jogamp.gluegen.CommentEmitter.emit.

Emit the body of a comment for the specified function; do NOT emit the open (e.g., comment "/*") or close (e.g., "*\/") characters.

Annotations
@Override
emitBeginningback to summary
protected void emitBeginning(final CMethodBindingEmitter emitter, final PrintWriter writer)
emitEndingback to summary
protected void emitEnding(final CMethodBindingEmitter emitter, final PrintWriter writer)